-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_core_fileproc.py
More file actions
124 lines (106 loc) · 3.18 KB
/
test_core_fileproc.py
File metadata and controls
124 lines (106 loc) · 3.18 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
import os
import pytest
import tempfile
from urlchecker.core.fileproc import (
check_file_type,
get_file_paths,
collect_links_from_file,
include_file,
remove_empty,
)
@pytest.mark.parametrize(
"file_path",
[".filename"],
)
@pytest.mark.parametrize("file_types", [[".*"]])
def test_check_file_type(file_path, file_types):
"""
test pattern matching
"""
output = check_file_type(file_path, file_types)
if not output:
raise AssertionError
# check for false
output = check_file_type("nonesense" + file_path, file_types)
if output:
raise AssertionError
@pytest.mark.parametrize(
"file_path",
["tests/test_files/sample_test_file.txt", "tests/test_files/sample_test_file.py"],
)
@pytest.mark.parametrize("file_types", [[".txt", ".py"]])
def test_check_file_type(file_path, file_types):
"""
test check file types
"""
output = check_file_type(file_path, file_types)
if not output:
raise AssertionError
# check for false
output = check_file_type(file_path + ".nonesense", file_types)
if output:
raise AssertionError
@pytest.mark.parametrize(
"file_path",
["tests/test_files/sample_test_file.md", "tests/test_files/sample_test_file.py"],
)
@pytest.mark.parametrize(
"exclude_patterns", [["[.py]"], ["[.md]"], ["tests/test_file"]]
)
def test_include_files(file_path, exclude_patterns):
"""
test if a file should be included based on patterns (using extension for test)
"""
_, extension = os.path.splitext(file_path)
expected = not extension in file_path
result = include_file(file_path, exclude_patterns)
# No files should be included for a global path pattern
if "tests/test_file" in exclude_patterns:
if result:
raise AssertionError
# Otherwise, the patterns should honor extension
else:
if result != expected:
raise AssertionError
@pytest.mark.parametrize("base_path", ["tests/test_files"])
@pytest.mark.parametrize("file_types", [[".md", ".py"]])
def test_get_file_paths(base_path, file_types):
"""
get path to all files under a give directory and its subfolders.
Args:
base_path (str) : base path.
file_types (list) : list of file extensions to accept.
Returns:
list of file paths.
"""
file_paths = get_file_paths(base_path, file_types)
expected_paths = [
[
"tests/test_files/sample_test_file.md",
"tests/test_files/sample_test_file.py",
],
[
"tests/test_files/sample_test_file.py",
"tests/test_files/sample_test_file.md",
],
]
# assert
assert file_paths in expected_paths
@pytest.mark.parametrize(
"file_path",
["tests/test_files/sample_test_file.md", "tests/test_files/sample_test_file.md"],
)
def collect_links_from_file(file_path):
"""
test links collerction function.
"""
# read file content
urls = collect_links_from_file()
assert len(url) == 3
def test_remove_empty():
"""
test that empty urls are removed
"""
urls = ["notempty", "notempty", "", None]
if len(remove_empty(urls)) != 2:
raise AssertionError