-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_context.py
More file actions
65 lines (53 loc) · 2.39 KB
/
test_context.py
File metadata and controls
65 lines (53 loc) · 2.39 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
from codemodder.context import CodemodExecutionContext as Context
from codemodder.dependency import Security
from codemodder.registry import load_registered_codemods
from codemodder.project_analysis.python_repo_manager import PythonRepoManager
class TestContext:
def test_successful_dependency_description(self, mocker):
registry = load_registered_codemods()
repo_manager = PythonRepoManager(mocker.Mock())
codemod = registry.match_codemods(codemod_include=["url-sandbox"])[0]
context = Context(mocker.Mock(), True, False, registry, repo_manager, [], [])
context.add_dependencies(codemod.id, {Security})
pkg_store_name = "pyproject.toml"
pkg_store = mocker.Mock()
pkg_store.type.value = pkg_store_name
mocker.patch(
"codemodder.project_analysis.file_parsers.base_parser.BaseParser.parse",
return_value=[pkg_store],
)
context.process_dependencies(codemod.id)
description = context.add_description(codemod)
assert description.startswith(codemod.description)
assert "## Dependency Updates\n" in description
assert (
f"We have automatically added this dependency to your project's `{pkg_store_name}` file."
in description
)
assert Security.description in description
assert "### Manual Installation\n" not in description
def test_failed_dependency_description(self, mocker):
registry = load_registered_codemods()
repo_manager = PythonRepoManager(mocker.Mock())
codemod = registry.match_codemods(codemod_include=["url-sandbox"])[0]
context = Context(mocker.Mock(), True, False, registry, repo_manager, [], [])
context.add_dependencies(codemod.id, {Security})
mocker.patch(
"codemodder.project_analysis.python_repo_manager.PythonRepoManager._parse_all_stores",
return_value=[],
)
context.process_dependencies(codemod.id)
description = context.add_description(codemod)
assert description.startswith(codemod.description)
assert "## Dependency Updates\n" in description
assert Security.description in description
assert "### Manual Installation\n" in description
assert (
f"""For `setup.py`:
```diff
install_requires=[
+ "{Security.requirement}",
],
```"""
in description
)