-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin lazy loading, optional attribute_name for register_api,
different groups for sources, nodes and sinks, tests
- Loading branch information
Showing
3 changed files
with
49 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,55 @@ | ||
from streamz.sources import Source | ||
from streamz import Stream | ||
import pytest | ||
from streamz import Source, Stream | ||
|
||
|
||
class MockEntryPoint: | ||
|
||
def __init__(self, name, cls): | ||
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): | ||
class test_stream(Stream): | ||
pass | ||
|
||
entry_point = MockEntryPoint("test_node", test) | ||
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" | ||
assert Stream.test_node.__name__ == "test_stream" | ||
|
||
|
||
def test_register_plugin_entry_point_modifier(): | ||
class test(Source): | ||
class test_source(Source): | ||
pass | ||
|
||
entry_point = MockEntryPoint("from_test", test) | ||
Stream.register_plugin_entry_point(entry_point, staticmethod) | ||
def modifier(fn): | ||
fn.__name__ = 'modified_name' | ||
return staticmethod(fn) | ||
|
||
entry_point = MockEntryPoint("from_test", test_source) | ||
Stream.register_plugin_entry_point(entry_point, modifier) | ||
|
||
Stream.from_test() | ||
|
||
assert Stream.from_test.__self__ is Stream | ||
assert Stream.from_test.__name__ == "modified_name" | ||
|
||
|
||
def test_register_plugin_entry_point_raises(): | ||
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() |