Skip to content

Commit 0dcec5a

Browse files
committed
It seems zlib works differently in py26, and thus requires special handling.
This also explains why the tests suddenly stopped working - after all, the interpreter changed ... .
1 parent e7fdd94 commit 0dcec5a

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

Diff for: gitdb/stream.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import mmap
99
import os
10+
import sys
1011
import zlib
1112

1213
from gitdb.fun import (
@@ -30,6 +31,7 @@
3031
from gitdb.utils.encoding import force_bytes
3132

3233
has_perf_mod = False
34+
PY26 = sys.version_info[:2] < (2, 7)
3335
try:
3436
from _perf import apply_delta as c_apply_delta
3537
has_perf_mod = True
@@ -275,10 +277,14 @@ def read(self, size=-1):
275277
# We feed possibly overlapping chunks, which is why the unconsumed tail
276278
# has to be taken into consideration, as well as the unused data
277279
# if we hit the end of the stream
278-
# NOTE: For some reason, the code worked for a long time with substracting unconsumed_tail
279-
# Now, however, it really asks for unused_data, and I wonder whether unconsumed_tail still has to
280-
# be substracted. On the plus side, the tests work, so it seems to be ok for py 2.7 and 3.4
281-
self._cbr += len(indata) - len(self._zip.unconsumed_tail) - len(self._zip.unused_data)
280+
# NOTE: Behavior changed in PY2.7 onward, which requires special handling to make the tests work properly.
281+
# They are thorough, and I assume it is truly working.
282+
if PY26:
283+
unused_datalen = len(self._zip.unconsumed_tail)
284+
else:
285+
unused_datalen = len(self._zip.unconsumed_tail) + len(self._zip.unused_data)
286+
# end handle very special case ...
287+
self._cbr += len(indata) - unused_datalen
282288
self._br += len(dcompdat)
283289

284290
if dat:
@@ -505,7 +511,6 @@ def new(cls, stream_list):
505511
if stream_list[-1].type_id in delta_types:
506512
raise ValueError("Cannot resolve deltas if there is no base object stream, last one was type: %s" % stream_list[-1].type)
507513
# END check stream
508-
509514
return cls(stream_list)
510515

511516
#} END interface

Diff for: gitdb/test/test_stream.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import tempfile
2929
import os
30-
import sys
31-
from nose import SkipTest
3230

3331
class TestStream(TestBase):
3432
"""Test stream classes"""
@@ -71,16 +69,10 @@ def _assert_stream_reader(self, stream, cdata, rewind_stream=lambda s: None):
7169
# END handle special type
7270

7371
def test_decompress_reader(self):
74-
cache = dict()
7572
for close_on_deletion in range(2):
7673
for with_size in range(2):
7774
for ds in self.data_sizes:
78-
if ds in cache:
79-
cdata = cache[ds]
80-
else:
81-
cdata = make_bytes(ds, randomize=False)
82-
cache[ds] = cdata
83-
# end handle caching (maybe helps on py2.6 ?)
75+
cdata = make_bytes(ds, randomize=False)
8476

8577
# zdata = zipped actual data
8678
# cdata = original content data
@@ -128,9 +120,6 @@ def test_sha_writer(self):
128120
assert writer.sha() != prev_sha
129121

130122
def test_compressed_writer(self):
131-
if sys.version_info[:2] < (2,7) and os.environ.get('TRAVIS'):
132-
raise SkipTest("For some reason, this test STALLS on travis ci on py2.6, but works on my centos py2.6 interpreter")
133-
# end special case ...
134123
for ds in self.data_sizes:
135124
fd, path = tempfile.mkstemp()
136125
ostream = FDCompressedSha1Writer(fd)

0 commit comments

Comments
 (0)