-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_core_check.py
More file actions
132 lines (111 loc) · 3.85 KB
/
test_core_check.py
File metadata and controls
132 lines (111 loc) · 3.85 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
import os
import re
import sys
import pytest
import configparser
from urlchecker.core.fileproc import get_file_paths
from urlchecker.main.github import clone_repo
from urlchecker.core.check import UrlChecker
@pytest.mark.parametrize(
"file_paths",
[
["tests/test_files/sample_test_file.md"],
["tests/test_files/sample_test_file.c"],
["tests/test_files/sample_test_file.rst"],
],
)
@pytest.mark.parametrize("print_all", [False, True])
@pytest.mark.parametrize(
"exclude_urls", [["https://github.com/SuperKogito/SuperKogito.github.io"]]
)
@pytest.mark.parametrize(
"exclude_patterns",
[[], ["https://github.com/SuperKogito/SuperKogito.github.io"]],
)
def test_check_files(file_paths, print_all, exclude_urls, exclude_patterns):
"""
test check repo function.
"""
checker = UrlChecker(print_all=print_all)
checker.run(
file_paths,
exclude_urls=exclude_urls,
exclude_patterns=exclude_patterns,
retry_count=1,
)
@pytest.mark.parametrize("local_folder_path", ["./tests/test_files"])
@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"])
def test_locally(local_folder_path, config_fname):
# init config parser
config = configparser.ConfigParser()
config.read(config_fname)
# read input variables
git_path = local_folder_path
file_types = config["DEFAULT"]["file_types_test_values"].split(",")
print_all = True
exclude_urls = config["DEFAULT"]["exclude_test_urls"].split(",")
exclude_patterns = config["DEFAULT"]["exclude_test_patterns"].split(",")
# get all file paths
file_paths = get_file_paths(git_path, file_types)
# check repo urls
checker = UrlChecker(print_all=print_all)
checker.run(
file_paths=file_paths,
exclude_urls=exclude_urls,
exclude_patterns=exclude_patterns,
retry_count=1,
)
print("Done.")
@pytest.mark.parametrize("retry_count", [1, 3])
def test_check_run_save(tmp_path, retry_count):
# init vars
git_path = "https://github.com/urlstechie/urlchecker-test-repo"
file_types = [".py", ".md"]
print_all = True
exclude_urls = [
"https://superkogito.github.io/figures/fig2.html",
"https://superkogito.github.io/figures/fig4.html",
]
exclude_patterns = ["https://superkogito.github.io/tables"]
timeout = 1
force_pass = False
# clone repo
base_path = clone_repo(git_path)
# get all file paths in subfolder specified
base_path = os.path.join(base_path, "test_files")
file_paths = get_file_paths(base_path, file_types)
# check repo urls
checker = UrlChecker(print_all=print_all)
check_results = checker.run(
file_paths=file_paths,
exclude_urls=exclude_urls,
exclude_patterns=exclude_patterns,
retry_count=retry_count,
timeout=timeout,
)
# Test saving to file
output_file = os.path.join(str(tmp_path), "results.csv")
assert not os.path.exists(output_file)
saved_file = checker.save_results(output_file)
assert os.path.exists(output_file)
# Read in output file
with open(saved_file, "r") as filey:
lines = filey.readlines()
# Header line has three items
assert lines[0] == "URL,RESULT,FILENAME\n"
# Ensure content looks okay
for line in lines[1:]:
url, result, filename = line.split(",")
root = filename.split("/")[0]
assert url.startswith("http")
assert result in ["passed", "failed"]
assert re.search("(.py|.md)$", filename)
# Save with full path
saved_file = checker.save_results(output_file, relative_paths=False)
# Read in output file
with open(saved_file, "r") as filey:
lines = filey.readlines()
# Ensure content looks okay
for line in lines[1:]:
url, result, filename = line.split(",")
assert not filename.startswith(root)