Debian Codegraph @

tests/cascade_dependencies_test.py

raw
1 import os
2 import pathlib
3
4 from unittest import mock
5 import pytest
6
7 extra_plugin_dir = os.path.join(
8 os.path.dirname(os.path.realpath(__file__)), "cascade_dependent_plugins"
9 )
10
11 orig_path_glob = pathlib.Path.glob
12
13
14 def reordered_plugin_files(self, pattern):
15 if self.name == "cascade_dependent_plugins":
16 yield pathlib.Path(extra_plugin_dir + "/parent2.plug")
17 yield pathlib.Path(extra_plugin_dir + "/child1.plug")
18 yield pathlib.Path(extra_plugin_dir + "/child2.plug")
19 yield pathlib.Path(extra_plugin_dir + "/parent1.plug")
20 return
21 yield from orig_path_glob(self, pattern)
22
23
24 @pytest.fixture
25 def mock_before_bot_load():
26 patcher = mock.patch.object(pathlib.Path, "glob", reordered_plugin_files)
27 patcher.start()
28 yield
29 patcher.stop()
30
31
32 def test_dependency_commands(mock_before_bot_load, testbot):
33 assert "Hello from Child1" in testbot.exec_command("!parent1 to child1")
34 assert "Hello from Child2" in testbot.exec_command("!parent1 to child2")
35 assert "Hello from Parent1" in testbot.exec_command("!parent2 to parent1")