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 ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 0.2.6
3
+ Version: 0.3.0
4
4
  Summary: A collection of Python modules that are useful across multiple projects
5
5
  Author-email: Francis Potter <wizlib@steampunkwizard.ca>
6
6
  License: MIT
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 0.2.6
3
+ Version: 0.3.0
4
4
  Summary: A collection of Python modules that are useful across multiple projects
5
5
  Author-email: Francis Potter <wizlib@steampunkwizard.ca>
6
6
  License: MIT
@@ -1,8 +1,10 @@
1
1
  .version
2
2
  README.md
3
3
  pyproject.toml
4
+ test/test_super_wrapper.py
4
5
  wizlib/__init__.py
5
6
  wizlib/rlinput.py
7
+ wizlib/super_wrapper.py
6
8
  wizlib.egg-info/PKG-INFO
7
9
  wizlib.egg-info/SOURCES.txt
8
10
  wizlib.egg-info/dependency_links.txt
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