diff --git a/python/grass/gunittest/testsuite/test_assertions.py b/python/grass/gunittest/testsuite/test_assertions.py index 64bc790b3dd..631e0e9d2f8 100644 --- a/python/grass/gunittest/testsuite/test_assertions.py +++ b/python/grass/gunittest/testsuite/test_assertions.py @@ -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 @@ -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( diff --git a/python/grass/gunittest/testsuite/test_checkers.py b/python/grass/gunittest/testsuite/test_checkers.py index c1a692fbc6d..14356fe4f24 100644 --- a/python/grass/gunittest/testsuite/test_checkers.py +++ b/python/grass/gunittest/testsuite/test_checkers.py @@ -22,7 +22,6 @@ file_md5, text_file_md5, ) -from grass.gunittest.utils import xfail_windows class TestValuesEqual(TestCase): @@ -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 @@ -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(