wizlib 0.2.6__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wizlib might be problematic. Click here for more details.
- wizlib-0.3.0/.version +1 -0
- {wizlib-0.2.6/wizlib.egg-info → wizlib-0.3.0}/PKG-INFO +1 -1
- wizlib-0.3.0/test/test_super_wrapper.py +36 -0
- wizlib-0.3.0/wizlib/super_wrapper.py +34 -0
- {wizlib-0.2.6 → wizlib-0.3.0/wizlib.egg-info}/PKG-INFO +1 -1
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib.egg-info/SOURCES.txt +2 -0
- wizlib-0.2.6/.version +0 -1
- {wizlib-0.2.6 → wizlib-0.3.0}/README.md +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/pyproject.toml +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/setup.cfg +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib/__init__.py +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib/rlinput.py +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib.egg-info/dependency_links.txt +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib.egg-info/requires.txt +0 -0
- {wizlib-0.2.6 → wizlib-0.3.0}/wizlib.egg-info/top_level.txt +0 -0
wizlib-0.3.0/.version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.3.0
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from unittest import TestCase
|
|
2
|
+
from unittest.mock import patch
|
|
3
|
+
from io import StringIO
|
|
4
|
+
|
|
5
|
+
from wizlib.super_wrapper import SuperWrapper
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestSuperWrapper(TestCase):
|
|
9
|
+
|
|
10
|
+
def test_super_wrapper(self):
|
|
11
|
+
|
|
12
|
+
class Parent(SuperWrapper):
|
|
13
|
+
def execute(self, method, *args, **kwargs):
|
|
14
|
+
print(f"Parent execute before")
|
|
15
|
+
method(self, *args, **kwargs)
|
|
16
|
+
print(f"Parent execute after")
|
|
17
|
+
|
|
18
|
+
class InBetween(Parent):
|
|
19
|
+
@Parent.wrap
|
|
20
|
+
def execute(self, method, *args, **kwargs):
|
|
21
|
+
print(f"IB execute before")
|
|
22
|
+
method(self, *args, **kwargs)
|
|
23
|
+
print(f"IB execute after")
|
|
24
|
+
|
|
25
|
+
class NewChild(InBetween):
|
|
26
|
+
@InBetween.wrap
|
|
27
|
+
def execute(self, name):
|
|
28
|
+
print(f"Hello {name}")
|
|
29
|
+
|
|
30
|
+
with patch('sys.stdout', o:=StringIO()):
|
|
31
|
+
c = NewChild()
|
|
32
|
+
c.execute("Jane")
|
|
33
|
+
o.seek(0)
|
|
34
|
+
r = o.read()
|
|
35
|
+
self.assertEqual(r, "Parent execute before\nIB execute before\nHello Jane\nIB execute after\nParent execute after\n")
|
|
36
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Provide a decorator to wrap a method so that it's called within the inherited
|
|
2
|
+
# version of that method.
|
|
3
|
+
#
|
|
4
|
+
# Example of use:
|
|
5
|
+
#
|
|
6
|
+
# class Parent(SuperWrapper):
|
|
7
|
+
# def execute(self, method, *args, **kwargs):
|
|
8
|
+
# print(f"Parent execute before")
|
|
9
|
+
# method(self, *args, **kwargs)
|
|
10
|
+
# print(f"Parent execute after")
|
|
11
|
+
#
|
|
12
|
+
# class InBetween(Parent):
|
|
13
|
+
# @Parent.wrap
|
|
14
|
+
# def execute(self, method, *args, **kwargs):
|
|
15
|
+
# print(f"IB execute before")
|
|
16
|
+
# method(self, *args, **kwargs)
|
|
17
|
+
# print(f"IB execute after")
|
|
18
|
+
#
|
|
19
|
+
# class NewChild(InBetween):
|
|
20
|
+
# @InBetween.wrap
|
|
21
|
+
# def execute(self, name):
|
|
22
|
+
# print(f"Hello {name}")
|
|
23
|
+
#
|
|
24
|
+
# c = NewChild()
|
|
25
|
+
# c.execute("Jane")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SuperWrapper:
|
|
29
|
+
@classmethod
|
|
30
|
+
def wrap(parent_class, method):
|
|
31
|
+
def wrapper(self, *args, **kwargs):
|
|
32
|
+
parent_method = getattr(parent_class, method.__name__)
|
|
33
|
+
return parent_method(self, method, *args, **kwargs)
|
|
34
|
+
return wrapper
|
wizlib-0.2.6/.version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.2.6
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|