File: test_plugins.py

package info (click to toggle)
python-streamz 0.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 824 kB
  • sloc: python: 6,714; makefile: 18; sh: 18
file content (60 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (3)
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
import inspect

import pytest
from streamz import Source, Stream


class MockEntryPoint:

    def __init__(self, name, cls, module_name=None):
        self.name = name
        self.cls = cls
        self.module_name = module_name

    def load(self):
        return self.cls


def test_register_plugin_entry_point():
    class test_stream(Stream):
        pass

    entry_point = MockEntryPoint("test_node", test_stream)
    Stream.register_plugin_entry_point(entry_point)

    assert Stream.test_node.__name__ == "stub"

    Stream().test_node()

    assert Stream.test_node.__name__ == "test_stream"


def test_register_plugin_entry_point_modifier():
    class test_source(Source):
        pass

    entry_point = MockEntryPoint("from_test", test_source)
    Stream.register_plugin_entry_point(entry_point, staticmethod)

    Stream.from_test()

    assert inspect.isfunction(Stream().from_test)


def test_register_plugin_entry_point_raises_type():
    class invalid_node:
        pass

    entry_point = MockEntryPoint("test", invalid_node, "test_module.test")

    Stream.register_plugin_entry_point(entry_point)

    with pytest.raises(TypeError):
        Stream.test()


def test_register_plugin_entry_point_raises_duplicate_name():
    entry_point = MockEntryPoint("map", None)

    with pytest.raises(ValueError):
        Stream.register_plugin_entry_point(entry_point)