-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_main.py
51 lines (40 loc) · 1.66 KB
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Tests that relate to the main.py module."""
from typing import Optional
from argparse import ArgumentParser
import pytest
from clang_tools.main import get_parser
class Args:
"""A pseudo namespace for testing argparse.
These class attributes are set to the CLI args default values."""
directory: str = ""
install: Optional[str] = None
overwrite: bool = False
no_progress_bar: bool = False
uninstall: Optional[str] = None
@pytest.fixture
def parser() -> ArgumentParser:
"""get the arg parser for the tests in this module."""
return get_parser()
@pytest.mark.parametrize("arg_name", ["install", "directory", "uninstall"])
@pytest.mark.parametrize("arg_value", [str(v) for v in range(7, 17)] + ["12.0.1"])
def test_arg_parser(arg_name: str, arg_value: str, parser: ArgumentParser):
"""Test CLI arg parsing using a set of fake args."""
args = parser.parse_args([f"--{arg_name}={arg_value}"])
assert getattr(args, arg_name) == arg_value
@pytest.mark.parametrize("switch_name", ["overwrite", "no-progress-bar"])
def test_cli_switch(switch_name: str, parser: ArgumentParser):
"""Test the CLI switches/flags"""
args = parser.parse_args([f"--{switch_name}"])
assert getattr(args, switch_name.replace("-", "_"))
@pytest.mark.parametrize("name, default_value", [
("install", None),
("uninstall", None),
("overwrite", False),
("no_progress_bar", False),
("directory", ""),
("tool", ['clang-format', 'clang-tidy'])
])
def test_default_args(parser: ArgumentParser, name, default_value):
"""Test the default values of CLI args"""
args = parser.parse_args([])
assert getattr(args, name) == default_value