Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions python/grass/gunittest/testsuite/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,21 @@ def setUpClass(cls):
open(cls.emtpy_file, "w").close()
cls.file_with_md5 = cls.__name__ + "_this_is_a_file_with_known_md5"
file_content = "Content of the file with known MD5.\n"
Path(cls.file_with_md5).write_text(file_content)
# newline="" keeps the \n as-is instead of letting the platform
# default translate it to \r\n, so the MD5 matches file_md5 below
# on every platform (assertFileMd5 hashes the file in binary mode)
Path(cls.file_with_md5).write_text(file_content, newline="")
# MD5 sum created using:
# echo 'Content of the file with known MD5.' > some_file.txt
# md5sum some_file.txt
cls.file_md5 = "807bba4ffac4bb351bc3f27853009949"

cls.file_with_same_content = cls.__name__ + "_file_with_same_content"
Path(cls.file_with_same_content).write_text(file_content)
Path(cls.file_with_same_content).write_text(file_content, newline="")

cls.file_with_different_content = cls.__name__ + "_file_with_different_content"
Path(cls.file_with_different_content).write_text(
file_content + " Something else here."
file_content + " Something else here.", newline=""
)

@classmethod
Expand All @@ -386,7 +389,6 @@ def test_assertFileExists_empty_file(self):
self.failureException, self.assertFileExists, filename=self.emtpy_file
)

@xfail_windows
def test_assertFileMd5(self):
self.assertFileMd5(filename=self.file_with_md5, md5=self.file_md5)
self.assertRaises(
Expand Down
8 changes: 4 additions & 4 deletions python/grass/gunittest/testsuite/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
file_md5,
text_file_md5,
)
from grass.gunittest.utils import xfail_windows


class TestValuesEqual(TestCase):
Expand Down Expand Up @@ -369,8 +368,10 @@ def setUpClass(cls):
with open(cls.correct_file_name_platform_nl, "w") as f:
# \n should be converted to platform newline
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.correct_file_name_unix_nl, "w") as f:
# binary mode will write pure \n
with open(cls.correct_file_name_unix_nl, "w", newline="") as f:
# newline="" keeps the \n as-is instead of letting the platform
# default translate it to \r\n, so file_md5() (binary mode)
# below matches correct_md5sum on every platform
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.wrong_file_name, "w") as f:
# \n should be converted to platform newline
Expand All @@ -382,7 +383,6 @@ def tearDownClass(cls):
try_remove(cls.correct_file_name_unix_nl)
try_remove(cls.wrong_file_name)

@xfail_windows
def test_text_file_binary(self):
r"""File with ``\n`` (LF) newlines as binary (MD5 has ``\n``)."""
self.assertEqual(
Expand Down