diff options
Diffstat (limited to 'git/test/db')
| -rw-r--r-- | git/test/db/lib.py | 42 | ||||
| -rw-r--r-- | git/test/db/py/test_git.py | 8 | ||||
| -rw-r--r-- | git/test/db/py/test_loose.py | 6 | ||||
| -rw-r--r-- | git/test/db/py/test_mem.py | 10 | ||||
| -rw-r--r-- | git/test/db/py/test_pack.py | 8 | ||||
| -rw-r--r-- | git/test/db/py/test_ref.py | 8 | ||||
| -rw-r--r-- | git/test/db/test_base.py | 4 |
7 files changed, 66 insertions, 20 deletions
diff --git a/git/test/db/lib.py b/git/test/db/lib.py index 5aebcd5c..499ca252 100644 --- a/git/test/db/lib.py +++ b/git/test/db/lib.py @@ -8,7 +8,8 @@ from git.test.lib import ( with_packs_rw, ZippedStoreShaWriter, fixture_path, - TestBase + TestBase, + rorepo_dir, ) from git.stream import Sha1Writer @@ -29,12 +30,49 @@ from struct import pack __all__ = ('TestDBBase', 'with_rw_directory', 'with_packs_rw', 'fixture_path') class TestDBBase(TestBase): - """Base class providing testing routines on databases""" + """Base Class providing default functionality to all tests such as: + + - Utility functions provided by the TestCase base of the unittest method such as:: + self.fail("todo") + self.failUnlessRaises(...) + + - Class level repository which is considered read-only as it is shared among + all test cases in your type. + Access it using:: + self.rorepo # 'ro' stands for read-only + + The rorepo is in fact your current project's git repo. If you refer to specific + shas for your objects, be sure you choose some that are part of the immutable portion + of the project history ( to assure tests don't fail for others ). + + Derived types can override the default repository type to create a different + read-only repo, allowing to test their specific type + """ # data two_lines = "1234\nhello world" all_data = (two_lines, ) + #{ Configuration + # The repository type to instantiate. It takes at least a path to operate upon + # during instantiation. + RepoCls = None + + # if True, a read-only repo will be provided and RepoCls must be set. + # Otherwise it may remain unset + needs_ro_repo = True + #} END configuration + + @classmethod + def setUpAll(cls): + """ + Dynamically add a read-only repository to our actual type. This way + each test type has its own repository + """ + if cls.needs_ro_repo: + assert cls.RepoCls is not None, "RepoCls class member must be set" + cls.rorepo = cls.RepoCls(rorepo_dir()) + #END handle rorepo def _assert_object_writing_simple(self, db): # write a bunch of objects and query their streams and info diff --git a/git/test/db/py/test_git.py b/git/test/db/py/test_git.py index 524d4080..ecaa5c8f 100644 --- a/git/test/db/py/test_git.py +++ b/git/test/db/py/test_git.py @@ -3,7 +3,7 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php from git.test.lib import rorepo_dir -from git.test.db.lib import * +from git.test.db.lib import TestDBBase, with_rw_directory from git.exc import BadObject from git.db.py.complex import PureGitODB from git.base import OStream, OInfo @@ -12,10 +12,10 @@ from git.util import hex_to_bin, bin_to_hex import os class TestGitDB(TestDBBase): - RepoCls = PureGitODB + needs_ro_repo = False def test_reading(self): - gdb = self.RepoCls(os.path.join(rorepo_dir(), 'objects')) + gdb = PureGitODB(os.path.join(rorepo_dir(), 'objects')) # we have packs and loose objects, alternates doesn't necessarily exist assert 1 < len(gdb.databases()) < 4 @@ -44,7 +44,7 @@ class TestGitDB(TestDBBase): @with_rw_directory def test_writing(self, path): - gdb = self.RepoCls(path) + gdb = PureGitODB(path) # its possible to write objects self._assert_object_writing(gdb) diff --git a/git/test/db/py/test_loose.py b/git/test/db/py/test_loose.py index eb18c05d..0c9b4831 100644 --- a/git/test/db/py/test_loose.py +++ b/git/test/db/py/test_loose.py @@ -2,18 +2,18 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from git.test.db.lib import * +from git.test.db.lib import TestDBBase, with_rw_directory from git.db.py.loose import PureLooseObjectODB from git.exc import BadObject from git.util import bin_to_hex class TestLooseDB(TestDBBase): - RepoCls = PureLooseObjectODB + needs_ro_repo = False @with_rw_directory def test_basics(self, path): - ldb = self.RepoCls(path) + ldb = PureLooseObjectODB(path) # write data self._assert_object_writing(ldb) diff --git a/git/test/db/py/test_mem.py b/git/test/db/py/test_mem.py index ed14cc21..bc98dc56 100644 --- a/git/test/db/py/test_mem.py +++ b/git/test/db/py/test_mem.py @@ -2,14 +2,14 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * -from git.db.py import ( - PureMemoryDB, - PureLooseObjectODB - ) +from git.test.db.lib import TestDBBase, with_rw_directory +from git.db.py.mem import PureMemoryDB +from git.db.py.loose import PureLooseObjectODB class TestPureMemoryDB(TestDBBase): + needs_ro_repo = False + @with_rw_directory def test_writing(self, path): mdb = PureMemoryDB() diff --git a/git/test/db/py/test_pack.py b/git/test/db/py/test_pack.py index 4854c4e7..5043f446 100644 --- a/git/test/db/py/test_pack.py +++ b/git/test/db/py/test_pack.py @@ -2,8 +2,9 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * -from git.db.py import PurePackedODB +from git.test.db.lib import TestDBBase, with_packs_rw + +from git.db.py.pack import PurePackedODB from git.test.lib import fixture_path from git.exc import BadObject, AmbiguousObjectName @@ -13,12 +14,15 @@ import random class TestPackDB(TestDBBase): + needs_ro_repo = False + @with_packs_rw def test_writing(self, path): pdb = PurePackedODB(path) # on demand, we init our pack cache num_packs = len(pdb.entities()) + assert num_packs assert pdb._st_mtime != 0 # test pack directory changed: diff --git a/git/test/db/py/test_ref.py b/git/test/db/py/test_ref.py index 43fbb48f..c5374dc9 100644 --- a/git/test/db/py/test_ref.py +++ b/git/test/db/py/test_ref.py @@ -2,8 +2,8 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * -from git.db.py import PureReferenceDB +from git.test.db.lib import * +from git.db.py.ref import PureReferenceDB from git.util import ( NULL_BIN_SHA, @@ -14,6 +14,8 @@ import os class TestPureReferenceDB(TestDBBase): + needs_ro_repo = False + def make_alt_file(self, alt_path, alt_list): """Create an alternates file which contains the given alternates. The list can be empty""" @@ -44,7 +46,7 @@ class TestPureReferenceDB(TestDBBase): assert len(rdb.databases()) == 1 # we should now find a default revision of ours - git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976") + git_sha = hex_to_bin("5aebcd5cb3340fb31776941d7e4d518a712a8655") assert rdb.has_object(git_sha) # remove valid diff --git a/git/test/db/test_base.py b/git/test/db/test_base.py index 1dbf6fe7..2a882d0a 100644 --- a/git/test/db/test_base.py +++ b/git/test/db/test_base.py @@ -6,7 +6,9 @@ from lib import * from git.db import RefSpec class TestBase(TestDBBase): - + + needs_ro_repo = False + @with_rw_directory def test_basics(self, path): self.failUnlessRaises(ValueError, RefSpec, None, None) |
