Commit 5b5d597c authored by FichteFoll's avatar FichteFoll

Improve live printing for --test-repositories test

parent 7a926e05
...@@ -465,55 +465,63 @@ class TestContainer(object): ...@@ -465,55 +465,63 @@ 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
else:
try:
with _open(path) as f:
source = f.read().decode('utf-8', 'replace')
except Exception as e:
yield cls._fail("Opening %s failed" % path, e)
return
if not source:
yield cls._fail("%s is empty" % path)
return return
else:
# Parse the repository
try: try:
with _open(path) as f: data = json.loads(source)
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("Could not parse %s" % path, e)
yield cls._fail("Opening %s failed" % path, e)
return return
if not source: # Check for the schema version first (and generator failures it's
yield cls._fail("%s is empty" % path) # badly formatted)
return if 'schema_version' not in data:
yield cls._fail("No schema_version found in %s" % path)
return
schema = data['schema_version']
if schema != '3.0.0' and float(schema) not in (1.0, 1.1, 1.2, 2.0):
yield cls._fail("Unrecognized schema version %s in %s"
% (schema, path))
return
# Parse the repository success = True
try:
data = json.loads(source)
except Exception as e:
yield cls._fail("Could not parse %s" % path, e)
return
# Check for the schema version first (and generator failures it's # Do not generate 1000 failing tests for not yet updated repos
# badly formatted) if schema != '3.0.0':
if 'schema_version' not in data: stream.write("skipping (schema version %s)"
yield cls._fail("No schema_version found in %s" % path) % data['schema_version'])
return return
schema = data['schema_version'] else:
if schema != '3.0.0' and float(schema) not in (1.0, 1.1, 1.2, 2.0): stream.write("done")
yield cls._fail("Unrecognized schema version %s in %s" finally:
% (schema, path)) if not success:
return stream.write("failed")
# Do not generate 1000 failing tests for not yet updated repos stream.write("\n")
if schema != '3.0.0':
cls._write(stream, "skipping (schema version %s)\n"
% data['schema_version'])
return
cls._write(stream, 'done\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