Mike Frysinger | 9589a25 | 2023-06-23 02:56:16 -0400 | [diff] [blame] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Test the gerrit module.""" |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from chromite.scripts import gerrit |
| 10 | |
| 11 | |
| 12 | def test_main_usage(): |
| 13 | """Basic tests for the main help.""" |
| 14 | # Missing subcommand is an error. |
| 15 | with pytest.raises(SystemExit) as excinfo: |
| 16 | gerrit.main([]) |
| 17 | assert excinfo.value.code != 0 |
| 18 | |
| 19 | with pytest.raises(SystemExit) as excinfo: |
| 20 | gerrit.main(["--help"]) |
| 21 | assert excinfo.value.code == 0 |
| 22 | |
| 23 | actions = gerrit._GetActions() # pylint: disable=protected-access |
| 24 | # Don't track exactly how many actions there are, just make sure we have a |
| 25 | # reasonable return value. |
| 26 | assert len(actions) > 20 |
| 27 | assert "help" in actions |
| 28 | assert "search" in actions |
| 29 | |
| 30 | # Check help for all subcommands. |
| 31 | for action in actions: |
| 32 | with pytest.raises(SystemExit) as excinfo: |
| 33 | gerrit.main(["help", action]) |
| 34 | assert excinfo.value.code == 0 |
| 35 | |
| 36 | gerrit.main(["help-all"]) |