Message333272
This seems to exist on master. Since they are multilines assertMultiLineEqual is used and is there something incorrect during the diff calculation using ndiff due to absence of '\n'? The current diff is calculated as below with difflib.ndiff and seems to produce incorrect output due to absence of newline. The last change was done for single string comparison with issue9174.
difflib.ndiff calculation done internally for the below reproducer
$ ./python.exe
Python 3.8.0a0 (heads/master:a234e14839, Jan 8 2019, 21:57:35)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import difflib
>>> print(''.join(difflib.ndiff(['a\n', 'b'], ['c\n', 'd'])))
- a
- b+ c
+ d
>>> print(''.join(difflib.ndiff(['a\n', 'b\n'], ['c\n', 'd\n']))) # Possible correct candidate?
- a
- b
+ c
+ d
A simpler reproducer
import unittest
class StdErrUnitTests(unittest.TestCase):
def test_function_name(self):
expected = "a\nb"
actual = "c\nd"
self.assertEqual(expected, actual)
def test_function_name_newlines_end(self):
expected = "a\nb\n"
actual = "c\nd\n"
self.assertEqual(expected, actual) # produces extra new line at the diff in the end with \d\n
if __name__ == '__main__':
unittest.main()
$ ./python.exe ../backups/bpo35687_1.py
FF
======================================================================
FAIL: test_function_name (__main__.StdErrUnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "../backups/bpo35687_1.py", line 9, in test_function_name
self.assertEqual(expected, actual)
AssertionError: 'a\nb' != 'c\nd'
- a
- b+ c
+ d
======================================================================
FAIL: test_function_name_newlines_end (__main__.StdErrUnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "../backups/bpo35687_1.py", line 15, in test_function_name_newlines_end
self.assertEqual(expected, actual)
AssertionError: 'a\nb\n' != 'c\nd\n'
- a
- b
+ c
+ d
----------------------------------------------------------------------
Ran 2 tests in 0.003s
FAILED (failures=2) |
|
Date |
User |
Action |
Args |
2019-01-09 01:44:43 | xtreak | set | recipients:
+ xtreak, paul.moore, rbcollins, tim.golden, ned.deily, ezio.melotti, michael.foord, zach.ware, addons_zz |
2019-01-09 01:44:42 | xtreak | set | messageid: <1546998282.75.0.428957892217.issue35687@roundup.psfhosted.org> |
2019-01-09 01:44:42 | xtreak | link | issue35687 messages |
2019-01-09 01:44:42 | xtreak | create | |
|