Skip to content

Commit ac96e0e

Browse files
committed
Add test_main.py #1
1 parent 3a23574 commit ac96e0e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

clang_tools/install.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None:
7777
shutil.move(old_file_name, f"{install_dir}/{new_file_name}")
7878
os.chmod(os.path.join(install_dir, new_file_name), 0o755)
7979
except PermissionError:
80-
raise SystemExit("You don't have permission. Try to run with the appropriate permissions.")
80+
raise SystemExit(
81+
f"Don't have permission to install {new_file_name} to {install_dir}. \
82+
Try to run with the appropriate permissions."
83+
)
8184

8285

8386
def install_clang_tools(version, directory) -> None:

clang_tools/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import sys
12
import argparse
23
from clang_tools.install import install_clang_tools
34

45

5-
def main() -> int:
6+
def parse_args(args):
67
parser = argparse.ArgumentParser(prog='clang-tools')
78

89
parser.add_argument(
@@ -18,13 +19,16 @@ def main() -> int:
1819
default="",
1920
help="The directory where is the clang-tools install.",
2021
)
21-
args = parser.parse_args()
22+
return parser.parse_args()
23+
24+
25+
def main():
26+
args = parse_args(sys.argv[1:])
2227

2328
version = args.install
2429
directory = args.directory
25-
2630
install_clang_tools(version, directory)
2731

2832

2933
if __name__ == '__main__':
30-
raise SystemExit(main())
34+
main()

tests/test_main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
from unittest import mock
3+
from clang_tools.main import main
4+
5+
6+
@pytest.mark.parametrize("argv, called, response", [(['-i'], True, False), (['-d'], True, False)])
7+
def test_main_install(argv, called, response):
8+
with mock.patch('sys.argv', [''] + argv):
9+
if called and not response:
10+
with pytest.raises(SystemExit):
11+
main()
12+
else:
13+
main()

0 commit comments

Comments
 (0)