Commit 5b5d597c authored by FichteFoll's avatar FichteFoll

Improve live printing for --test-repositories test

parent 7a926e05
...@@ -465,16 +465,18 @@ class TestContainer(object): ...@@ -465,16 +465,18 @@ class TestContainer(object):
A file-like object used for diagnostic output that provides .write() A file-like object used for diagnostic output that provides .write()
and .flush() and .flush()
""" """
# TODO multi-threading
stream.write("%s ... " % path)
stream.flush()
cls._write(stream, "%s ... " % path) success = False
try:
if re.match('https?://', path, re.I) is not None: if re.match('https?://', path, re.I) is not None:
# Download the repository # Download the repository
try: try:
with urlopen(path) as f: with urlopen(path) as f:
source = f.read().decode("utf-8", 'replace') source = f.read().decode("utf-8", 'replace')
except Exception as e: except Exception as e:
cls._write(stream, 'failed (%s)\n' % str_cls(e))
yield cls._fail("Downloading %s failed" % path, e) yield cls._fail("Downloading %s failed" % path, e)
return return
else: else:
...@@ -482,7 +484,6 @@ class TestContainer(object): ...@@ -482,7 +484,6 @@ class TestContainer(object):
with _open(path) as f: with _open(path) as f:
source = f.read().decode('utf-8', 'replace') source = f.read().decode('utf-8', 'replace')
except Exception as e: except Exception as e:
cls._write(stream, 'failed (%s)\n' % str_cls(e))
yield cls._fail("Opening %s failed" % path, e) yield cls._fail("Opening %s failed" % path, e)
return return
...@@ -507,13 +508,20 @@ class TestContainer(object): ...@@ -507,13 +508,20 @@ class TestContainer(object):
yield cls._fail("Unrecognized schema version %s in %s" yield cls._fail("Unrecognized schema version %s in %s"
% (schema, path)) % (schema, path))
return return
success = True
# Do not generate 1000 failing tests for not yet updated repos # Do not generate 1000 failing tests for not yet updated repos
if schema != '3.0.0': if schema != '3.0.0':
cls._write(stream, "skipping (schema version %s)\n" stream.write("skipping (schema version %s)"
% data['schema_version']) % data['schema_version'])
return return
else:
cls._write(stream, 'done\n') stream.write("done")
finally:
if not success:
stream.write("failed")
stream.write("\n")
# `path` is for output during tests only # `path` is for output during tests only
yield cls._test_repository_keys, (path, data) yield cls._test_repository_keys, (path, data)
...@@ -544,21 +552,6 @@ class TestContainer(object): ...@@ -544,21 +552,6 @@ class TestContainer(object):
return cls._test_error, args return cls._test_error, args
@classmethod
def _write(cls, stream, string):
"""
Writes dianostic output to a file-like object.
:param stream:
Must have the methods .write() and .flush()
:param string:
The string to write - a newline will NOT be appended
"""
stream.write(string)
stream.flush()
class DefaultChannelTests(TestContainer, unittest.TestCase): class DefaultChannelTests(TestContainer, unittest.TestCase):
maxDiff = None maxDiff = None
...@@ -589,7 +582,7 @@ class DefaultChannelTests(TestContainer, unittest.TestCase): ...@@ -589,7 +582,7 @@ class DefaultChannelTests(TestContainer, unittest.TestCase):
# when run with "--test-repositories" parameter. # when run with "--test-repositories" parameter.
return return
cls._write(stream, "Fetching remote repositories:\n") stream.write("Fetching remote repositories:\n")
for repository in cls.j['repositories']: for repository in cls.j['repositories']:
if repository.startswith('.'): if repository.startswith('.'):
...@@ -600,7 +593,8 @@ class DefaultChannelTests(TestContainer, unittest.TestCase): ...@@ -600,7 +593,8 @@ class DefaultChannelTests(TestContainer, unittest.TestCase):
for test in cls._include_tests(repository, stream): for test in cls._include_tests(repository, stream):
yield test yield test
cls._write(stream, '\n') stream.write('\n')
stream.flush()
class DefaultRepositoryTests(TestContainer, unittest.TestCase): class DefaultRepositoryTests(TestContainer, unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment