mirror of
https://github.com/mvt-project/mvt.git
synced 2026-10-21 23:01:17 +02:00
Expose completed modules during initialization
This commit is contained in:
1 parent
2fe7f4e261
commit
59c3f5d60c
2 files changed
+47
-1
No files matched your search
@@ -9,6 +9,7 @@ import threading
|
||||
import time
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
from rich.console import Console
|
||||
|
||||
from mvt.common.command import Command
|
||||
@@ -126,6 +127,38 @@ class TestCommand:
|
||||
"ThirdModule",
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("jobs", [1, 2])
|
||||
@pytest.mark.parametrize("parallel_safe", [False, True])
|
||||
def test_initialization_hook_sees_completed_dependencies(self, jobs, parallel_safe):
|
||||
class Prerequisite(FirstModule):
|
||||
pass
|
||||
|
||||
Prerequisite.parallel_safe = parallel_safe
|
||||
|
||||
class Dependent(SecondModule):
|
||||
dependencies = (Prerequisite,)
|
||||
|
||||
def run(self):
|
||||
self.results = self.get_dependency_results(Prerequisite) + ["second"]
|
||||
|
||||
class HookCommand(RecordingCommand):
|
||||
def module_init(self, module):
|
||||
if isinstance(module, Dependent):
|
||||
self.seen = [
|
||||
executed.results
|
||||
for executed in self.executed
|
||||
if isinstance(executed, Prerequisite)
|
||||
]
|
||||
|
||||
cmd = HookCommand(jobs=jobs)
|
||||
cmd.modules = [Dependent, Prerequisite]
|
||||
|
||||
cmd.run()
|
||||
|
||||
assert cmd.seen == [["first"]]
|
||||
assert [type(module) for module in cmd.executed] == [Prerequisite, Dependent]
|
||||
assert cmd.executed[1].results == ["first", "second"]
|
||||
|
||||
def test_circular_dependency_warns_and_stops(self, caplog):
|
||||
class CircularOne(RecordingModule):
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user