Skip to content

Commit c192638

Browse files
committed
Fixed all remaining python repository tests
1 parent 2bfc2e9 commit c192638

File tree

9 files changed

+77
-64
lines changed

9 files changed

+77
-64
lines changed

git/test/db/lib.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
with_packs_rw,
99
ZippedStoreShaWriter,
1010
fixture_path,
11-
TestBase
11+
TestBase,
12+
rorepo_dir,
1213
)
1314

1415
from git.stream import Sha1Writer
@@ -29,12 +30,49 @@
2930
__all__ = ('TestDBBase', 'with_rw_directory', 'with_packs_rw', 'fixture_path')
3031

3132
class TestDBBase(TestBase):
32-
"""Base class providing testing routines on databases"""
33+
"""Base Class providing default functionality to all tests such as:
34+
35+
- Utility functions provided by the TestCase base of the unittest method such as::
36+
self.fail("todo")
37+
self.failUnlessRaises(...)
38+
39+
- Class level repository which is considered read-only as it is shared among
40+
all test cases in your type.
41+
Access it using::
42+
self.rorepo # 'ro' stands for read-only
43+
44+
The rorepo is in fact your current project's git repo. If you refer to specific
45+
shas for your objects, be sure you choose some that are part of the immutable portion
46+
of the project history ( to assure tests don't fail for others ).
47+
48+
Derived types can override the default repository type to create a different
49+
read-only repo, allowing to test their specific type
50+
"""
3351

3452
# data
3553
two_lines = "1234\nhello world"
3654
all_data = (two_lines, )
3755

56+
#{ Configuration
57+
# The repository type to instantiate. It takes at least a path to operate upon
58+
# during instantiation.
59+
RepoCls = None
60+
61+
# if True, a read-only repo will be provided and RepoCls must be set.
62+
# Otherwise it may remain unset
63+
needs_ro_repo = True
64+
#} END configuration
65+
66+
@classmethod
67+
def setUpAll(cls):
68+
"""
69+
Dynamically add a read-only repository to our actual type. This way
70+
each test type has its own repository
71+
"""
72+
if cls.needs_ro_repo:
73+
assert cls.RepoCls is not None, "RepoCls class member must be set"
74+
cls.rorepo = cls.RepoCls(rorepo_dir())
75+
#END handle rorepo
3876

3977
def _assert_object_writing_simple(self, db):
4078
# write a bunch of objects and query their streams and info

git/test/db/py/test_git.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
from git.test.lib import rorepo_dir
6-
from git.test.db.lib import *
6+
from git.test.db.lib import TestDBBase, with_rw_directory
77
from git.exc import BadObject
88
from git.db.py.complex import PureGitODB
99
from git.base import OStream, OInfo
@@ -12,10 +12,10 @@
1212
import os
1313

1414
class TestGitDB(TestDBBase):
15-
RepoCls = PureGitODB
15+
needs_ro_repo = False
1616

1717
def test_reading(self):
18-
gdb = self.RepoCls(os.path.join(rorepo_dir(), 'objects'))
18+
gdb = PureGitODB(os.path.join(rorepo_dir(), 'objects'))
1919

2020
# we have packs and loose objects, alternates doesn't necessarily exist
2121
assert 1 < len(gdb.databases()) < 4
@@ -44,7 +44,7 @@ def test_reading(self):
4444

4545
@with_rw_directory
4646
def test_writing(self, path):
47-
gdb = self.RepoCls(path)
47+
gdb = PureGitODB(path)
4848

4949
# its possible to write objects
5050
self._assert_object_writing(gdb)

git/test/db/py/test_loose.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from git.test.db.lib import *
5+
from git.test.db.lib import TestDBBase, with_rw_directory
66
from git.db.py.loose import PureLooseObjectODB
77
from git.exc import BadObject
88
from git.util import bin_to_hex
99

1010
class TestLooseDB(TestDBBase):
1111

12-
RepoCls = PureLooseObjectODB
12+
needs_ro_repo = False
1313

1414
@with_rw_directory
1515
def test_basics(self, path):
16-
ldb = self.RepoCls(path)
16+
ldb = PureLooseObjectODB(path)
1717

1818
# write data
1919
self._assert_object_writing(ldb)

git/test/db/py/test_mem.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from lib import *
6-
from git.db.py import (
7-
PureMemoryDB,
8-
PureLooseObjectODB
9-
)
5+
from git.test.db.lib import TestDBBase, with_rw_directory
6+
from git.db.py.mem import PureMemoryDB
7+
from git.db.py.loose import PureLooseObjectODB
108

119
class TestPureMemoryDB(TestDBBase):
1210

11+
needs_ro_repo = False
12+
1313
@with_rw_directory
1414
def test_writing(self, path):
1515
mdb = PureMemoryDB()

git/test/db/py/test_pack.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from lib import *
6-
from git.db.py import PurePackedODB
5+
from git.test.db.lib import TestDBBase, with_packs_rw
6+
7+
from git.db.py.pack import PurePackedODB
78
from git.test.lib import fixture_path
89

910
from git.exc import BadObject, AmbiguousObjectName
@@ -13,12 +14,15 @@
1314

1415
class TestPackDB(TestDBBase):
1516

