Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Aug 6, 2024
1 parent e9e666d commit 1c45582
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"python.linting.cwd": "",
"python.testing.pytestArgs": [
"tests"
"tests",
"estimage/plugins"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_inidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

import estimage.inidata as tm
from estimage.persistence import card, event
from estimage import persistence
from estimage.persistence.card import ini
import estimage.data as data
from tests.test_events import early_event, less_early_event
Expand All @@ -23,15 +23,15 @@ def temp_filename():

@pytest.fixture
def cardio_inifile_cls(temp_filename):
class TmpIniCardIO(card.ini.IniCardIO):
class TmpIniCardIO(persistence.card.ini.IniCardIO):
CONFIG_FILENAME = temp_filename

yield TmpIniCardIO


@pytest.fixture
def eventmgr_relevant_io(temp_filename):
class TmpIniEventMgr(event.ini.IniEventsIO):
class TmpIniEventMgr(persistence.event.ini.IniEventsIO):
CONFIG_FILENAME = temp_filename

yield TmpIniEventMgr
Expand Down
73 changes: 66 additions & 7 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import estimage.plugins as tm
import estimage.plugins.null as null_plugin
from estimage import PluginResolver as to
from estimage import persistence


def test_get_plugin_dynamically():
Expand All @@ -18,12 +19,6 @@ def format(self, what):
return what


@to.class_is_extendable("Ext")
class Extendable:
def return_hello(self):
return "hello"


class MockPluginWithoutDecl:
class Formatter:
OVERRIDEN = "maybe"
Expand All @@ -47,7 +42,6 @@ def test_load_plugins(print_plugin):
assert print_plugin.NAME == "Print"



@pytest.fixture
def resolver():
ret = to()
Expand Down Expand Up @@ -110,3 +104,68 @@ def test_load_routes(print_plugin):
def test_dont_load_routes():
bp = tm.get_plugin_blueprint(tm)
assert bp is None


@to.class_is_extendable("Ext")
class Extendable:
def return_hello(self):
return "hello"


@persistence.loader_of(Extendable, "void")
class LoaderOfExtendable:
@classmethod
def load(cls):
return Extendable()


class PluginOne:
EXPORTS = dict(Ext="ExtendableOne")

class ExtendableOne(Extendable):
def return_hello(self):
ret = super().return_hello()
return ret + " one"


@persistence.loader_of(PluginOne.ExtendableOne, "void")
class LoaderOfExtendableOne:
@classmethod
def load(cls):
ret = super().load()
ret.is_one = True
return ret


class PluginTwo:
EXPORTS = dict(Ext="ExtendableTwo")

class ExtendableTwo:
def return_hello(self):
ret = super().return_hello()
return ret + " two"


def test_two_plugin_composition(resolver):
resolver.resolve_class_extension(PluginOne)
resolver.resolve_class_extension(PluginTwo)
final_extendable = resolver.class_dict["Ext"]()
assert "hello" in final_extendable.return_hello()
assert "one" in final_extendable.return_hello()
assert "two" in final_extendable.return_hello()
assert final_extendable.return_hello() == "hello one two"


def test_two_plugin_loading(resolver):
resolver.resolve_class_extension(PluginTwo)
intermed_extendable_cls = resolver.class_dict["Ext"]
loader = persistence.LOADERS[intermed_extendable_cls]["void"]
loaded = loader.load()
assert "hello" in loaded.return_hello()
assert not hasattr(loaded, "is_one")
resolver.resolve_class_extension(PluginOne)
final_extendable_cls = resolver.class_dict["Ext"]
loader = persistence.LOADERS[final_extendable_cls]["void"]
loaded = loader.load()
assert "hello" in loaded.return_hello()
assert hasattr(loaded, "is_one")

0 comments on commit 1c45582

Please sign in to comment.