Rev 40: Fix up the tests. Mostly it was just changing things to in http://bzr.arbash-meinel.com/plugins/groupcompress

John Arbash Meinel john at arbash-meinel.com
Wed Mar 4 21:42:17 GMT 2009


At http://bzr.arbash-meinel.com/plugins/groupcompress

------------------------------------------------------------
revno: 40
revision-id: john at arbash-meinel.com-20090304214211-rg22q09z8queeer0
parent: john at arbash-meinel.com-20090304212250-xcvwt1yx4zt76pev
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: groupcompress
timestamp: Wed 2009-03-04 15:42:11 -0600
message:
  Fix up the tests. Mostly it was just changing things to
  no longer include the labels.
  It also means we get a positive compression ratio :).
-------------- next part --------------
=== modified file 'groupcompress.py'
--- a/groupcompress.py	2009-03-04 21:22:50 +0000
+++ b/groupcompress.py	2009-03-04 21:42:11 +0000
@@ -380,7 +380,7 @@
             assert entry.type == 'delta'
             # XXX: This is inefficient at best
             source = ''.join(self.lines)
-            bytes = _groupcompress_pyx.apply_delta(source, delta)
+            bytes = _groupcompress_pyx.apply_delta(source, stored_bytes)
             assert entry.sha1 == sha_string(bytes)
         return bytes, entry.sha1
 

=== modified file 'tests/test_groupcompress.py'
--- a/tests/test_groupcompress.py	2009-03-04 21:06:22 +0000
+++ b/tests/test_groupcompress.py	2009-03-04 21:42:11 +0000
@@ -63,9 +63,6 @@
             'strange\ncommon\n', None)
         self.assertEqual(sha_string('strange\ncommon\n'), sha1)
         expected_lines = [
-            'fulltext\n',
-            'label:label\nsha1:%s\n' % sha1,
-            'len:15\n',
             'strange\ncommon\n',
             ]
         self.assertEqual(expected_lines, compressor.lines)
@@ -97,14 +94,10 @@
                                     'that needs a 16 byte match\n'
                                     'different\n'), sha1_2)
         expected_lines.extend([
-            'delta\n'
-            'label:newlabel\n',
-            'sha1:%s\n' % sha1_2,
-            'len:16\n',
             # source and target length
-            '\x7e\x36',
+            '\x34\x36',
             # copy the line common
-            '\x91\x52\x2c', #copy, offset 0x52, len 0x2c
+            '\x91\x08\x2c', #copy, offset 0x08, len 0x2c
             # add the line different, and the trailing newline
             '\x0adifferent\n', # insert 10 bytes
             ])
@@ -129,29 +122,28 @@
                        'different\nmoredifferent\nand then some more\n'),
             sha1_3)
         expected_lines.extend([
-            'delta\n',
-            'label:label3\n',
-            'sha1:%s\n' % sha1_3,
-            'len:13\n',
-            '\xfa\x01\x5f' # source and target length
+            '\x63\x5f' # source and target length
             # insert new
             '\x03new',
             # Copy of first parent 'common' range
-            '\x91\x51\x31' # copy, offset 0x51, 0x31 bytes
+            '\x91\x07\x31' # copy, offset 0x07, 0x31 bytes
             # Copy of second parent 'different' range
-            '\x91\xcf\x2b' # copy, offset 0xcf, 0x2b bytes
+            '\x91\x38\x2b' # copy, offset 0x38, 0x2b bytes
             ])
         self.assertEqualDiffEncoded(expected_lines, compressor.lines)
         self.assertEqual(sum(map(len, expected_lines)), end_point)
 
     def test_stats(self):
         compressor = groupcompress.GroupCompressor(True)
-        compressor.compress(('label',), 'strange\ncommon\n', None)
+        compressor.compress(('label',), 'strange\ncommon long line\n'
+                                        'plus more text\n', None)
         compressor.compress(('newlabel',),
-                            'common\ndifferent\nmoredifferent\n', None)
+                            'common long line\nplus more text\n'
+                            'different\nmoredifferent\n', None)
         compressor.compress(('label3',),
-                            'new\ncommon\ndifferent\nmoredifferent\n', None)
-        self.assertAlmostEqual(0.3, compressor.ratio(), 1)
+                            'new\ncommon long line\nplus more text\n'
+                            '\ndifferent\nmoredifferent\n', None)
+        self.assertAlmostEqual(1.4, compressor.ratio(), 1)
 
     def test_extract_from_compressor(self):
         # Knit fetching will try to reconstruct texts locally which results in
@@ -163,7 +155,8 @@
         sha1_2, end_point = compressor.compress(('newlabel',),
             'common long line\nthat needs a 16 byte match\ndifferent\n', None)
         # get the first out
-        self.assertEqual(('strange\ncommon\n', sha1_1),
+        self.assertEqual(('strange\ncommon long line\n'
+                          'that needs a 16 byte match\n', sha1_1),
             compressor.extract(('label',)))
         # and the second
         self.assertEqual(('common long line\nthat needs a 16 byte match\n'
@@ -269,7 +262,7 @@
         bytes = gcb.to_bytes()
         self.assertStartsWith(bytes,
                               'gcb1z\n' # group compress block v1 zlib
-                              '76\n' # Length of compressed bytes
+                              '77\n' # Length of compressed bytes
                               '183\n' # Length of all meta-info
                              )
         remaining_bytes = bytes[13:]



More information about the bazaar-commits mailing list