From fe69c9f4a6cf4a851e051a5d0081ecc7208811ed Mon Sep 17 00:00:00 2001 From: Marko Ristin Date: Tue, 7 Nov 2023 12:52:13 +0100 Subject: [PATCH] Record intermediate test data without CR (#419) We remove carriage-return characters (`\r`) from the golden files, and save them explicitly as bytes so that we have less problems between Windows and Linux. Namely, Git treats long text files as binary so changes in the line endings are unexpectedly reported as differences. --- .../expected_symbol_table.txt | 0 .../meta_model.py | 0 .../expected_symbol_table.txt | Bin 0 -> 1507 bytes .../meta_model.py | 20 ++++++++++++++++++ tests/intermediate/test_translate.py | 19 ++++++++++++++--- 5 files changed, 36 insertions(+), 3 deletions(-) rename test_data/intermediate/expected/documentation/{docstring_as_raw_string => docstring_with_special_characters_in_literal}/expected_symbol_table.txt (100%) rename test_data/intermediate/expected/documentation/{docstring_as_raw_string => docstring_with_special_characters_in_literal}/meta_model.py (100%) create mode 100644 test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt create mode 100644 test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py diff --git a/test_data/intermediate/expected/documentation/docstring_as_raw_string/expected_symbol_table.txt b/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/expected_symbol_table.txt similarity index 100% rename from test_data/intermediate/expected/documentation/docstring_as_raw_string/expected_symbol_table.txt rename to test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/expected_symbol_table.txt diff --git a/test_data/intermediate/expected/documentation/docstring_as_raw_string/meta_model.py b/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py similarity index 100% rename from test_data/intermediate/expected/documentation/docstring_as_raw_string/meta_model.py rename to test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py diff --git a/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt b/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed295e2f343c3fabdf9471d166d5510e98e46f1f GIT binary patch literal 1507 zcmbtU-)q}25YF@diX#l%j5bNPhp|!@!m>QA>qzr3=sF`y=U7yhj3hVl{`#Hl*mbr* zA7(H}cc=UD-Q9Oz7pYMjmMT1Z17Iqf__{YTKmX&&4^o)9NekOv=6r_)Z`SbJlK zFFM%?bAgVd7EJpSO5PVkdEal=FPXVS7Nx=hwP#*ZMXp3HGs)u>Qx3aiq<&^ppZ3FS zdf|zPAss8r;4)smobR%`%5Dhe0D1elswkMP&SlvgaP{^m_L4v@Z?7A~}BQ8rnwlxc57XF%>At|Jisv{@JGzOa@tOa_pkJ z+*C>cL1G{!>7d!*4bT9b!!DOR2kF4myOi;#tu>VvkQsXvA*eH>l-bdYK;IgFR0icW z=?4V{RxU|v!kcoZE}=b4Yg=49x$PMsS}g9x#pQ?j0Ft146#@c*Tq}{JM$|V0Ko*)h zK%<>j9@~Zp<{5;wfpOcXF}R#5)g&xKqp|>p8+6N2^HhCx1PQ>ehtYoiiT(xs%hCS* z{9;rsKdx4z>dSl{F00jQIjZPyeW+`Tgj=SI&sE&dfI{Y}S}exhbN_ F None: symbol_table_str = intermediate.dump(symbol_table) if tests.common.RERECORD: - expected_symbol_table_pth.write_text( - symbol_table_str, encoding="utf-8" - ) + # NOTE (mristin, 2023-11-07): + # We have to write the bytes since Git considers too long text + # files to be binaries. This is problematic when we re-record + # on Windows and Linux due to the different line endings. + # Therefore, we remove here carriage returns (``\r``) so that + # we have the same representation on both operating systems. + + symbol_table_bytes = symbol_table_str.encode( + "utf-8", errors="strict" + ).replace(b"\r", b"") + + expected_symbol_table_pth.write_bytes(symbol_table_bytes) else: try: + # NOTE (mristin, 2023-11-07): + # We assume that Python will automatically represent new lines + # as ``\n`` so that it matches ``symbol_table_bytes`` above. + expected_symbol_table_str = expected_symbol_table_pth.read_text( encoding="utf-8" )