-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_client_check.py
More file actions
159 lines (133 loc) · 4.28 KB
/
test_client_check.py
File metadata and controls
159 lines (133 loc) · 4.28 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
import pytest
import argparse
import tempfile
import subprocess
import configparser
from urlchecker.client import check
def test_client_general():
# excute scripts
pipe = subprocess.run(
["urlchecker", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
assert pipe.stderr.decode("utf-8") == ""
pipe = subprocess.run(
["urlchecker", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
assert pipe.stderr.decode("utf-8") == ""
pipe = subprocess.run(
["urlchecker", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
assert pipe.stderr.decode("utf-8") == ""
@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"])
@pytest.mark.parametrize("cleanup", [False, True])
@pytest.mark.parametrize("print_all", [False, True])
@pytest.mark.parametrize("force_pass", [False, True])
@pytest.mark.parametrize("rcount", [1, 3])
@pytest.mark.parametrize("timeout", [5, 7])
def test_client_check(config_fname, cleanup, print_all, force_pass, rcount, timeout):
# init config parser
config = configparser.ConfigParser()
config.read(config_fname)
# init env variables
path = config["DEFAULT"]["git_path_test_value"]
file_types = config["DEFAULT"]["file_types_test_values"]
exclude_urls = config["DEFAULT"]["exclude_test_urls"]
exclude_patterns = config["DEFAULT"]["exclude_test_patterns"]
# Generate command
cmd = [
"urlchecker",
"check",
"--subfolder",
"test_files",
"--file-types",
file_types,
"--exclude-files",
"conf.py",
"--exclude-urls",
exclude_urls,
"--exclude_patterns",
exclude_patterns,
"--retry-count",
str(rcount),
"--timeout",
str(timeout),
]
# Add boolean arguments
if cleanup:
cmd.append("--cleanup")
if print_all:
cmd.append("--print-all")
if force_pass:
cmd.append("--force-pass")
# Add final path
cmd.append(path)
# excute script
pipe = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@pytest.mark.parametrize("save", [True])
def test_client_save(save):
# init config parser
config = configparser.ConfigParser()
config.read("./tests/_local_test_config.conf")
# init env variables
path = config["DEFAULT"]["git_path_test_value"]
file_types = config["DEFAULT"]["file_types_test_values"]
exclude_urls = config["DEFAULT"]["exclude_test_urls"]
exclude_patterns = config["DEFAULT"]["exclude_test_patterns"]
# Generate command
cmd = [
"urlchecker",
"check",
"--subfolder",
"test_files",
"--file-types",
file_types,
"--exclude-files",
"conf.py",
"--exclude-urls",
exclude_urls,
"--exclude_patterns",
exclude_patterns,
]
# Write to file
if save:
output_csv = tempfile.NamedTemporaryFile(suffix=".csv", prefix="urlchecker-")
cmd += ["--save", output_csv.name]
# Add final path
cmd.append(path)
print(" ".join(cmd))
# excute script
pipe = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if save:
if not os.path.exists(output_csv.name):
raise AssertionError
@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"])
def test_client_check_main(config_fname):
# init config parser
config = configparser.ConfigParser()
config.read(config_fname)
# init env variables
path = config["DEFAULT"]["git_path_test_value"]
file_types = config["DEFAULT"]["file_types_test_values"]
exclude_urls = config["DEFAULT"]["exclude_test_urls"]
exclude_patterns = config["DEFAULT"]["exclude_test_patterns"]
# init args
args = argparse.Namespace()
args.path = path
args.branch = "master"
args.subfolder = "test_files"
args.cleanup = True
args.force_pass = True
args.no_print = True
args.file_types = file_types
args.files = ""
args.exclude_urls = ""
args.exclude_patterns = ""
args.exclude_files = ""
args.save = ""
args.retry_count = 1
args.timeout = 5
# excute script
with pytest.raises(SystemExit) as e:
check.main(args=args, extra=[])
assert e.value.code == 0