diff options
author | Brian Harring <ferringb@gmail.com> | 2022-12-24 13:14:53 -0800 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2022-12-25 19:49:11 +0200 |
commit | d6a7c2e44b4f497357f8569d423104232a58f384 (patch) | |
tree | 625ac52169356714a9f5e69e11f2b6cc2d72355a /tests/test_demandload.py | |
parent | compression: prefer gtar over tar if available (diff) | |
download | snakeoil-d6a7c2e44b4f497357f8569d423104232a58f384.tar.gz snakeoil-d6a7c2e44b4f497357f8569d423104232a58f384.tar.bz2 snakeoil-d6a7c2e44b4f497357f8569d423104232a58f384.zip |
Reformat w/ black 22.12.0 for consistency.
Signed-off-by: Brian Harring <ferringb@gmail.com>
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests/test_demandload.py')
-rw-r--r-- | tests/test_demandload.py | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/tests/test_demandload.py b/tests/test_demandload.py index ec2661c9..843cf801 100644 --- a/tests/test_demandload.py +++ b/tests/test_demandload.py @@ -9,6 +9,7 @@ from snakeoil import demandload # setup is what the test expects. # it also explicitly resets the state on the way out. + def reset_globals(functor): def f(*args, **kwds): orig_demandload = demandload.demandload @@ -22,60 +23,61 @@ def reset_globals(functor): demandload.demand_compile_regexp = orig_demand_compile demandload._protection_enabled = orig_protection demandload._noisy_protection = orig_noisy + return f class TestParser: - @reset_globals def test_parse(self): for input, output in [ - ('foo', [('foo', 'foo')]), - ('foo:bar', [('foo.bar', 'bar')]), - ('foo:bar,baz@spork', [('foo.bar', 'bar'), ('foo.baz', 'spork')]), - ('foo@bar', [('foo', 'bar')]), - ('foo_bar', [('foo_bar', 'foo_bar')]), - ]: + ("foo", [("foo", "foo")]), + ("foo:bar", [("foo.bar", "bar")]), + ("foo:bar,baz@spork", [("foo.bar", "bar"), ("foo.baz", "spork")]), + ("foo@bar", [("foo", "bar")]), + ("foo_bar", [("foo_bar", "foo_bar")]), + ]: assert output == list(demandload.parse_imports([input])) - pytest.raises(ValueError, list, demandload.parse_imports(['a.b'])) - pytest.raises(ValueError, list, demandload.parse_imports(['a:,'])) - pytest.raises(ValueError, list, demandload.parse_imports(['a:b,x@'])) - pytest.raises(ValueError, list, demandload.parse_imports(['b-x'])) - pytest.raises(ValueError, list, demandload.parse_imports([' b_x'])) + pytest.raises(ValueError, list, demandload.parse_imports(["a.b"])) + pytest.raises(ValueError, list, demandload.parse_imports(["a:,"])) + pytest.raises(ValueError, list, demandload.parse_imports(["a:b,x@"])) + pytest.raises(ValueError, list, demandload.parse_imports(["b-x"])) + pytest.raises(ValueError, list, demandload.parse_imports([" b_x"])) class TestPlaceholder: - @reset_globals def test_getattr(self): scope = {} - placeholder = demandload.Placeholder(scope, 'foo', list) - assert scope == object.__getattribute__(placeholder, '_scope') + placeholder = demandload.Placeholder(scope, "foo", list) + assert scope == object.__getattribute__(placeholder, "_scope") assert placeholder.__doc__ == [].__doc__ - assert scope['foo'] == [] + assert scope["foo"] == [] demandload._protection_enabled = lambda: True with pytest.raises(ValueError): - getattr(placeholder, '__doc__') + getattr(placeholder, "__doc__") @reset_globals def test__str__(self): scope = {} - placeholder = demandload.Placeholder(scope, 'foo', list) - assert scope == object.__getattribute__(placeholder, '_scope') + placeholder = demandload.Placeholder(scope, "foo", list) + assert scope == object.__getattribute__(placeholder, "_scope") assert str(placeholder) == str([]) - assert scope['foo'] == [] + assert scope["foo"] == [] @reset_globals def test_call(self): def passthrough(*args, **kwargs): return args, kwargs + def get_func(): return passthrough + scope = {} - placeholder = demandload.Placeholder(scope, 'foo', get_func) - assert scope == object.__getattribute__(placeholder, '_scope') - assert (('arg',), {'kwarg': 42}) == placeholder('arg', kwarg=42) - assert passthrough is scope['foo'] + placeholder = demandload.Placeholder(scope, "foo", get_func) + assert scope == object.__getattribute__(placeholder, "_scope") + assert (("arg",), {"kwarg": 42}) == placeholder("arg", kwarg=42) + assert passthrough is scope["foo"] @reset_globals def test_setattr(self): @@ -83,45 +85,43 @@ class TestPlaceholder: pass scope = {} - placeholder = demandload.Placeholder(scope, 'foo', Struct) + placeholder = demandload.Placeholder(scope, "foo", Struct) placeholder.val = 7 demandload._protection_enabled = lambda: True with pytest.raises(ValueError): - getattr(placeholder, 'val') - assert 7 == scope['foo'].val + getattr(placeholder, "val") + assert 7 == scope["foo"].val class TestImport: - @reset_globals def test_demandload(self): scope = {} - demandload.demandload('snakeoil:demandload', scope=scope) - assert demandload is not scope['demandload'] - assert demandload.demandload is scope['demandload'].demandload - assert demandload is scope['demandload'] + demandload.demandload("snakeoil:demandload", scope=scope) + assert demandload is not scope["demandload"] + assert demandload.demandload is scope["demandload"].demandload + assert demandload is scope["demandload"] @reset_globals def test_disabled_demandload(self): scope = {} - demandload.disabled_demandload('snakeoil:demandload', scope=scope) - assert demandload is scope['demandload'] + demandload.disabled_demandload("snakeoil:demandload", scope=scope) + assert demandload is scope["demandload"] class TestDemandCompileRegexp: - @reset_globals def test_demand_compile_regexp(self): scope = {} - demandload.demand_compile_regexp('foo', 'frob', scope=scope) - assert list(scope.keys()) == ['foo'] - assert 'frob' == scope['foo'].pattern - assert 'frob' == scope['foo'].pattern + demandload.demand_compile_regexp("foo", "frob", scope=scope) + assert list(scope.keys()) == ["foo"] + assert "frob" == scope["foo"].pattern + assert "frob" == scope["foo"].pattern # verify it's delayed via a bad regex. - demandload.demand_compile_regexp('foo', 'f(', scope=scope) - assert list(scope.keys()) == ['foo'] + demandload.demand_compile_regexp("foo", "f(", scope=scope) + assert list(scope.keys()) == ["foo"] # should blow up on accessing an attribute. - obj = scope['foo'] + obj = scope["foo"] with pytest.raises(sre_constants.error): - getattr(obj, 'pattern') + getattr(obj, "pattern") |