17+
needs_ro_repo = False
18+
1619
@with_packs_rw
1720
def test_writing(self, path):
1821
pdb = PurePackedODB(path)
1922

2023
# on demand, we init our pack cache
2124
num_packs = len(pdb.entities())
25+
assert num_packs
2226
assert pdb._st_mtime != 0
2327

2428
# test pack directory changed:

git/test/db/py/test_ref.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from lib import *
6-
from git.db.py import PureReferenceDB
5+
from git.test.db.lib import *
6+
from git.db.py.ref import PureReferenceDB
77

88
from git.util import (
99
NULL_BIN_SHA,
@@ -14,6 +14,8 @@
1414

1515
class TestPureReferenceDB(TestDBBase):
1616

17+
needs_ro_repo = False
18+
1719
def make_alt_file(self, alt_path, alt_list):
1820
"""Create an alternates file which contains the given alternates.
1921
The list can be empty"""
@@ -44,7 +46,7 @@ def test_writing(self, path):
4446
assert len(rdb.databases()) == 1
4547

4648
# we should now find a default revision of ours
47-
git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976")
49+
git_sha = hex_to_bin("5aebcd5cb3340fb31776941d7e4d518a712a8655")
4850
assert rdb.has_object(git_sha)
4951

5052
# remove valid

git/test/db/test_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from git.db import RefSpec
77

88
class TestBase(TestDBBase):
9-
9+
10+
needs_ro_repo = False
11+
1012
@with_rw_directory
1113
def test_basics(self, path):
1214
self.failUnlessRaises(ValueError, RefSpec, None, None)

git/test/lib/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def with_packs_rw(func):
8686
:note: needs with_rw_directory wrapped around it"""
8787
def wrapper(self, path):
8888
src_pack_glob = fixture_path('packs/*')
89+
print src_pack_glob
8990
copy_files_globbed(src_pack_glob, path, hard_link_ok=True)
9091
return func(self, path)
9192
# END wrapper
@@ -103,7 +104,6 @@ def rorepo_dir():
103104
base = os.path.join(dirname(dirname(dirname(dirname(__file__)))), '.git')
104105
assert os.path.isdir(base)
105106
return base
106-
107107

108108
def maketemp(*args, **kwargs):
109109
"""Wrapper around default tempfile.mktemp to fix an osx issue"""
@@ -116,8 +116,15 @@ def fixture_path(relapath=''):
116116
""":return: absolute path into the fixture directory
117117
:param relapath: relative path into the fixtures directory, or ''
118118
to obtain the fixture directory itself"""
119-
return os.path.join(dirname(__file__), 'fixtures', relapath)
119+
test_dir = os.path.dirname(os.path.dirname(__file__))
120+
return os.path.join(test_dir, "fixtures", relapath)
120121

122+
def fixture(name):
123+
return open(fixture_path(name), 'rb').read()
124+
125+
def absolute_project_path():
126+
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
127+
121128
def copy_files_globbed(source_glob, target_dir, hard_link_ok=False):
122129
"""Copy all files found according to the given source glob into the target directory
123130
:param hard_link_ok: if True, hard links will be created if possible. Otherwise

git/test/lib/helper.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,11 @@
1919

2020

2121
__all__ = (
22-
'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter',
22+
'StringProcessAdapter', 'GlobalsItemDeletorMetaCls',
2323
'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase',
24-
'GlobalsItemDeletorMetaCls'
25-
)
24+
)
2625

27-
#{ Routines
2826

29-
def fixture_path(name):
30-
test_dir = os.path.dirname(os.path.dirname(__file__))
31-
return os.path.join(test_dir, "fixtures", name)
32-
33-
def fixture(name):
34-
return open(fixture_path(name), 'rb').read()
35-
36-
def absolute_project_path():
37-
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
38-
39-
#} END routines
4027

4128
#{ Adapters
4229

@@ -227,37 +214,10 @@ def __new__(metacls, name, bases, clsdict):
227214
class TestBase(TestCase):
228215
"""
229216
Base Class providing default functionality to all tests such as:
230-
231217
- Utility functions provided by the TestCase base of the unittest method such as::
232218
self.fail("todo")
233219
self.failUnlessRaises(...)
234-
235-
- Class level repository which is considered read-only as it is shared among
236-
all test cases in your type.
237-
Access it using::
238-
self.rorepo # 'ro' stands for read-only
239-
240-
The rorepo is in fact your current project's git repo. If you refer to specific
241-
shas for your objects, be sure you choose some that are part of the immutable portion
242-
of the project history ( to assure tests don't fail for others ).
243-
244-
Derived types can override the default repository type to create a differnt
245-
read-only repo, allowing to test their specific type
246220
"""
247-
#{ Configuration
248-
# The repository type to instantiate. It takes at least a path to operate upon
249-
# during instantiation.
250-
RepoCls = None
251-
#} END configuration
252-
253-
@classmethod
254-
def setUpAll(cls):
255-
"""
256-
Dynamically add a read-only repository to our actual type. This way
257-
each test type has its own repository
258-
"""
259-
assert cls.RepoCls is not None, "RepoCls class member must be set"
260-
cls.rorepo = cls.RepoCls(rorepo_dir())
261221

262222
def _make_file(self, rela_path, data, repo=None):
263223
"""

0 commit comments

Comments
 (0)