Skip to content

grass.gunittest: Preserve exact bytes in MD5 test fixtures - #730

Closed
echoix wants to merge 4 commits into
mainfrom
gunittest-md5-newline-fixtures
Closed

echoix wants to merge 4 commits into
mainfrom
gunittest-md5-newline-fixtures

Conversation

@echoix

@echoix echoix commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Description

Write the MD5 test fixtures in test_checkers.py and test_assertions.py with newline="", so \n is not translated to \r\n on Windows. These files are hashed in binary mode and compared against MD5 sums computed from \n content. The two other fixtures written next to file_with_md5 get the same treatment, since test_assertFilesEqualMd5 compares their hashes against it.

The @xfail_windows markers on test_text_file_binary and test_assertFileMd5 are removed: an unexpected success makes TestResult.wasSuccessful() return False, which would fail the gunittest run.

Also fixes the platfrom typos in the test_text_file_platform test name and the platform_newline attribute.

Motivation and context

Extracted from the stale OSGeo#2616 (newline handling by @ninsbl), reworked against current main, with AI assistance (Claude Code).

How has this been tested?

Both hardcoded MD5 sums were checked against hashlib.md5() of the \n-only content, and ruff check passes. On a Windows CI run, TestMd5Sums in test_checkers.py passes, and test_assertions.py runs 31 tests with only the pre-existing @xfail_windows expected failure (test_assertLooksLike_multiline_platform_dependent).

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes. (Fixes existing tests only.)

Python's default text-mode writing translates "\n" to os.linesep, which
on Windows turns the MD5 test fixtures into "\r\n" files. Two tests hash
them in binary mode against MD5 sums computed from "\n" content:
test_text_file_binary in test_checkers.py and test_assertFileMd5 in
test_assertions.py.

Write these fixtures with newline="" so the bytes match the hardcoded
sums on every platform. Do the same for the other fixtures written next
to file_with_md5, since test_assertFilesEqualMd5 compares their hashes
against it. Remove the now obsolete @xfail_windows markers from the two
tests, because an unexpected success makes the gunittest run fail.

Based on the newline handling in OSGeo#2616 by Stefan Blumentrath,
reworked against current main with AI assistance.
@echoix echoix closed this Oct 10, 2026
@echoix
echoix deleted the gunittest-md5-newline-fixtures branch October 10, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants