Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #95: Resolve E741 errors #96

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testing/test_hookrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def hello(self, arg):

plugin = Plugin()
pm.register(plugin)
l = hook.hello(arg=3)
assert l == [4]
out = hook.hello(arg=3)
assert out == [4]
assert not hasattr(hook, 'world')
pm.unregister(plugin)
assert hook.hello(arg=3) == []
Expand Down
40 changes: 20 additions & 20 deletions testing/test_method_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,42 +215,42 @@ def test_load_setuptools_not_installed(monkeypatch, pm):


def test_add_tracefuncs(he_pm):
l = []
out = []

class api1(object):
@hookimpl
def he_method1(self):
l.append("he_method1-api1")
out.append("he_method1-api1")

class api2(object):
@hookimpl
def he_method1(self):
l.append("he_method1-api2")
out.append("he_method1-api2")

he_pm.register(api1())
he_pm.register(api2())

def before(hook_name, hook_impls, kwargs):
l.append((hook_name, list(hook_impls), kwargs))
out.append((hook_name, list(hook_impls), kwargs))

def after(outcome, hook_name, hook_impls, kwargs):
l.append((outcome, hook_name, list(hook_impls), kwargs))
out.append((outcome, hook_name, list(hook_impls), kwargs))

undo = he_pm.add_hookcall_monitoring(before, after)

he_pm.hook.he_method1(arg=1)
assert len(l) == 4
assert l[0][0] == "he_method1"
assert len(l[0][1]) == 2
assert isinstance(l[0][2], dict)
assert l[1] == "he_method1-api2"
assert l[2] == "he_method1-api1"
assert len(l[3]) == 4
assert l[3][1] == l[0][0]
assert len(out) == 4
assert out[0][0] == "he_method1"
assert len(out[0][1]) == 2
assert isinstance(out[0][2], dict)
assert out[1] == "he_method1-api2"
assert out[2] == "he_method1-api1"
assert len(out[3]) == 4
assert out[3][1] == out[0][0]

undo()
he_pm.hook.he_method1(arg=1)
assert len(l) == 4 + 2
assert len(out) == 4 + 2


def test_hook_tracing(he_pm):
Expand All @@ -268,18 +268,18 @@ def he_method1(self):
raise ValueError()

he_pm.register(api1())
l = []
he_pm.trace.root.setwriter(l.append)
out = []
he_pm.trace.root.setwriter(out.append)
undo = he_pm.enable_tracing()
try:
indent = he_pm.trace.root.indent
he_pm.hook.he_method1(arg=1)
assert indent == he_pm.trace.root.indent
assert len(l) == 2
assert 'he_method1' in l[0]
assert 'finish' in l[1]
assert len(out) == 2
assert 'he_method1' in out[0]
assert 'finish' in out[1]

l[:] = []
out[:] = []
he_pm.register(api2())

with pytest.raises(ValueError):
Expand Down
40 changes: 20 additions & 20 deletions testing/test_multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@


def test_uses_copy_of_methods():
l = [lambda: 42]
mc = _LegacyMultiCall(l, {})
out = [lambda: 42]
mc = _LegacyMultiCall(out, {})
repr(mc)
l[:] = []
out[:] = []
res = mc.execute()
return res == 42

Expand Down Expand Up @@ -112,46 +112,46 @@ def m2():


def test_hookwrapper():
l = []
out = []

@hookimpl(hookwrapper=True)
def m1():
l.append("m1 init")
out.append("m1 init")
yield None
l.append("m1 finish")
out.append("m1 finish")

@hookimpl
def m2():
l.append("m2")
out.append("m2")
return 2

res = MC([m2, m1], {})
assert res == [2]
assert l == ["m1 init", "m2", "m1 finish"]
l[:] = []
assert out == ["m1 init", "m2", "m1 finish"]
out[:] = []
res = MC([m2, m1], {}, {"firstresult": True})
assert res == 2
assert l == ["m1 init", "m2", "m1 finish"]
assert out == ["m1 init", "m2", "m1 finish"]


def test_hookwrapper_order():
l = []
out = []

@hookimpl(hookwrapper=True)
def m1():
l.append("m1 init")
out.append("m1 init")
yield 1
l.append("m1 finish")
out.append("m1 finish")

@hookimpl(hookwrapper=True)
def m2():
l.append("m2 init")
out.append("m2 init")
yield 2
l.append("m2 finish")
out.append("m2 finish")

res = MC([m2, m1], {})
assert res == []
assert l == ["m1 init", "m2 init", "m2 finish", "m1 finish"]
assert out == ["m1 init", "m2 init", "m2 finish", "m1 finish"]


def test_hookwrapper_not_yield():
Expand All @@ -177,18 +177,18 @@ def m1():

@pytest.mark.parametrize("exc", [ValueError, SystemExit])
def test_hookwrapper_exception(exc):
l = []
out = []

