Example #1
0
 def test_pydiff_example(self):
     ondisk = [
         'The Way that can be told of is not the eternal Way;\r\n',
         'The name that can be named is not the eternal name.\r\n',
         'The Nameless is the origin of Heaven and Earth;\r\n',
         'The Named is the mother of all things.\r\n',
         '  so we may see their subtlety,\r\n',
         '  so we may see their outcome.\r\n',
         'And let there always be being,\r\n',
         'The two are the same,\r\n',
         'But cheese after they are produced,\r\n',
         '  they have different names.\r\n',
     ]
     inmemory = [
         'The Nameless is the origin of Heaven and Earth;\r\n',
         'The named is the mother of all things.\r\n',
         '\r\n',
         'Therefore let there always be non-being,\r\n',
         '  so we may see their subtlety,\r\n',
         'And let there always be being,\r\n',
         '  so we may see their outcome.\r\n',
         'The two are the same,\r\n',
         'But after they are produced,\r\n',
         '  they have different names.\r\n',
         'They both may be called deep and profound.\r\n',
         'Deeper and more profound,\r\n',
         'The door of all subtleties!\r\n',
     ]
     trec = ('replace', 0, len(ondisk), 0, len(inmemory))
     t1 = time.time()
     fixedTuples = difflibex.split_opcodes(trec, ondisk, inmemory)
     t2 = time.time()
     et1 = t2 - t1
     self.assertListEqual(fixedTuples,
                          [('delete', 0, 1, 0, 0),
                           ('delete', 1, 2, 0, 0), ('equal', 2, 3, 0, 1), ('replace', 3, 4, 1, 2),
                           ('insert', 4, 4, 2, 4), ('equal', 4, 5, 4, 5), ('insert', 5, 5, 5, 6),
                           ('equal', 5, 6, 6, 7), ('delete', 6, 7, 7, 7), ('equal', 7, 8, 7, 8),
                           ('replace', 8, 9, 8, 9), ('equal', 9, 10, 9, 10), ('insert', 10, 10, 10, 13)])
     # Now verify that the caching is working with a second lookup of the same values
     t1 = time.time()
     fixedTuples2 = difflibex.split_opcodes(trec, ondisk, inmemory)
     t2 = time.time()
     # et2 should be time to look up a hash entry
     # et1 show time spent calculating the diff, should be at least 10 times slower
     # than doing a hash lookup and returning a reference.
     et2 = t2 - t1 
     self.assertEqual(fixedTuples, fixedTuples2)
     self.assertGreater(et1 / 10.0, et2, "first time wasn't fast enough: et1:%g, et2:%g" % (et1, et2))
Example #2
0
 def _do_tests(self, ondisk, inmemory):
     trec = ('replace', 0, len(ondisk), 0, len(inmemory))
     return difflibex.split_opcodes(trec, ondisk, inmemory)
Example #3
0
 def test_pydiff_example(self):
     ondisk = [
         "The Way that can be told of is not the eternal Way;\r\n",
         "The name that can be named is not the eternal name.\r\n",
         "The Nameless is the origin of Heaven and Earth;\r\n",
         "The Named is the mother of all things.\r\n",
         "  so we may see their subtlety,\r\n",
         "  so we may see their outcome.\r\n",
         "And let there always be being,\r\n",
         "The two are the same,\r\n",
         "But cheese after they are produced,\r\n",
         "  they have different names.\r\n",
     ]
     inmemory = [
         "The Nameless is the origin of Heaven and Earth;\r\n",
         "The named is the mother of all things.\r\n",
         "\r\n",
         "Therefore let there always be non-being,\r\n",
         "  so we may see their subtlety,\r\n",
         "And let there always be being,\r\n",
         "  so we may see their outcome.\r\n",
         "The two are the same,\r\n",
         "But after they are produced,\r\n",
         "  they have different names.\r\n",
         "They both may be called deep and profound.\r\n",
         "Deeper and more profound,\r\n",
         "The door of all subtleties!\r\n",
     ]
     trec = ("replace", 0, len(ondisk), 0, len(inmemory))
     t1 = time.time()
     fixedTuples = difflibex.split_opcodes(trec, ondisk, inmemory)
     t2 = time.time()
     et1 = t2 - t1
     self.assertListEqual(
         fixedTuples,
         [
             ("delete", 0, 1, 0, 0),
             ("delete", 1, 2, 0, 0),
             ("equal", 2, 3, 0, 1),
             ("replace", 3, 4, 1, 2),
             ("insert", 4, 4, 2, 4),
             ("equal", 4, 5, 4, 5),
             ("insert", 5, 5, 5, 6),
             ("equal", 5, 6, 6, 7),
             ("delete", 6, 7, 7, 7),
             ("equal", 7, 8, 7, 8),
             ("replace", 8, 9, 8, 9),
             ("equal", 9, 10, 9, 10),
             ("insert", 10, 10, 10, 13),
         ],
     )
     # Now verify that the caching is working with a second lookup of the same values
     t1 = time.time()
     fixedTuples2 = difflibex.split_opcodes(trec, ondisk, inmemory)
     t2 = time.time()
     # et2 should be time to look up a hash entry
     # et1 show time spent calculating the diff, should be at least 10 times slower
     # than doing a hash lookup and returning a reference.
     et2 = t2 - t1
     self.assertEqual(fixedTuples, fixedTuples2)
     self.assertGreater(et1 / 10.0, et2, "first time wasn't fast enough: et1:%g, et2:%g" % (et1, et2))
Example #4
0
 def _do_tests(self, ondisk, inmemory):
     trec = ("replace", 0, len(ondisk), 0, len(inmemory))
     return difflibex.split_opcodes(trec, ondisk, inmemory)