blob: 3e3887f60b5db378400eba046351f6db7ef2dff0 [file] [log] [blame]
Mike Frysinger9589a252023-06-23 02:56:16 -04001# 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
7import pytest
8
9from chromite.scripts import gerrit
10
11
12def 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"])