Deprecate Flow.unload_script in favor of Flow.unload_scripts

In the presence of arguments, unloading a single script is clumsy and
less useful.
This commit is contained in:
Aldo Cortesi 2014-01-13 14:20:34 +13:00
parent 4f69eef8f3
commit 069aca1df4
2 changed files with 12 additions and 9 deletions

View File

@ -1394,7 +1394,8 @@ class FlowMaster(controller.Master):
"""
pass
def unload_script(self, script):
def unload_scripts(self):
for script in self.scripts[:]:
script.unload()
self.scripts.remove(script)
@ -1627,8 +1628,7 @@ class FlowMaster(controller.Master):
return f
def shutdown(self):
for script in self.scripts:
self.unload_script(script)
self.unload_scripts()
controller.Master.shutdown(self)
if self.stream:
for i in self.state._flow_list:

View File

@ -565,8 +565,7 @@ class TestFlowMaster:
fm = flow.FlowMaster(None, s)
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
assert not fm.unload_script(fm.scripts[0])
assert not fm.unload_script(fm.scripts[0])
assert not fm.unload_scripts()
assert fm.load_script("nonexistent")
assert "ValueError" in fm.load_script(tutils.test_data.path("scripts/starterr.py"))
assert len(fm.scripts) == 0
@ -613,9 +612,13 @@ class TestFlowMaster:
fm.handle_clientdisconnect(dc)
assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"
#unload first script
fm.unload_script(fm.scripts[0])
assert len(fm.scripts) == 1
fm.unload_scripts()
assert len(fm.scripts) == 0
assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
err = flow.Error(f.request, "msg")
err.reply = controller.DummyReply()
fm.handle_error(err)