From: CaselIT Date: Wed, 1 Dec 2021 21:11:36 +0000 (+0100) Subject: Provide useful error message in stub tests X-Git-Tag: rel_1_7_6~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fce5dbd53cd23c972e82f8cba91a3b4624e523b;p=thirdparty%2Fsqlalchemy%2Falembic.git Provide useful error message in stub tests Change-Id: I6d2662cb5c13d5438210aa001cbdb8c7eb876bb7 --- diff --git a/tests/test_stubs.py b/tests/test_stubs.py index efb1a9df..d1e286ee 100644 --- a/tests/test_stubs.py +++ b/tests/test_stubs.py @@ -1,3 +1,4 @@ +import difflib from pathlib import Path import subprocess import sys @@ -31,11 +32,23 @@ class TestStubFiles(TestBase): def test_op_pyi(self): res = run_command("op") generated = res.stdout - expected = Path(alembic.__file__).parent / "op.pyi" - eq_(generated, expected.read_text()) + file_path = Path(alembic.__file__).parent / "op.pyi" + expected = file_path.read_text() + eq_(generated, expected, compare(generated, expected)) def test_context_pyi(self): res = run_command("context") generated = res.stdout - expected = Path(alembic.__file__).parent / "context.pyi" - eq_(generated, expected.read_text()) + file_path = Path(alembic.__file__).parent / "context.pyi" + expected = file_path.read_text() + eq_(generated, expected, compare(generated, expected)) + + +def compare(actual: str, expected: str): + diff = difflib.unified_diff( + actual.splitlines(), + expected.splitlines(), + fromfile="generated", + tofile="expected", + ) + return "\n".join(diff)