diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2014-11-14 12:39:09 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2014-11-14 12:40:22 +0100 |
commit | 0dcec5a27b341ce58e5ab169f91aa25b2cafec0c (patch) | |
tree | 176a493d114fab7cc6e930bf318b2339db386cf5 | |
parent | e7fdd949d0cb2c42c9217e3c7009eb28c6b53446 (diff) | |
download | gitdb-py2n3.tar.gz |
It seems zlib works differently in py26, and thus requires special handling.py2n3
This also explains why the tests suddenly stopped working - after all, the interpreter changed ... .
-rw-r--r-- | gitdb/stream.py | 15 | ||||
-rw-r--r-- | gitdb/test/test_stream.py | 13 |
2 files changed, 11 insertions, 17 deletions
diff --git a/gitdb/stream.py b/gitdb/stream.py index 0332df6..edd6dd2 100644 --- a/gitdb/stream.py +++ b/gitdb/stream.py @@ -7,6 +7,7 @@ from io import BytesIO import mmap import os +import sys import zlib from gitdb.fun import ( @@ -30,6 +31,7 @@ from gitdb.utils.compat import buffer from gitdb.utils.encoding import force_bytes has_perf_mod = False +PY26 = sys.version_info[:2] < (2, 7) try: from _perf import apply_delta as c_apply_delta has_perf_mod = True @@ -275,10 +277,14 @@ class DecompressMemMapReader(LazyMixin): # We feed possibly overlapping chunks, which is why the unconsumed tail # has to be taken into consideration, as well as the unused data # if we hit the end of the stream - # NOTE: For some reason, the code worked for a long time with substracting unconsumed_tail - # Now, however, it really asks for unused_data, and I wonder whether unconsumed_tail still has to - # be substracted. On the plus side, the tests work, so it seems to be ok for py 2.7 and 3.4 - self._cbr += len(indata) - len(self._zip.unconsumed_tail) - len(self._zip.unused_data) + # NOTE: Behavior changed in PY2.7 onward, which requires special handling to make the tests work properly. + # They are thorough, and I assume it is truly working. + if PY26: + unused_datalen = len(self._zip.unconsumed_tail) + else: + unused_datalen = len(self._zip.unconsumed_tail) + len(self._zip.unused_data) + # end handle very special case ... + self._cbr += len(indata) - unused_datalen self._br += len(dcompdat) if dat: @@ -505,7 +511,6 @@ class DeltaApplyReader(LazyMixin): if stream_list[-1].type_id in delta_types: raise ValueError("Cannot resolve deltas if there is no base object stream, last one was type: %s" % stream_list[-1].type) # END check stream - return cls(stream_list) #} END interface diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py index f8d9f5d..50db44b 100644 --- a/gitdb/test/test_stream.py +++ b/gitdb/test/test_stream.py @@ -27,8 +27,6 @@ from gitdb.typ import ( import tempfile import os -import sys -from nose import SkipTest class TestStream(TestBase): """Test stream classes""" @@ -71,16 +69,10 @@ class TestStream(TestBase): # END handle special type def test_decompress_reader(self): - cache = dict() for close_on_deletion in range(2): for with_size in range(2): for ds in self.data_sizes: - if ds in cache: - cdata = cache[ds] - else: - cdata = make_bytes(ds, randomize=False) - cache[ds] = cdata - # end handle caching (maybe helps on py2.6 ?) + cdata = make_bytes(ds, randomize=False) # zdata = zipped actual data # cdata = original content data @@ -128,9 +120,6 @@ class TestStream(TestBase): assert writer.sha() != prev_sha def test_compressed_writer(self): - if sys.version_info[:2] < (2,7) and os.environ.get('TRAVIS'): - raise SkipTest("For some reason, this test STALLS on travis ci on py2.6, but works on my centos py2.6 interpreter") - # end special case ... for ds in self.data_sizes: fd, path = tempfile.mkstemp() ostream = FDCompressedSha1Writer(fd) |