tests: fix attempt 0

This commit is contained in:
Mark Joshwel 2023-09-02 10:08:49 +00:00
parent 592a2c661c
commit af083fb49a

12
test.py
View file

@ -31,11 +31,11 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/> For more information, please refer to <http://unlicense.org/>
""" """
from io import StringIO
from sys import stderr from sys import stderr
from textwrap import indent from textwrap import indent
from traceback import format_exception from traceback import format_exception
from typing import Final, NamedTuple from typing import Final, NamedTuple
from io import StringIO
import surplus import surplus
@ -52,7 +52,7 @@ class TestFailure(NamedTuple):
test: ContinuityTest test: ContinuityTest
exception: Exception exception: Exception
output: str output: str
test_stderr: StringIO stderr: StringIO
tests: list[ContinuityTest] = [ tests: list[ContinuityTest] = [
@ -95,7 +95,7 @@ tests: list[ContinuityTest] = [
"St Lucia, Greater Brisbane, Dutton Park\n" "St Lucia, Greater Brisbane, Dutton Park\n"
"4072\n" "4072\n"
"Queensland, Australia" "Queensland, Australia"
) ),
], ],
), ),
ContinuityTest( ContinuityTest(
@ -163,7 +163,9 @@ def main() -> int:
raise ContinuityFailure("did not match any expected outputs") raise ContinuityFailure("did not match any expected outputs")
except Exception as exc: except Exception as exc:
failures.append(TestFailure(test=test, exception=exc, output=output, stderr=test_stderr)) failures.append(
TestFailure(test=test, exception=exc, output=output, stderr=test_stderr)
)
stderr.write(indent(text="(fail)", prefix=INDENT * " ") + "\n\n") stderr.write(indent(text="(fail)", prefix=INDENT * " ") + "\n\n")
else: else:
@ -186,7 +188,7 @@ def main() -> int:
+ (indent(text=repr(fail.output), prefix=(2 * INDENT) * " ") + "\n") + (indent(text=repr(fail.output), prefix=(2 * INDENT) * " ") + "\n")
+ (indent(text=fail.output, prefix=(2 * INDENT) * " ") + "\n\n") + (indent(text=fail.output, prefix=(2 * INDENT) * " ") + "\n\n")
+ (indent(text="stderr:", prefix=INDENT * " ") + "\n") + (indent(text="stderr:", prefix=INDENT * " ") + "\n")
+ (indent(text=fail.test_stderr.getvalue(), prefix=(2 * INDENT) * " ")) + (indent(text=fail.stderr.getvalue(), prefix=(2 * INDENT) * " "))
) )
passes = len(tests) - len(failures) passes = len(tests) - len(failures)