class TestOutputFormat(unittest.TestCase):
def test_tab_delimiter(self):
- args = ['one', 'two', 'Original', 'Current',
+ 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], [
"--- Current\t2010-04-02 10:20:52"])
def test_no_trailing_tab_on_empty_filedate(self):
- args = ['one', 'two', 'Original', 'Current']
+ args = [['one'], ['two'], 'Original', 'Current']
ud = difflib.unified_diff(*args, lineterm='')
self.assertEqual(list(ud)[0:2], ["--- Original", "+++ Current"])
lineterm=b'')
assertDiff(expect, actual)
+
+class TestInputTypes(unittest.TestCase):
+ def _assert_type_error(self, msg, generator, *args):
+ with self.assertRaises(TypeError) as ctx:
+ list(generator(*args))
+ self.assertEqual(msg, str(ctx.exception))
+
+ def test_input_type_checks(self):
+ unified = difflib.unified_diff
+ context = difflib.context_diff
+
+ expect = "input must be a sequence of strings, not str"
+ self._assert_type_error(expect, unified, 'a', ['b'])
+ self._assert_type_error(expect, context, 'a', ['b'])
+
+ self._assert_type_error(expect, unified, ['a'], 'b')
+ self._assert_type_error(expect, context, ['a'], 'b')
+
+ expect = "lines to compare must be str, not NoneType (None)"
+ self._assert_type_error(expect, unified, ['a'], [None])
+ self._assert_type_error(expect, context, ['a'], [None])
+
def test_mixed_types_content(self):
# type of input content must be consistent: all str or all bytes
a = [b'hello']
b = ['bar\n']
list(difflib.unified_diff(a, b, 'a', 'b', datea, dateb))
- def _assert_type_error(self, msg, generator, *args):
- with self.assertRaises(TypeError) as ctx:
- list(generator(*args))
- self.assertEqual(msg, str(ctx.exception))
class TestJunkAPIs(unittest.TestCase):
def test_is_line_junk_true(self):