-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_has_manifest_files.py
More file actions
70 lines (55 loc) · 2.51 KB
/
test_has_manifest_files.py
File metadata and controls
70 lines (55 loc) · 2.51 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
from pathlib import PurePath
from unittest.mock import patch
from socketsecurity.core import Core
# Minimal patterns matching what the Socket API returns
MOCK_PATTERNS = {
"npm": {
"packagejson": {"pattern": "package.json"},
"packagelockjson": {"pattern": "package-lock.json"},
"yarnlock": {"pattern": "yarn.lock"},
},
"pypi": {
"requirements": {"pattern": "*requirements.txt"},
"requirementsin": {"pattern": "*requirements*.txt"},
"setuppy": {"pattern": "setup.py"},
},
"maven": {
"pomxml": {"pattern": "pom.xml"},
},
}
@patch.object(Core, "get_supported_patterns", return_value=MOCK_PATTERNS)
@patch.object(Core, "__init__", lambda self, *a, **kw: None)
class TestHasManifestFiles:
def test_root_level_package_json(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["package.json"]) is True
def test_root_level_package_lock_json(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["package-lock.json"]) is True
def test_subdirectory_package_json(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["libs/ui/package.json"]) is True
def test_root_level_requirements_txt(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["requirements.txt"]) is True
def test_subdirectory_requirements_txt(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["src/requirements.txt"]) is True
def test_prefixed_requirements_txt(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["dev-requirements.txt"]) is True
def test_no_manifest_files(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["README.md", "src/app.py"]) is False
def test_mixed_files_with_manifest(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files([".gitlab-ci.yml", "package.json", "src/app.tsx"]) is True
def test_empty_list(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files([]) is False
def test_dot_slash_prefix_normalized(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["./package.json"]) is True
def test_pom_xml_root(self, mock_patterns):
core = Core.__new__(Core)
assert core.has_manifest_files(["pom.xml"]) is True