summaryrefslogtreecommitdiff
path: root/Lib/test/test_difflib.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-04-12 16:35:19 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-04-12 16:35:19 +0000
commit1a14d3d169a34293f416abe4a41e4141c4e07965 (patch)
tree66c9de2d714533b17be4f16c7326da7771242c0d /Lib/test/test_difflib.py
parent9aca91d7d73121a73cdf5d742a8b6cae30989f50 (diff)
downloadcpython-git-1a14d3d169a34293f416abe4a41e4141c4e07965.tar.gz
Issue #7585: use tab between components in unified and context diff headers.
Instead of spaces between the filename and date (or whatever the string is that follows the filename, if any) use tabs. This is what the unix 'diff' command does, for example, and difflib was intended to follow the 'standard' way of doing diffs. This improves compatibility with patch tools. The docs and examples are also changed to recommended that the date format used be the ISO 8601 format, which is what modern diff tools emit by default. Patch by Anatoly Techtonik.
Diffstat (limited to 'Lib/test/test_difflib.py')
-rw-r--r--Lib/test/test_difflib.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
index 93f5c742e9..1b828bb65a 100644
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -159,10 +159,32 @@ class TestSFpatches(unittest.TestCase):
difflib.SequenceMatcher(None, old, new).get_opcodes()
+class TestOutputFormat(unittest.TestCase):
+ def test_tab_delimiter(self):
+ args = ['one', 'two', 'Original', 'Current',
+ '2005-01-26 23:30:50', '2010-04-02 10:20:52']
+ ud = difflib.unified_diff(*args, lineterm='')
+ self.assertEqual(list(ud)[0:2], [
+ "--- Original\t2005-01-26 23:30:50",
+ "+++ Current\t2010-04-02 10:20:52"])
+ cd = difflib.context_diff(*args, lineterm='')
+ self.assertEqual(list(cd)[0:2], [
+ "*** Original\t2005-01-26 23:30:50",
+ "--- Current\t2010-04-02 10:20:52"])
+
+ def test_no_trailing_tab_on_empty_filedate(self):
+ args = ['one', 'two', 'Original', 'Current']
+ ud = difflib.unified_diff(*args, lineterm='')
+ self.assertEqual(list(ud)[0:2], ["--- Original", "+++ Current"])
+
+ cd = difflib.context_diff(*args, lineterm='')
+ self.assertEqual(list(cd)[0:2], ["*** Original", "--- Current"])
+
+
def test_main():
difflib.HtmlDiff._default_prefix = 0
Doctests = doctest.DocTestSuite(difflib)
- run_unittest(TestSFpatches, TestSFbugs, Doctests)
+ run_unittest(TestSFpatches, TestSFbugs, TestOutputFormat, Doctests)
if __name__ == '__main__':
test_main()