Exemple #1
0
 def test_no_context_banner_for_non_sequence(self):
     set1 = {1, 2}
     set2 = {'a', 'b'}
     diff_obj = diff.diff(set1, set2)
     expected_diff_items = [
         '{} {}'.format(diff.remove('-'), diff.remove('1')),
         '{} {}'.format(diff.remove('-'), diff.remove('2')),
         '{} {}'.format(diff.insert('+'), diff.insert('a')),
         '{} {}'.format(diff.insert('+'), diff.insert('b'))
     ]
     # allow the expected output to be unordered
     actual_string = diff_obj.context_blocks[0].__str__()
     actual_items = actual_string.split('\n')
     if sys.version_info.major >= 3:
         self.assertCountEqual(expected_diff_items, actual_items)
     else:
         self.assertItemsEqual(expected_diff_items, actual_items)
Exemple #2
0
 def test_context_banner_is_correct_for_sequences(self):
     '''
     Context banners should contain the information you need the two original
     sequences such that you only get the items contained within the
     displayed context block.
     '''
     seq1 = [0, 1, 2, 3, 0]
     seq2 = [0, 4, 2, 5, 0]
     # the useful context for this diff is the slice 1:4 in both sequences
     s1_start = s2_start = '1'
     s1_end = s2_end = '4'
     diff_obj = diff.diff(seq1, seq2)
     expected_banner = [
         '@@ {}{},{} {}{},{} @@'.format(
             diff.remove('-'), diff.remove(s1_start), diff.remove(s1_end),
             diff.insert('+'), diff.insert(s2_start), diff.insert(s2_end))
     ]
     expected_diff_items = [
         '{} {}'.format(diff.remove('-'), diff.remove('1')),
         '{} {}'.format(diff.insert('+'), diff.insert('4')),
         '{} {}'.format(diff.unchanged(' '), diff.unchanged('2')),
         '{} {}'.format(diff.remove('-'), diff.remove('3')),
         '{} {}'.format(diff.insert('+'), diff.insert('5'))
     ]
     expected_diff_output = '\n'.join(expected_banner + expected_diff_items)
     # expected_diff_output is unicode type, convert to str for comparison
     self.assertEqual(
         diff_obj.context_blocks[0].__str__(), str(expected_diff_output))
Exemple #3
0
 def test_diff_item_str(self):
     item = 'a'
     di = diff.DiffItem(diff.remove, item)
     expected_str = diff.remove('{}'.format(item))
     self.assertEqual(di.__str__(), expected_str)