-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_basicpatterns.py
More file actions
58 lines (37 loc) · 1.79 KB
/
Copy pathtest_basicpatterns.py
File metadata and controls
58 lines (37 loc) · 1.79 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
import pytest
from pathlib import Path
from codeaudit.filehelpfunctions import read_in_source_file
from codeaudit.issuevalidations import find_constructs
def test_basic_patterns():
current_file_directory = Path(__file__).parent
# validation1.py is in a subfolder:
validation_file_path = current_file_directory / "validationfiles" / "validation1.py"
source = read_in_source_file(validation_file_path)
constructs = {"os.access", "eval"}
actual_data = find_constructs(source, constructs)
# This is the expected dictionary
expected_data = {"os.access": [8, 14], "eval": [11]}
# Assert that the actual data matches the expected data
assert actual_data == expected_data
def test_basic_patterns2():
current_file_directory = Path(__file__).parent
# validation1.py is in a subfolder:
validation_file_path = current_file_directory / "validationfiles" / "validation2.py"
source = read_in_source_file(validation_file_path)
constructs = {"os", "os.access", "eval"}
actual_data = find_constructs(source, constructs)
# This is the expected dictionary
expected_data = {"os.access": [8, 12], "eval": [10], "os": [8, 12]}
# Assert that the actual data matches the expected data
assert actual_data == expected_data
def test_assert_keyword():
current_file_directory = Path(__file__).parent
# validation1.py is in a subfolder:
validation_file_path = current_file_directory / "validationfiles" / "assert.py"
source = read_in_source_file(validation_file_path)
constructs = {"os", "os.access", "assert"}
actual_data = find_constructs(source, constructs)
# This is the expected dictionary
expected_data = {"assert": [5, 31]}
# Assert that the actual data matches the expected data
assert actual_data == expected_data