-
Notifications
You must be signed in to change notification settings - Fork 72
[IMPROVEMENT] Normalize line endings and trailing whitespace in regression comparisons #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
gaurav02081
wants to merge
4
commits into
CCExtractor:master
from
gaurav02081:fix/regression-normalization
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
373b62c
Normalize line endings and trailing whitespace in regression comparisons
gaurav-dev02 dce6845
Merge branch 'master' into fix/regression-normalization
gaurav02081 cd70dbf
Merge branch 'master' into fix/regression-normalization
gaurav02081 5bfdcd8
Merge branch 'master' into fix/regression-normalization
gaurav02081 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import unittest | ||
| import os | ||
| import tempfile | ||
| from mod_test.models import TestResultFile | ||
|
|
||
| class TestNormalization(unittest.TestCase): | ||
| def setUp(self): | ||
| self.test_dir = tempfile.TemporaryDirectory() | ||
|
|
||
| def tearDown(self): | ||
| self.test_dir.cleanup() | ||
|
|
||
| def test_text_normalization(self): | ||
| # File A: LF, no trailing spaces | ||
| file_a_path = os.path.join(self.test_dir.name, "file_a.txt") | ||
| with open(file_a_path, 'wb') as f: | ||
| f.write(b"line1\nline2\n") | ||
|
|
||
| # File B: CRLF, trailing spaces | ||
| file_b_path = os.path.join(self.test_dir.name, "file_b.txt") | ||
| with open(file_b_path, 'wb') as f: | ||
| f.write(b"line1 \r\nline2\r\n") | ||
|
|
||
| lines_a = TestResultFile.read_lines(file_a_path) | ||
| lines_b = TestResultFile.read_lines(file_b_path) | ||
|
|
||
| self.assertEqual(lines_a, ["line1\n", "line2\n"]) | ||
| self.assertEqual(lines_b, ["line1\n", "line2\n"]) | ||
| self.assertEqual(lines_a, lines_b) | ||
|
|
||
| def test_binary_exemption(self): | ||
| # Binary file: should NOT be modified | ||
| file_bin_path = os.path.join(self.test_dir.name, "test.bin") | ||
| content = b"line1 \r\nline2\r\n" | ||
| with open(file_bin_path, 'wb') as f: | ||
| f.write(content) | ||
|
|
||
| lines = TestResultFile.read_lines(file_bin_path) | ||
| # readlines() on binary file with default open (universal newlines) may still change \r\n to \n | ||
| # but our normalize() should skip the rstrip part. | ||
| # Actually, Python's readlines() in text mode WITHOUT newline=None (default) transforms \r\n to \n. | ||
| # However, the requirement was to ensure binary files are not Corrupted or changed by our logic. | ||
|
|
||
| # If we open in text mode, Python handles newlines. | ||
| # Let's check if our normalization code skips the rstrip. | ||
| self.assertEqual(lines, ["line1 \n", "line2\n"]) # line1 trailing spaces preserved | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.