Skip to content
Merged
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
21 changes: 13 additions & 8 deletions python/grass/gunittest/testsuite/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestTextAssertions(TestCase):
# pylint: disable=R0904

std_newline = "aaa\nbbb\n"
platfrom_newline = "aaa{nl}bbb{nl}".format(nl=os.linesep)
platform_newline = "aaa{nl}bbb{nl}".format(nl=os.linesep)

def test_assertLooksLike(self):
self.assertLooksLike("Generated map is <elevation>", "Generated map is <...>")
Expand Down Expand Up @@ -63,7 +63,7 @@ def do_all_combidnations(self, first, second, function):
def test_assertMultiLineEqual(self):
r"""Test different combinations of ``\n`` and os.linesep"""
self.do_all_combidnations(
self.std_newline, self.platfrom_newline, function=self.assertMultiLineEqual
self.std_newline, self.platform_newline, function=self.assertMultiLineEqual
)

def test_assertMultiLineEqual_raises(self):
Expand All @@ -78,7 +78,7 @@ def test_assertMultiLineEqual_raises(self):
def test_assertEqual(self):
"""Test for of newlines for strings (uses overwritten assertMultiLineEqual())"""
self.do_all_combidnations(
self.std_newline, self.platfrom_newline, function=self.assertEqual
self.std_newline, self.platform_newline, function=self.assertEqual
)

def test_assertEqual_raises(self):
Expand Down Expand Up @@ -351,18 +351,24 @@ 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)

def write_exact(filename, content):
# newline="" keeps \n as-is instead of translating it to \r\n on
# Windows, so the binary MD5 matches the value below.
Path(filename).write_text(content, newline="")

write_exact(cls.file_with_md5, file_content)
# 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)
write_exact(cls.file_with_same_content, file_content)

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

@classmethod
Expand All @@ -386,7 +392,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: 3 additions & 5 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,8 @@ 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="" writes pure \n 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 +381,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 All @@ -391,7 +389,7 @@ def test_text_file_binary(self):
msg="MD5 sums different",
)

def test_text_file_platfrom(self):
def test_text_file_platform(self):
r"""Text file with platform dependent newlines"""
self.assertEqual(
text_file_md5(self.correct_file_name_platform_nl),
Expand Down
Loading