scripts: .start can now return an Addon instance
This commit is contained in:
parent
05caa0a03d
commit
9294d19f90
|
@ -99,7 +99,6 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler):
|
|||
return False
|
||||
if os.path.basename(event.src_path).startswith("."):
|
||||
return False
|
||||
print(event.src_path)
|
||||
return True
|
||||
|
||||
def on_modified(self, event):
|
||||
|
@ -151,7 +150,10 @@ class Script:
|
|||
|
||||
def load_script(self):
|
||||
self.ns = load_script(self.path, self.args)
|
||||
self.run("start")
|
||||
ret = self.run("start")
|
||||
if ret:
|
||||
self.ns = ret
|
||||
self.run("start")
|
||||
|
||||
def tick(self):
|
||||
if self.should_reload.is_set():
|
||||
|
|
|
@ -116,6 +116,19 @@ class TestScript(mastertest.MasterTest):
|
|||
assert not fm.state.view[0].request.is_replay
|
||||
assert fm.state.view[1].request.is_replay
|
||||
|
||||
def test_addon(self):
|
||||
s = state.State()
|
||||
m = master.FlowMaster(options.Options(), None, s)
|
||||
sc = script.Script(
|
||||
tutils.test_data.path(
|
||||
"data/addonscripts/addon.py"
|
||||
)
|
||||
)
|
||||
m.addons.add(sc)
|
||||
assert sc.ns.event_log == [
|
||||
'scriptstart', 'addonstart', 'addonconfigure'
|
||||
]
|
||||
|
||||
|
||||
class TestScriptLoader(mastertest.MasterTest):
|
||||
def test_simple(self):
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
event_log = []
|
||||
|
||||
|
||||
class Addon:
|
||||
@property
|
||||
def event_log(self):
|
||||
return event_log
|
||||
|
||||
def start(self):
|
||||
event_log.append("addonstart")
|
||||
|
||||
def configure(self, options):
|
||||
event_log.append("addonconfigure")
|
||||
|
||||
|
||||
def configure(options):
|
||||
event_log.append("addonconfigure")
|
||||
|
||||
|
||||
def start():
|
||||
event_log.append("scriptstart")
|
||||
return Addon()
|
Loading…
Reference in New Issue