|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | import pytest |
3 | | -import subprocess |
| 4 | +import argparse |
4 | 5 | import tempfile |
| 6 | +import subprocess |
5 | 7 | import configparser |
| 8 | +from urlchecker.client import main as init_main |
| 9 | +from urlchecker.client.check import main as check_main |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"]) |
| 13 | +@pytest.mark.parametrize("cleanup", [False, True]) |
| 14 | +@pytest.mark.parametrize("print_all", [False]) |
| 15 | +@pytest.mark.parametrize("verbose", [True]) |
| 16 | +@pytest.mark.parametrize("force_pass", [False, True]) |
| 17 | +@pytest.mark.parametrize("rcount", [1]) |
| 18 | +@pytest.mark.parametrize("timeout", [3]) |
| 19 | +def test_client_init_( |
| 20 | + config_fname, cleanup, print_all, verbose, force_pass, rcount, timeout |
| 21 | +): |
| 22 | + |
| 23 | + # init config parser |
| 24 | + config = configparser.ConfigParser() |
| 25 | + config.read(config_fname) |
| 26 | + |
| 27 | + # init env variables |
| 28 | + path = config["DEFAULT"]["git_path_test_value"] |
| 29 | + file_types = config["DEFAULT"]["file_types_test_values"] |
| 30 | + exclude_urls = config["DEFAULT"]["exclude_test_urls"] |
| 31 | + exclude_patterns = config["DEFAULT"]["exclude_test_patterns"] |
| 32 | + |
| 33 | + # Generate command |
| 34 | + cmd = [ |
| 35 | + "urlchecker", |
| 36 | + "check", |
| 37 | + "--branch", |
| 38 | + "main", |
| 39 | + "--subfolder", |
| 40 | + "test_files", |
| 41 | + "--file-types", |
| 42 | + file_types, |
| 43 | + "--exclude-files", |
| 44 | + "conf.py", |
| 45 | + "--exclude-urls", |
| 46 | + exclude_urls, |
| 47 | + "--exclude-patterns", |
| 48 | + exclude_patterns, |
| 49 | + "--retry-count", |
| 50 | + str(rcount), |
| 51 | + "--timeout", |
| 52 | + str(timeout), |
| 53 | + ] |
| 54 | + |
| 55 | + # Add boolean arguments |
| 56 | + if cleanup: |
| 57 | + cmd.append("--cleanup") |
| 58 | + if print_all: |
| 59 | + cmd.append("--print-all") |
| 60 | + if force_pass: |
| 61 | + cmd.append("--force-pass") |
| 62 | + if verbose: |
| 63 | + cmd.append("--verbose") |
| 64 | + |
| 65 | + # Add final path |
| 66 | + cmd.append(path) |
| 67 | + |
| 68 | + # assign args and run main |
| 69 | + sys.argv = cmd |
| 70 | + with pytest.raises(SystemExit): |
| 71 | + init_main() |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize( |
| 75 | + "command", ["", "--version", "--help", "--unsupported_command"] |
| 76 | +) |
| 77 | +def test_command(command): |
| 78 | + # assign args and run main |
| 79 | + sys.argv = ["urlchecker", command] |
| 80 | + with pytest.raises(SystemExit): |
| 81 | + init_main() |
| 82 | + |
| 83 | + |
| 84 | +@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"]) |
| 85 | +@pytest.mark.parametrize("cleanup", [False, True]) |
| 86 | +@pytest.mark.parametrize("no_print", [True]) |
| 87 | +@pytest.mark.parametrize("verbose", [False]) |
| 88 | +@pytest.mark.parametrize("force_pass", [False]) |
| 89 | +@pytest.mark.parametrize("rcount", [1]) |
| 90 | +@pytest.mark.parametrize("timeout", [3]) |
| 91 | +def test_arguments_from_cli( |
| 92 | + config_fname, cleanup, no_print, verbose, force_pass, rcount, timeout |
| 93 | +): |
| 94 | + |
| 95 | + # init config parser |
| 96 | + config = configparser.ConfigParser() |
| 97 | + config.read("./tests/_local_test_config.conf") |
| 98 | + |
| 99 | + # Generate command |
| 100 | + cmd = argparse.Namespace( |
| 101 | + path=config["DEFAULT"]["git_path_test_value"], |
| 102 | + subfolder="test_files", |
| 103 | + branch="main", |
| 104 | + cleanup=str(cleanup), |
| 105 | + file_types=config["DEFAULT"]["file_types_test_values"], |
| 106 | + files="", |
| 107 | + no_print=str(no_print), |
| 108 | + exclude_urls=config["DEFAULT"]["exclude_test_urls"], |
| 109 | + exclude_patterns=config["DEFAULT"]["exclude_test_patterns"], |
| 110 | + exclude_files="conf.py", |
| 111 | + force_pass=str(force_pass), |
| 112 | + retry_count=rcount, |
| 113 | + save=None, |
| 114 | + timeout=timeout, |
| 115 | + verbose=verbose, |
| 116 | + ) |
| 117 | + with pytest.raises(SystemExit): |
| 118 | + check_main(cmd, None) |
6 | 119 |
|
7 | 120 |
|
8 | 121 | @pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"]) |
|
12 | 125 | @pytest.mark.parametrize("force_pass", [False, True]) |
13 | 126 | @pytest.mark.parametrize("rcount", [1, 3]) |
14 | 127 | @pytest.mark.parametrize("timeout", [3, 5]) |
15 | | -def test_client_general(config_fname, cleanup, print_all, verbose, |
16 | | - force_pass, rcount, timeout): |
| 128 | +def test_client_general( |
| 129 | + config_fname, cleanup, print_all, verbose, force_pass, rcount, timeout |
| 130 | +): |
17 | 131 |
|
18 | 132 | # init config parser |
19 | 133 | config = configparser.ConfigParser() |
|
0 commit comments