aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_unittest/test_case.py
diff options
context:
space:
mode:
authorMichael Blahay <mblahay@users.noreply.github.com>2023-05-04 18:37:17 -0400
committerGitHub <noreply@github.com>2023-05-04 16:37:17 -0600
commit46361bb84332800bc3632688e6ef3b4dd4a48723 (patch)
tree040035775dd304158eb242d04b38bd9324628afe /Lib/test/test_unittest/test_case.py
parent7d35c3121ade679dd6e8b4a0bac7b3702aee6921 (diff)
downloadcpython-46361bb84332800bc3632688e6ef3b4dd4a48723.tar.gz
cpython-46361bb84332800bc3632688e6ef3b4dd4a48723.zip
gh-68968: Correcting message display issue with assertEqual (#103937)
Diffstat (limited to 'Lib/test/test_unittest/test_case.py')
-rw-r--r--Lib/test/test_unittest/test_case.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py
index dd5ff6d553e..ed5eb5609a5 100644
--- a/Lib/test/test_unittest/test_case.py
+++ b/Lib/test/test_unittest/test_case.py
@@ -1149,6 +1149,66 @@ test case
error = str(e).split('\n', 1)[1]
self.assertEqual(sample_text_error, error)
+ def testAssertEqualwithEmptyString(self):
+ '''Verify when there is an empty string involved, the diff output
+ does not treat the empty string as a single empty line. It should
+ instead be handled as a non-line.
+ '''
+ sample_text = ''
+ revised_sample_text = 'unladen swallows fly quickly'
+ sample_text_error = '''\
++ unladen swallows fly quickly
+'''
+ try:
+ self.assertEqual(sample_text, revised_sample_text)
+ except self.failureException as e:
+ # need to remove the first line of the error message
+ error = str(e).split('\n', 1)[1]
+ self.assertEqual(sample_text_error, error)
+
+ def testAssertEqualMultipleLinesMissingNewlineTerminator(self):
+ '''Verifying format of diff output from assertEqual involving strings
+ with multiple lines, but missing the terminating newline on both.
+ '''
+ sample_text = 'laden swallows\nfly sloely'
+ revised_sample_text = 'laden swallows\nfly slowly'
+ sample_text_error = '''\
+ laden swallows
+- fly sloely
+? ^
++ fly slowly
+? ^
+'''
+ try:
+ self.assertEqual(sample_text, revised_sample_text)
+ except self.failureException as e:
+ # need to remove the first line of the error message
+ error = str(e).split('\n', 1)[1]
+ self.assertEqual(sample_text_error, error)
+
+ def testAssertEqualMultipleLinesMismatchedNewlinesTerminators(self):
+ '''Verifying format of diff output from assertEqual involving strings
+ with multiple lines and mismatched newlines. The output should
+ include a - on it's own line to indicate the newline difference
+ between the two strings
+ '''
+ sample_text = 'laden swallows\nfly sloely\n'
+ revised_sample_text = 'laden swallows\nfly slowly'
+ sample_text_error = '''\
+ laden swallows
+- fly sloely
+? ^
++ fly slowly
+? ^
+-\x20
+'''
+ try:
+ self.assertEqual(sample_text, revised_sample_text)
+ except self.failureException as e:
+ # need to remove the first line of the error message
+ error = str(e).split('\n', 1)[1]
+ self.assertEqual(sample_text_error, error)
+
def testEqualityBytesWarning(self):
if sys.flags.bytes_warning:
def bytes_warning():