File: cascade_dependencies_test.py

package info (click to toggle)
errbot 6.2.0%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,856 kB
  • sloc: python: 11,572; makefile: 163; sh: 97
file content (35 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (2)
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
import os
import pathlib

from unittest import mock
import pytest

extra_plugin_dir = os.path.join(
    os.path.dirname(os.path.realpath(__file__)), "cascade_dependent_plugins"
)

orig_path_glob = pathlib.Path.glob


def reordered_plugin_files(self, pattern):
    if self.name == "cascade_dependent_plugins":
        yield pathlib.Path(extra_plugin_dir + "/parent2.plug")
        yield pathlib.Path(extra_plugin_dir + "/child1.plug")
        yield pathlib.Path(extra_plugin_dir + "/child2.plug")
        yield pathlib.Path(extra_plugin_dir + "/parent1.plug")
        return
    yield from orig_path_glob(self, pattern)


@pytest.fixture
def mock_before_bot_load():
    patcher = mock.patch.object(pathlib.Path, "glob", reordered_plugin_files)
    patcher.start()
    yield
    patcher.stop()


def test_dependency_commands(mock_before_bot_load, testbot):
    assert "Hello from Child1" in testbot.exec_command("!parent1 to child1")
    assert "Hello from Child2" in testbot.exec_command("!parent1 to child2")
    assert "Hello from Parent1" in testbot.exec_command("!parent2 to parent1")