summaryrefslogtreecommitdiff
path: root/gitdb/test
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-24 17:32:06 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-24 18:26:06 +0200
commit534c9bbe320f638153f9ffd79b79fa124b544d0f (patch)
tree731c56781e2b0bf367919ed8a0ef7e0a61f6a200 /gitdb/test
parent08b1f5f4fdc95d4ce24aa33ec82ac0d9723b8a02 (diff)
downloadgitdb-2.1.0.dev1.tar.gz
fix(win): FIX and HIDE 2 win-errors remainingv2.1.0.dev1
+ File-in-use errors were fixed with `gitdb.util.mman.collect()`! + This call is disabled `gitdb.util.HIDE_WINDOWS_KNOWN_ERRORS == False`. + Depend on latest smmp `v2.1.0.dev1` tag
Diffstat (limited to 'gitdb/test')
-rw-r--r--gitdb/test/db/lib.py10
-rw-r--r--gitdb/test/db/test_git.py3
-rw-r--r--gitdb/test/db/test_pack.py10
-rw-r--r--gitdb/test/lib.py9
-rw-r--r--gitdb/test/performance/test_pack_streaming.py5
-rw-r--r--gitdb/test/test_example.py21
-rw-r--r--gitdb/test/test_pack.py77
-rw-r--r--gitdb/test/test_stream.py17
8 files changed, 85 insertions, 67 deletions
diff --git a/gitdb/test/db/lib.py b/gitdb/test/db/lib.py
index 528bcc1..d7365ea 100644
--- a/gitdb/test/db/lib.py
+++ b/gitdb/test/db/lib.py
@@ -39,7 +39,7 @@ class TestDBBase(TestBase):
# data
two_lines = b'1234\nhello world'
- all_data = (two_lines, )
+ all_data = (two_lines,)
def _assert_object_writing_simple(self, db):
# write a bunch of objects and query their streams and info
@@ -56,10 +56,10 @@ class TestDBBase(TestBase):
assert isinstance(info, OInfo)
assert info.type == istream.type and info.size == istream.size
- stream = db.stream(istream.binsha)
- assert isinstance(stream, OStream)
- assert stream.binsha == info.binsha and stream.type == info.type
- assert stream.read() == data
+ with db.stream(istream.binsha) as stream:
+ assert isinstance(stream, OStream)
+ assert stream.binsha == info.binsha and stream.type == info.type
+ assert stream.read() == data
# END for each item
assert db.size() == null_objs + ni
diff --git a/gitdb/test/db/test_git.py b/gitdb/test/db/test_git.py
index acc0f15..b637c13 100644
--- a/gitdb/test/db/test_git.py
+++ b/gitdb/test/db/test_git.py
@@ -24,7 +24,8 @@ class TestGitDB(TestDBBase):
# access should be possible
gitdb_sha = next(gdb.sha_iter())
assert isinstance(gdb.info(gitdb_sha), OInfo)
- assert isinstance(gdb.stream(gitdb_sha), OStream)
+ with gdb.stream(gitdb_sha) as stream:
+ assert isinstance(gdb.stream(gitdb_sha), OStream)
ni = 50
assert gdb.size() >= ni
sha_list = list(gdb.sha_iter())
diff --git a/gitdb/test/db/test_pack.py b/gitdb/test/db/test_pack.py
index b361a59..f7e631e 100644
--- a/gitdb/test/db/test_pack.py
+++ b/gitdb/test/db/test_pack.py
@@ -13,10 +13,16 @@ from gitdb.exc import BadObject, AmbiguousObjectName
import os
import random
+from gitdb.util import mman, HIDE_WINDOWS_KNOWN_ERRORS
class TestPackDB(TestDBBase):
+ ## Unless HIDE_WINDOWS_KNOWN_ERRORS, on Windows fails with:
+ # File "D:\Work\gitdb.git\gitdb\test\db\test_pack.py", line 41, in test_writing
+ # os.rename(pack_path, new_pack_path)
+ # PermissionError: [WinError 32] The process cannot access the file
+ # because it is being used by another process: 'pack-c0438c19fb16422b6bbcce24387b3264416d485b.packrenamed'
@with_rw_directory
@with_packs_rw
def test_writing(self, path):
@@ -30,6 +36,10 @@ class TestPackDB(TestDBBase):
# packs removed - rename a file, should affect the glob
pack_path = pdb.entities()[0].pack().path()
new_pack_path = pack_path + "renamed"
+ ## FIXME: Had to manually collect leaked files!!
+ if HIDE_WINDOWS_KNOWN_ERRORS:
+ leaked_mmaps = mman.collect()
+ self.assertEqual(leaked_mmaps, 6)
os.rename(pack_path, new_pack_path)
pdb.update_cache(force=True)
diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py
index 8b5cb02..0017031 100644
--- a/gitdb/test/lib.py
+++ b/gitdb/test/lib.py
@@ -17,7 +17,7 @@ import tempfile
import unittest
from gitdb import OStream
-from gitdb.util import rmtree
+from gitdb.util import rmtree, mman, HIDE_WINDOWS_KNOWN_ERRORS
from gitdb.utils.compat import xrange
@@ -96,6 +96,13 @@ def with_rw_directory(func):
# memory maps closed, once objects go out of scope. For some reason
# though this is not the case here unless we collect explicitly.
if not keep:
+ if HIDE_WINDOWS_KNOWN_ERRORS:
+ ## Or else 2 Windows TCs fail with:
+ # File "D:\Work\gitdb.git\gitdb\util.py", line 141, in onerror
+ # func(path) # Will scream if still not possible to delete.
+ # PermissionError: [WinError 32] The process cannot access the file
+ # because it is being used by another process: 'sss\\index_cc_wll5'
+ mman.collect()
gc.collect()
rmtree(path)
# END handle exception
diff --git a/gitdb/test/performance/test_pack_streaming.py b/gitdb/test/performance/test_pack_streaming.py
index 76f0f4a..21a7532 100644
--- a/gitdb/test/performance/test_pack_streaming.py
+++ b/gitdb/test/performance/test_pack_streaming.py
@@ -46,7 +46,8 @@ class TestPackStreamingPerformance(TestBigRepoR):
st = time()
for sha in pdb.sha_iter():
count += 1
- pdb.stream(sha)
+ with pdb.stream(sha):
+ pass
if count == ni:
break
# END gather objects for pack-writing
@@ -55,6 +56,8 @@ class TestPackStreamingPerformance(TestBigRepoR):
(ni, elapsed, ni / (elapsed or 1)), file=sys.stderr)
st = time()
+ ## We are leaking files here, but we don't care...
+ # and we need a `contextlib.ExitStack` to safely close them.
PackEntity.write_pack((pdb.stream(sha) for sha in pdb.sha_iter()), ostream.write, object_count=ni)
elapsed = time() - st
total_kb = ostream.bytes_written() / 1000
diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py
index 6e80bf5..0bf6d1a 100644
--- a/gitdb/test/test_example.py
+++ b/gitdb/test/test_example.py
@@ -18,26 +18,19 @@ class TestExamples(TestBase):
for sha1 in ldb.sha_iter():
oinfo = ldb.info(sha1)
- ostream = ldb.stream(sha1)
- assert oinfo[:3] == ostream[:3]
+ with ldb.stream(sha1) as ostream:
+ assert oinfo[:3] == ostream[:3]
- assert len(ostream.read()) == ostream.size
+ assert len(ostream.read()) == ostream.size
assert ldb.has_object(oinfo.binsha)
# END for each sha in database
- # assure we close all files
- try:
- del(ostream)
- del(oinfo)
- except UnboundLocalError:
- pass
- # END ignore exception if there are no loose objects
data = "my data".encode("ascii")
istream = IStream("blob", len(data), BytesIO(data))
# the object does not yet have a sha
assert istream.binsha is None
- ldb.store(istream)
- # now the sha is set
- assert len(istream.binsha) == 20
- assert ldb.has_object(istream.binsha)
+ with ldb.store(istream):
+ # now the sha is set
+ assert len(istream.binsha) == 20
+ assert ldb.has_object(istream.binsha)
diff --git a/gitdb/test/test_pack.py b/gitdb/test/test_pack.py
index 7484193..4f259cb 100644
--- a/gitdb/test/test_pack.py
+++ b/gitdb/test/test_pack.py
@@ -88,42 +88,42 @@ class TestPack(TestBase):
num_obj = 0
for obj in pack.stream_iter():
- num_obj += 1
- info = pack.info(obj.pack_offset)
- stream = pack.stream(obj.pack_offset)
-
- assert info.pack_offset == stream.pack_offset
- assert info.type_id == stream.type_id
- assert hasattr(stream, 'read')
-
- # it should be possible to read from both streams
- assert obj.read() == stream.read()
-
- streams = pack.collect_streams(obj.pack_offset)
- assert streams
-
- # read the stream
- try:
- dstream = DeltaApplyReader.new(streams)
- except ValueError:
- # ignore these, old git versions use only ref deltas,
- # which we havent resolved ( as we are without an index )
- # Also ignore non-delta streams
- continue
- # END get deltastream
-
- with dstream:
- # read all
- data = dstream.read()
- assert len(data) == dstream.size
-
- # test seek
- dstream.seek(0)
- assert dstream.read() == data
-
- # read chunks
- # NOTE: the current implementation is safe, it basically transfers
- # all calls to the underlying memory map
+ with obj:
+ num_obj += 1
+ info = pack.info(obj.pack_offset)
+ with pack.stream(obj.pack_offset) as stream:
+ assert info.pack_offset == stream.pack_offset
+ assert info.type_id == stream.type_id
+ assert hasattr(stream, 'read')
+
+ # it should be possible to read from both streams
+ assert obj.read() == stream.read()
+
+ streams = pack.collect_streams(obj.pack_offset)
+ assert streams
+
+ # read the stream
+ try:
+ dstream = DeltaApplyReader.new(streams)
+ except ValueError:
+ # ignore these, old git versions use only ref deltas,
+ # which we havent resolved ( as we are without an index )
+ # Also ignore non-delta streams
+ continue
+ # END get deltastream
+
+ with dstream:
+ # read all
+ data = dstream.read()
+ assert len(data) == dstream.size
+
+ # test seek
+ dstream.seek(0)
+ assert dstream.read() == data
+
+ # read chunks
+ # NOTE: the current implementation is safe, it basically transfers
+ # all calls to the underlying memory map
# END for each object
assert num_obj == size
@@ -142,6 +142,11 @@ class TestPack(TestBase):
self._assert_pack_file(pack, version, size)
# END for each pack to test
+ ## Unless HIDE_WINDOWS_KNOWN_ERRORS, on Windows fails with:
+ # File "D:\Work\gitdb.git\gitdb\util.py", line 141, in onerror
+ # func(path) # Will scream if still not possible to delete.
+ # PermissionError: [WinError 32] The process cannot access the file
+ # because it is being used by another process: 'sss\\index_cc_wll5'
@with_rw_directory
def test_pack_entity(self, rw_dir):
pack_objs = list()
diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py
index 7d3eeae..9bc3ca5 100644
--- a/gitdb/test/test_stream.py
+++ b/gitdb/test/test_stream.py
@@ -154,13 +154,12 @@ class TestStream(TestBase):
mdb = MemoryDB()
for sha in (b'888401851f15db0eed60eb1bc29dec5ddcace911',
b'7bb839852ed5e3a069966281bb08d50012fb309b',):
- ostream = odb.stream(hex_to_bin(sha))
-
- # if there is a bug, we will be missing one byte exactly !
- data = ostream.read()
- assert len(data) == ostream.size
-
- # Putting it back in should yield nothing new - after all, we have
- dump = mdb.store(IStream(ostream.type, ostream.size, BytesIO(data)))
- assert dump.hexsha == sha
+ with odb.stream(hex_to_bin(sha)) as ostream:
+ # if there is a bug, we will be missing one byte exactly !
+ data = ostream.read()
+ assert len(data) == ostream.size
+
+ # Putting it back in should yield nothing new - after all, we have
+ dump = mdb.store(IStream(ostream.type, ostream.size, BytesIO(data)))
+ assert dump.hexsha == sha
# end for each loose object sha to test