summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_difflib.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-03-14 23:18:47 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-03-14 23:18:47 (GMT)
commit102029dfd645123244437dee6fc8c0f72125433b (patch)
tree5afa2e1185862e22b95ea6aa8f5d0b614852a287 /Lib/test/test_difflib.py
parentfbd011dd4982b883d18039f494475022fc2d0cc6 (diff)
downloadcpython-102029dfd645123244437dee6fc8c0f72125433b.zip
cpython-102029dfd645123244437dee6fc8c0f72125433b.tar.gz
cpython-102029dfd645123244437dee6fc8c0f72125433b.tar.bz2
Issue #2052: Add charset parameter to HtmlDiff.make_file().
Diffstat (limited to 'Lib/test/test_difflib.py')
-rw-r--r--Lib/test/test_difflib.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
index 0ba8f0e..a078e71 100644
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -107,6 +107,20 @@ patch914575_to1 = """
5. Flat is better than nested.
"""
+patch914575_nonascii_from1 = """
+ 1. Beautiful is beTTer than ugly.
+ 2. Explicit is better than ımplıcıt.
+ 3. Simple is better than complex.
+ 4. Complex is better than complicated.
+"""
+
+patch914575_nonascii_to1 = """
+ 1. Beautiful is better than ügly.
+ 3. Sımple is better than complex.
+ 4. Complicated is better than cömplex.
+ 5. Flat is better than nested.
+"""
+
patch914575_from2 = """
\t\tLine 1: preceeded by from:[tt] to:[ssss]
\t\tLine 2: preceeded by from:[sstt] to:[sssst]
@@ -223,6 +237,27 @@ class TestSFpatches(unittest.TestCase):
new = [(i%2 and "K:%d" or "V:B:%d") % i for i in range(limit*2)]
difflib.SequenceMatcher(None, old, new).get_opcodes()
+ def test_make_file_default_charset(self):
+ html_diff = difflib.HtmlDiff()
+ output = html_diff.make_file(patch914575_from1.splitlines(),
+ patch914575_to1.splitlines())
+ self.assertIn('content="text/html; charset=utf-8"', output)
+
+ def test_make_file_iso88591_charset(self):
+ html_diff = difflib.HtmlDiff()
+ output = html_diff.make_file(patch914575_from1.splitlines(),
+ patch914575_to1.splitlines(),
+ charset='iso-8859-1')
+ self.assertIn('content="text/html; charset=iso-8859-1"', output)
+
+ def test_make_file_usascii_charset_with_nonascii_input(self):
+ html_diff = difflib.HtmlDiff()
+ output = html_diff.make_file(patch914575_nonascii_from1.splitlines(),
+ patch914575_nonascii_to1.splitlines(),
+ charset='us-ascii')
+ self.assertIn('content="text/html; charset=us-ascii"', output)
+ self.assertIn('&#305;mpl&#305;c&#305;t', output)
+
class TestOutputFormat(unittest.TestCase):
def test_tab_delimiter(self):