Rev 2486: Add tests for the decompress api. And update the compress tests in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/gzip_reader

John Arbash Meinel john at arbash-meinel.com
Wed May 9 04:43:29 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/gzip_reader

------------------------------------------------------------
revno: 2486
revision-id: john at arbash-meinel.com-20070509034259-oh6x2egsagzsl4ww
parent: john at arbash-meinel.com-20070509013152-eosdtgwm54158m0c
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: gzip_reader
timestamp: Tue 2007-05-08 22:42:59 -0500
message:
  Add tests for the decompress api. And update the compress tests
modified:
  bzrlib/tests/test_tuned_gzip.py test_tuned_gzip.py-20060418042056-c576dfc708984968
  bzrlib/tuned_gzip.py           tuned_gzip.py-20060407014720-5aadc518e928e8d2
-------------- next part --------------
=== modified file 'bzrlib/tests/test_tuned_gzip.py'
--- a/bzrlib/tests/test_tuned_gzip.py	2007-05-09 01:31:52 +0000
+++ b/bzrlib/tests/test_tuned_gzip.py	2007-05-09 03:42:59 +0000
@@ -113,6 +113,23 @@
     def test_compress_empty_string(self):
         self.assertCompressed('')
 
+    def test_compress_simple_strings(self):
+        self.assertCompressed('a')
+        self.assertCompressed('b')
+        self.assertCompressed('ab')
+        self.assertCompressed('abc')
+        self.assertCompressed('abcd')
+        self.assertCompressed('aaaa')
+
+    def test_compress_non_text(self):
+        self.assertCompressed('\x01')
+        self.assertCompressed('\x02')
+        self.assertCompressed('\xff')
+        self.assertCompressed('\xee\xef\xff')
+        self.assertCompressed('\xff\xff\xff\xff')
+
+    def test_compress_long_strings(self):
+        self.assertCompressed('abcdefghijklmnopqrstuvwxyz'*1000)
 
 
 class TestDecompressGzipHunk(tests.TestCase):
@@ -123,6 +140,37 @@
         plain_text = tuned_gzip.decompress_gzip_hunk(gzip_hunk)
         self.assertEqual(expected, plain_text)
 
+    def assertCompressDecompress(self, plain_text):
+        """Check that tuned_gzip.decompress_gzip_hunk() handles new gzip hunks.
+
+        :param plain_text: The plain text to directly compress, and then
+            compare against the return value of decompress_gzip_hunk.
+        """
+        tmp = StringIO()
+        gz = tuned_gzip.GzipFile(mode='wb', fileobj=tmp)
+        gz.write(plain_text)
+        gz.close()
+        measured = tuned_gzip.decompress_gzip_hunk(tmp.getvalue())
+        self.assertEqual(plain_text, measured)
+
     def test_decompress_empty_string(self):
         self.assertDecompress('', '\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff'
                                   '\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+
+    def test_decompress_simple_strings(self):
+        self.assertCompressDecompress('a')
+        self.assertCompressDecompress('b')
+        self.assertCompressDecompress('ab')
+        self.assertCompressDecompress('abc')
+        self.assertCompressDecompress('abcd')
+        self.assertCompressDecompress('aaaa')
+
+    def test_decompress_non_text(self):
+        self.assertCompressDecompress('\x01')
+        self.assertCompressDecompress('\x02')
+        self.assertCompressDecompress('\xff')
+        self.assertCompressDecompress('\xee\xef\xff')
+        self.assertCompressDecompress('\xff\xff\xff\xff')
+
+    def test_decompress_long_strings(self):
+        self.assertCompressDecompress('abcdefghijklmnopqrstuvwxyz'*1000)

=== modified file 'bzrlib/tuned_gzip.py'
--- a/bzrlib/tuned_gzip.py	2007-05-09 01:31:52 +0000
+++ b/bzrlib/tuned_gzip.py	2007-05-09 03:42:59 +0000
@@ -348,6 +348,7 @@
     """
     tmp = StringIO()
     gz = GzipFile(mode='wb', fileobj=tmp)
+    gz.write(text)
     gz.flush()
     gz.close()
     return tmp.getvalue()



More information about the bazaar-commits mailing list