Skip to content

Commit

Permalink
Record intermediate test data without CR (#419)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mristin authored Nov 7, 2023
1 parent 39980e5 commit fe69c9f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# We test for ``\x09`` and other special characters, and make sure they are represented
# adequately in the string dump of the symbol table.


class Non_empty_XML_serializable_string(str, DBC):
r"""
Represent a string with at least one character.
The string should also be serializable to XML, which is the background for
the following constraint.
:constraint AASd-130:
An attribute with data type "string" shall consist of these characters only:
^[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u00010000-\u0010FFFF]*$.
"""


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"
19 changes: 16 additions & 3 deletions tests/intermediate/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,24 @@ def test_cases(self) -> 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"
)
Expand Down

0 comments on commit fe69c9f

Please sign in to comment.