summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-02-20 11:58:30 +0100
committermathieui <mathieui@mathieui.net>2021-02-20 11:58:30 +0100
commit35a9526a4ce177d00be1fc6d168626c1d6edef31 (patch)
tree94c020b7b61323c533e5fdcbf466d7df51095376
parent2f0660c6ffc39639739fb6c0adfaa555e5780a73 (diff)
parent7e3e056e6b630411a1d05ffbfbc11b9fe4d45f5c (diff)
downloadslixmpp-35a9526a4ce177d00be1fc6d168626c1d6edef31.tar.gz
slixmpp-35a9526a4ce177d00be1fc6d168626c1d6edef31.tar.bz2
slixmpp-35a9526a4ce177d00be1fc6d168626c1d6edef31.tar.xz
slixmpp-35a9526a4ce177d00be1fc6d168626c1d6edef31.zip
Merge branch 'enable-debug-on-run-tests' into 'master'
run_tests: add a command-line option to enable debug logs See merge request poezio/slixmpp!136
-rwxr-xr-xrun_tests.py14
-rw-r--r--slixmpp/test/slixtest.py14
2 files changed, 22 insertions, 6 deletions
diff --git a/run_tests.py b/run_tests.py
index 3b9df045..f5103b15 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -10,7 +10,7 @@ from importlib import import_module
from pathlib import Path
-def run_tests(filenames=None):
+def run_tests(filenames=None, debug=False):
"""
Find and run all tests in the tests/ directory.
@@ -31,9 +31,12 @@ def run_tests(filenames=None):
tests = unittest.TestSuite(suites)
runner = unittest.TextTestRunner(verbosity=2)
- # Disable logging output
- logging.basicConfig(level=100)
- logging.disable(100)
+ if debug:
+ logging.basicConfig(level='DEBUG')
+ else:
+ # Disable logging output
+ logging.basicConfig(level=100)
+ logging.disable(100)
result = runner.run(tests)
return result
@@ -58,9 +61,10 @@ class TestCommand(Command):
if __name__ == '__main__':
parser = ArgumentParser(description='Run unit tests.')
parser.add_argument('tests', metavar='TEST', nargs='*', help='list of tests to run, or nothing to run them all')
+ parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False, help='enable debug output')
args = parser.parse_args()
- result = run_tests(args.tests)
+ result = run_tests(args.tests, args.debug)
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s'/>" % (
"xmlns='http//andyet.net/protocol/tests'",
result.testsRun, len(result.errors),
diff --git a/slixmpp/test/slixtest.py b/slixmpp/test/slixtest.py
index 668b02c0..d0e380f7 100644
--- a/slixmpp/test/slixtest.py
+++ b/slixmpp/test/slixtest.py
@@ -434,7 +434,9 @@ class SlixTest(unittest.TestCase):
timeout -- Time to wait in seconds for data to be received by
a live connection.
"""
+ self.wait_()
self.xmpp.data_received(data)
+ self.wait_()
def recv_header(self, sto='',
sfrom='',
@@ -623,10 +625,20 @@ class SlixTest(unittest.TestCase):
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(self.xmpp.run_filters(), loop=loop)
queue = self.xmpp.waiting_queue
- print(queue)
loop.run_until_complete(queue.join())
future.cancel()
+ def wait_(self):
+ async def yield_some():
+ for i in range(100):
+ await asyncio.sleep(0)
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(yield_some())
+
+ def run_coro(self, coro):
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(coro)
+
def stream_close(self):
"""
Disconnect the dummy XMPP client.