@hookimpl(hookwrapper=True)
def m1():
l.append("m1 init")
out.append("m1 init")
yield None
l.append("m1 finish")
out.append("m1 finish")

@hookimpl
def m2():
raise exc

with pytest.raises(exc):
MC([m2, m1], {})
assert l == ["m1 init", "m1 finish"]
assert out == ["m1 init", "m1 finish"]
70 changes: 35 additions & 35 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class A(object):
assert pm.is_registered(a1)
pm.register(a2, "hello")
assert pm.is_registered(a2)
l = pm.get_plugins()
assert a1 in l
assert a2 in l
out = pm.get_plugins()
assert a1 in out
assert a2 in out
assert pm.get_plugin('hello') == a2
assert pm.unregister(a1) == a1
assert not pm.is_registered(a1)

l = pm.list_name_plugin()
assert len(l) == 1
assert l == [("hello", a2)]
out = pm.list_name_plugin()
assert len(out) == 1
assert out == [("hello", a2)]


def test_has_plugin(pm):
Expand Down Expand Up @@ -162,25 +162,25 @@ def he_method1(self, arg):
pm.add_hookspecs(Hooks)

pm.hook.he_method1.call_historic(kwargs=dict(arg=1))
l = []
out = []

class Plugin(object):
@hookimpl
def he_method1(self, arg):
l.append(arg)
out.append(arg)

pm.register(Plugin())
assert l == [1]
assert out == [1]

class Plugin2(object):
@hookimpl
def he_method1(self, arg):
l.append(arg * 10)
out.append(arg * 10)

pm.register(Plugin2())
assert l == [1, 10]
assert out == [1, 10]
pm.hook.he_method1.call_historic(kwargs=dict(arg=12))
assert l == [1, 10, 120, 12]
assert out == [1, 10, 120, 12]


def test_with_result_memorized(pm):
Expand All @@ -191,16 +191,16 @@ def he_method1(self, arg):
pm.add_hookspecs(Hooks)

he_method1 = pm.hook.he_method1
he_method1.call_historic(lambda res: l.append(res), dict(arg=1))
l = []
he_method1.call_historic(lambda res: out.append(res), dict(arg=1))
out = []

class Plugin(object):
@hookimpl
def he_method1(self, arg):
return arg * 10

pm.register(Plugin())
assert l == [10]
assert out == [10]


def test_with_callbacks_immediately_executed(pm):
Expand All @@ -225,15 +225,15 @@ class Plugin3(object):
def he_method1(self, arg):
return arg * 30

l = []
out = []
pm.register(Plugin1())
pm.register(Plugin2())

he_method1 = pm.hook.he_method1
he_method1.call_historic(lambda res: l.append(res), dict(arg=1))
assert l == [20, 10]
he_method1.call_historic(lambda res: out.append(res), dict(arg=1))
assert out == [20, 10]
pm.register(Plugin3())
assert l == [20, 10, 30]
assert out == [20, 10, 30]


def test_register_historic_incompat_hookwrapper(pm):
Expand All @@ -244,12 +244,12 @@ def he_method1(self, arg):

pm.add_hookspecs(Hooks)

l = []
out = []

class Plugin(object):
@hookimpl(hookwrapper=True)
def he_method1(self, arg):
l.append(arg)
out.append(arg)

with pytest.raises(PluginValidationError):
pm.register(Plugin())
Expand All @@ -266,8 +266,8 @@ def he_method1(self, arg):
def he_method1(arg):
return arg * 10

l = pm.hook.he_method1.call_extra([he_method1], dict(arg=1))
assert l == [10]
out = pm.hook.he_method1.call_extra([he_method1], dict(arg=1))
assert out == [10]


def test_call_with_too_few_args(pm):
Expand Down Expand Up @@ -296,17 +296,17 @@ def he_method1(self, arg):

pm.add_hookspecs(Hooks)

l = []
out = []

class Plugin1(object):
@hookimpl
def he_method1(self, arg):
l.append(arg)
out.append(arg)

class Plugin2(object):
@hookimpl
def he_method1(self, arg):
l.append(arg * 10)
out.append(arg * 10)

class PluginNo(object):
pass
Expand All @@ -316,26 +316,26 @@ class PluginNo(object):
pm.register(plugin2)
pm.register(plugin3)
pm.hook.he_method1(arg=1)
assert l == [10, 1]
l[:] = []
assert out == [10, 1]
out[:] = []

hc = pm.subset_hook_caller("he_method1", [plugin1])
hc(arg=2)
assert l == [20]
l[:] = []
assert out == [20]
out[:] = []

hc = pm.subset_hook_caller("he_method1", [plugin2])
hc(arg=2)
assert l == [2]
l[:] = []
assert out == [2]
out[:] = []

pm.unregister(plugin1)
hc(arg=2)
assert l == []
l[:] = []
assert out == []
out[:] = []

pm.hook.he_method1(arg=1)
assert l == [10]
assert out == [10]


def test_multicall_deprecated(pm):
Expand Down
Loading