-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime_plugins.py
More file actions
68 lines (53 loc) · 1.88 KB
/
Copy pathtest_runtime_plugins.py
File metadata and controls
68 lines (53 loc) · 1.88 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
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from runtime.plugins.base import Plugin # noqa: E402
from runtime.plugins.manager import PluginManager # noqa: E402
class Recorder(Plugin):
def __init__(self, log: list[str]) -> None:
self.log = log
def before_run(self, manifest: dict) -> None:
self.log.append("before_run")
def after_run(self, manifest: dict) -> None:
self.log.append("after_run")
def before_step(self, step: dict, manifest: dict) -> None:
self.log.append("before_step")
def after_step(self, step: dict, manifest: dict) -> None:
self.log.append("after_step")
def on_error(self, step: dict, manifest: dict, error: str) -> None:
self.log.append("on_error")
def on_validation(self, manifest: dict, status: str) -> None:
self.log.append(f"validation:{status}")
class RuntimePluginTests(unittest.TestCase):
def test_plugin_manager_calls(self) -> None:
log: list[str] = []
manager = PluginManager([Recorder(log)])
manager.before_run({})
manager.before_step({}, {})
manager.after_step({}, {})
manager.on_error({}, {}, "boom")
manager.on_validation({}, "ok")
manager.after_run({})
self.assertEqual(
log,
[
"before_run",
"before_step",
"after_step",
"on_error",
"validation:ok",
"after_run",
],
)
def test_base_plugin_noops(self) -> None:
plugin = Plugin()
plugin.before_run({})
plugin.after_run({})
plugin.before_step({}, {})
plugin.after_step({}, {})
plugin.on_error({}, {}, "boom")
plugin.on_validation({}, "ok")
if __name__ == "__main__":
unittest.main()