forked from danger/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_plugins.py
More file actions
52 lines (39 loc) · 1.74 KB
/
Copy pathtest_plugins.py
File metadata and controls
52 lines (39 loc) · 1.74 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
import pytest
import tests
from danger_python.danger import Danger, DangerResults, Violation
from danger_python.plugins import DangerPlugin
class FirstPlugin(DangerPlugin):
def fancy_method_returning_sum(self, a: int, b: int) -> int:
return a + b
def test_that_plugin_method_is_registered_in_global_namespace():
"""
Test that plugin method is autoregistered in global namespace of
the package containing the method.
"""
result = tests.fancy_method_returning_sum(8, 7) # type: ignore
assert result == 15
class ModifiedFilesPrinterPlugin(DangerPlugin):
def print_modified_files(self):
methods = [self.message, self.markdown, self.warn, self.fail]
for index, modified_file in enumerate(self.danger.git.modified_files):
number_of_files = len(self.danger.git.modified_files)
methods[index](f"Files modified: {number_of_files}", modified_file, index)
@pytest.mark.parametrize(
"modified_files", [["message.py", "markdown.py", "warn.py", "fail.py"]]
)
def test_that_plugin_method_has_access_to_danger_and_reporting_methods(danger: Danger):
"""
Test that plugin method has access to the danger DSL and also the methods
for providing messages, markdowns, warnings and fails.
"""
tests.print_modified_files() # type: ignore
assert danger.results == DangerResults(
fails=[Violation(message="Files modified: 4", file_name="fail.py", line=3)],
warnings=[Violation(message="Files modified: 4", file_name="warn.py", line=2)],
markdowns=[
Violation(message="Files modified: 4", file_name="markdown.py", line=1)
],
messages=[
Violation(message="Files modified: 4", file_name="message.py", line=0)
],
)