summaryrefslogtreecommitdiff
path: root/tests/test_marshalling.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_marshalling.py')
-rw-r--r--tests/test_marshalling.py81
1 files changed, 52 insertions, 29 deletions
diff --git a/tests/test_marshalling.py b/tests/test_marshalling.py
index c209388..36c8aca 100644
--- a/tests/test_marshalling.py
+++ b/tests/test_marshalling.py
@@ -39,10 +39,14 @@ class InheritedDummyClass(DummyClass):
class TestCallableToRef:
- @pytest.mark.parametrize('obj, error', [
- (partial(DummyClass.meth), 'Cannot create a reference to a partial()'),
- (lambda: None, 'Cannot create a reference to a lambda')
- ], ids=['partial', 'lambda'])
+ @pytest.mark.parametrize(
+ "obj, error",
+ [
+ (partial(DummyClass.meth), "Cannot create a reference to a partial()"),
+ (lambda: None, "Cannot create a reference to a lambda"),
+ ],
+ ids=["partial", "lambda"],
+ )
def test_errors(self, obj, error):
exc = pytest.raises(SerializationError, callable_to_ref, obj)
assert str(exc.value) == error
@@ -52,18 +56,33 @@ class TestCallableToRef:
pass
exc = pytest.raises(SerializationError, callable_to_ref, nested)
- assert str(exc.value) == 'Cannot create a reference to a nested function'
-
- @pytest.mark.parametrize('input,expected', [
- (DummyClass.meth, 'test_marshalling:DummyClass.meth'),
- (DummyClass.classmeth, 'test_marshalling:DummyClass.classmeth'),
- (DummyClass.InnerDummyClass.innerclassmeth,
- 'test_marshalling:DummyClass.InnerDummyClass.innerclassmeth'),
- (DummyClass.staticmeth, 'test_marshalling:DummyClass.staticmeth'),
- (InheritedDummyClass.classmeth, 'test_marshalling:InheritedDummyClass.classmeth'),
- (timedelta, 'datetime:timedelta'),
- ], ids=['unbound method', 'class method', 'inner class method', 'static method',
- 'inherited class method', 'timedelta'])
+ assert str(exc.value) == "Cannot create a reference to a nested function"
+
+ @pytest.mark.parametrize(
+ "input,expected",
+ [
+ (DummyClass.meth, "test_marshalling:DummyClass.meth"),
+ (DummyClass.classmeth, "test_marshalling:DummyClass.classmeth"),
+ (
+ DummyClass.InnerDummyClass.innerclassmeth,
+ "test_marshalling:DummyClass.InnerDummyClass.innerclassmeth",
+ ),
+ (DummyClass.staticmeth, "test_marshalling:DummyClass.staticmeth"),
+ (
+ InheritedDummyClass.classmeth,
+ "test_marshalling:InheritedDummyClass.classmeth",
+ ),
+ (timedelta, "datetime:timedelta"),
+ ],
+ ids=[
+ "unbound method",
+ "class method",
+ "inner class method",
+ "static method",
+ "inherited class method",
+ "timedelta",
+ ],
+ )
def test_valid_refs(self, input, expected):
assert callable_to_ref(input) == expected
@@ -71,21 +90,25 @@ class TestCallableToRef:
class TestCallableFromRef:
def test_valid_ref(self):
from logging.handlers import RotatingFileHandler
- assert callable_from_ref('logging.handlers:RotatingFileHandler') is RotatingFileHandler
+
+ assert (
+ callable_from_ref("logging.handlers:RotatingFileHandler")
+ is RotatingFileHandler
+ )
def test_complex_path(self):
- pkg1 = ModuleType('pkg1')
- pkg1.pkg2 = 'blah'
- pkg2 = ModuleType('pkg1.pkg2')
+ pkg1 = ModuleType("pkg1")
+ pkg1.pkg2 = "blah"
+ pkg2 = ModuleType("pkg1.pkg2")
pkg2.varname = lambda: None
- sys.modules['pkg1'] = pkg1
- sys.modules['pkg1.pkg2'] = pkg2
- assert callable_from_ref('pkg1.pkg2:varname') == pkg2.varname
-
- @pytest.mark.parametrize('input,error', [
- (object(), TypeError),
- ('module', ValueError),
- ('module:blah', LookupError)
- ], ids=['raw object', 'module', 'module attribute'])
+ sys.modules["pkg1"] = pkg1
+ sys.modules["pkg1.pkg2"] = pkg2
+ assert callable_from_ref("pkg1.pkg2:varname") == pkg2.varname
+
+ @pytest.mark.parametrize(
+ "input,error",
+ [(object(), TypeError), ("module", ValueError), ("module:blah", LookupError)],
+ ids=["raw object", "module", "module attribute"],
+ )
def test_lookup_error(self, input, error):
pytest.raises(error, callable_from_ref, input)