From 758c29306f509008d80ee84443e04cf6655215ea Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sun, 2 Oct 2016 02:03:13 +0200 Subject: feat(io): breaking API: retrofit Packers as context-managers! + Packers MUST be invoked inside `Withh...` blocks, or `_cursor` won't exist! + Had to drop NotLazy for their hierarchy :-( + Count entrances/exits. + feat(util: add `rmtree()` for READ_ONLY files on Windows. 3-->2 Windows TCs now fail. --- gitdb/test/performance/test_pack.py | 43 +++++++++++++++++++---------------- gitdb/test/performance/test_stream.py | 18 +++++++-------- 2 files changed, 32 insertions(+), 29 deletions(-) (limited to 'gitdb/test/performance') diff --git a/gitdb/test/performance/test_pack.py b/gitdb/test/performance/test_pack.py index fc8d9d5..b99b91e 100644 --- a/gitdb/test/performance/test_pack.py +++ b/gitdb/test/performance/test_pack.py @@ -92,19 +92,20 @@ class TestPackedDBPerformance(TestBigRepoR): pdb = GitDB(os.path.join(self.gitrepopath, 'objects')) mdb = MemoryDB() for c, sha in enumerate(pdb.sha_iter()): - ostream = pdb.stream(sha) - # the issue only showed on larger files which are hardly compressible ... - if ostream.type != str_blob_type: - continue - istream = IStream(ostream.type, ostream.size, ostream.stream) - mdb.store(istream) - assert istream.binsha == sha, "Failed on object %s" % bin_to_hex(sha).decode('ascii') - # this can fail ... sometimes, so the packs dataset should be huge - assert len(mdb.stream(sha).read()) == ostream.size + with pdb.stream(sha) as ostream: + # the issue only showed on larger files which are hardly compressible ... + if ostream.type != str_blob_type: + continue + istream = IStream(ostream.type, ostream.size, ostream.stream) + mdb.store(istream) + assert istream.binsha == sha, "Failed on object %s" % bin_to_hex(sha).decode('ascii') + # this can fail ... sometimes, so the packs dataset should be huge + with mdb.stream(sha) as ost2: + assert len(ost2.read()) == ostream.size - if c and c % 1000 == 0: - print("Verified %i loose object compression/decompression cycles" % c, file=sys.stderr) - mdb._cache.clear() + if c and c % 1000 == 0: + print("Verified %i loose object compression/decompression cycles" % c, file=sys.stderr) + mdb._cache.clear() # end for each sha to copy @skip_on_travis_ci @@ -116,14 +117,16 @@ class TestPackedDBPerformance(TestBigRepoR): count = 0 st = time() for entity in pdb.entities(): - pack_verify = entity.is_valid_stream - sha_by_index = entity.index().sha - for index in xrange(entity.index().size()): - try: - assert pack_verify(sha_by_index(index), use_crc=crc) - count += 1 - except UnsupportedOperation: - pass + with entity: + pack_verify = entity.is_valid_stream + idx = entity.index() + sha_by_index = idx.sha + for index in xrange(idx.size()): + try: + assert pack_verify(sha_by_index(index), use_crc=crc) + count += 1 + except UnsupportedOperation: + pass # END ignore old indices # END for each index # END for each entity diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py index 704f4d0..c9b0f15 100644 --- a/gitdb/test/performance/test_stream.py +++ b/gitdb/test/performance/test_stream.py @@ -74,9 +74,9 @@ class TestObjDBPerformance(TestBigRepoR): # reading all at once st = time() - ostream = ldb.stream(sha) - shadata = ostream.read() - elapsed_readall = time() - st + with ldb.stream(sha) as ostream: + shadata = ostream.read() + elapsed_readall = time() - st stream.seek(0) assert shadata == stream.getvalue() @@ -87,12 +87,12 @@ class TestObjDBPerformance(TestBigRepoR): cs = 512 * 1000 chunks = list() st = time() - ostream = ldb.stream(sha) - while True: - data = ostream.read(cs) - chunks.append(data) - if len(data) < cs: - break + with ldb.stream(sha) as ostream: + while True: + data = ostream.read(cs) + chunks.append(data) + if len(data) < cs: + break # END read in chunks elapsed_readchunks = time() - st -- cgit v1.2.1