Exemple #1
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 #2
0
 def test_mapping_diff_item_str(self):
     key = 'a'
     val = [1, 2, 3]
     di = diff.MappingDiffItem(
         diff.unchanged, key, diff.insert, val)
     expected_str = (
         diff.unchanged('{!s}: '.format(key)) +
         diff.insert('{!s}'.format(val)))
     self.assertEqual(di.__str__(), expected_str)