Cleanup __main__.py a little bit

This commit is contained in:
louiz’
2016-10-07 23:25:26 +02:00
parent b7f02f79fa
commit 6ca8cd505f
+14 -11
View File
@@ -91,10 +91,11 @@ class XMPPComponent(slixmpp.BaseXMPP):
self.run_scenario() self.run_scenario()
def run_scenario(self): def run_scenario(self):
if scenario.steps: if self.scenario.steps:
step = scenario.steps.pop(0) step = self.scenario.steps.pop(0)
step(self, self.biboumi) step(self, self.biboumi)
else: else:
if self.biboumi:
self.biboumi.stop() self.biboumi.stop()
@asyncio.coroutine @asyncio.coroutine
@@ -194,10 +195,11 @@ class ProcessRunner:
class BiboumiRunner(ProcessRunner): class BiboumiRunner(ProcessRunner):
def __init__(self, name, with_valgrind): def __init__(self, name):
super().__init__() super().__init__()
self.name = name self.name = name
self.fd = open("biboumi_%s_output.txt" % (name,), "w") self.fd = open("biboumi_%s_output.txt" % (name,), "w")
with_valgrind = os.environ.get("E2E_WITH_VALGRIND") is not None
if with_valgrind: if with_valgrind:
self.create = asyncio.create_subprocess_exec("valgrind", "--suppressions=" + (os.environ.get("E2E_BIBOUMI_SUPP_DIR") or "") + "biboumi.supp", "--leak-check=full", "--show-leak-kinds=all", self.create = asyncio.create_subprocess_exec("valgrind", "--suppressions=" + (os.environ.get("E2E_BIBOUMI_SUPP_DIR") or "") + "biboumi.supp", "--leak-check=full", "--show-leak-kinds=all",
"--errors-for-leak-kinds=all", "--error-exitcode=16", "--errors-for-leak-kinds=all", "--error-exitcode=16",
@@ -248,7 +250,8 @@ class BiboumiTest:
self.scenario = scenario self.scenario = scenario
self.expected_code = expected_code self.expected_code = expected_code
def run(self, with_valgrind=True): def run(self):
with_valgrind = os.environ.get("E2E_WITH_VALGRIND") is not None
print("Running scenario: %s%s" % (self.scenario.name, " (with valgrind)" if with_valgrind else '')) print("Running scenario: %s%s" % (self.scenario.name, " (with valgrind)" if with_valgrind else ''))
# Redirect the slixmpp logging into a specific file # Redirect the slixmpp logging into a specific file
output_filename = "slixmpp_%s_output.txt" % (self.scenario.name,) output_filename = "slixmpp_%s_output.txt" % (self.scenario.name,)
@@ -259,7 +262,7 @@ class BiboumiTest:
filename=output_filename) filename=output_filename)
with open("test.conf", "w") as fd: with open("test.conf", "w") as fd:
fd.write(confs[scenario.conf]) fd.write(confs[self.scenario.conf])
try: try:
os.remove("e2e_test.sqlite") os.remove("e2e_test.sqlite")
@@ -267,7 +270,7 @@ class BiboumiTest:
pass pass
# Start the XMPP component and biboumi # Start the XMPP component and biboumi
biboumi = BiboumiRunner(scenario.name, with_valgrind) biboumi = BiboumiRunner(self.scenario.name)
xmpp = XMPPComponent(self.scenario, biboumi) xmpp = XMPPComponent(self.scenario, biboumi)
asyncio.get_event_loop().run_until_complete(biboumi.start()) asyncio.get_event_loop().run_until_complete(biboumi.start())
@@ -276,7 +279,7 @@ class BiboumiTest:
xmpp.process() xmpp.process()
code = asyncio.get_event_loop().run_until_complete(biboumi.wait()) code = asyncio.get_event_loop().run_until_complete(biboumi.wait())
xmpp.biboumi = None xmpp.biboumi = None
scenario.steps.clear() self.scenario.steps.clear()
failed = False failed = False
if not xmpp.failed: if not xmpp.failed:
if code != self.expected_code: if code != self.expected_code:
@@ -1516,11 +1519,11 @@ if __name__ == '__main__':
print("irc server started.") print("irc server started.")
print("Running %s checks for biboumi." % (len(scenarios))) print("Running %s checks for biboumi." % (len(scenarios)))
for scenario in scenarios: for s in scenarios:
test = BiboumiTest(scenario) test = BiboumiTest(s)
if not test.run(os.getenv("E2E_BIBOUMI_VALGRIND") is not None): if not test.run():
print("You can check the files slixmpp_%s_output.txt and biboumi_%s_output.txt to help you debug." % print("You can check the files slixmpp_%s_output.txt and biboumi_%s_output.txt to help you debug." %
(scenario.name, scenario.name)) (s.name, s.name))
failures += 1 failures += 1
print("Waiting for irc server to exit…") print("Waiting for irc server to exit…")