diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2011-05-30 13:06:37 +0200 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2011-05-30 13:06:37 +0200 |
| commit | 024adf37acddd6a5d8293b6b5d15795c59a142c0 (patch) | |
| tree | 3610b99168f984acb0eefe3a995295f4d3b1d096 /git/test/lib/helper.py | |
| parent | 112bb1672d6b28f203e7839e320b985486636800 (diff) | |
| download | GitPython-024adf37acddd6a5d8293b6b5d15795c59a142c0.tar.gz GitPython-024adf37acddd6a5d8293b6b5d15795c59a142c0.zip | |
Fixed tests far enough to allow basic repository tests to be applied to any of the new database types. This reduces code duplication to the mere minimum, but allows custom tests to be added on top easily and flexibly
Diffstat (limited to 'git/test/lib/helper.py')
| -rw-r--r-- | git/test/lib/helper.py | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 48d684e0..4fd82899 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -12,13 +12,16 @@ import tempfile import shutil import cStringIO -from base import maketemp +from base import ( + maketemp, + rorepo_dir + ) -GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) __all__ = ( 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter', - 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO' + 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', + 'GlobalsItemDeletorMetaCls' ) #{ Routines @@ -200,6 +203,26 @@ def with_rw_and_rw_remote_repo(working_tree_ref): return argument_passer #} END decorators + +#{ Meta Classes +class GlobalsItemDeletorMetaCls(type): + """Utiltiy to prevent the RepoBase to be picked up by nose as the metacls + will delete the instance from the globals""" + #{ Configuration + # Set this to a string name of the module to delete + ModuleToDelete = None + #} END configuration + + def __new__(metacls, name, bases, clsdict): + assert metacls.ModuleToDelete is not None, "Invalid metaclass configuration" + new_type = super(GlobalsItemDeletorMetaCls, metacls).__new__(metacls, name, bases, clsdict) + if name != metacls.ModuleToDelete: + mod = __import__(new_type.__module__, globals(), locals(), new_type.__module__) + delattr(mod, metacls.ModuleToDelete) + #END handle deletion + return new_type + +#} END meta classes class TestBase(TestCase): """ @@ -217,7 +240,15 @@ class TestBase(TestCase): 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 differnt + read-only repo, allowing to test their specific type """ + #{ Configuration + # The repository type to instantiate. It takes at least a path to operate upon + # during instantiation. + RepoCls = None + #} END configuration @classmethod def setUpAll(cls): @@ -225,7 +256,8 @@ class TestBase(TestCase): Dynamically add a read-only repository to our actual type. This way each test type has its own repository """ - cls.rorepo = Repo(GIT_REPO) + assert cls.RepoCls is not None, "RepoCls class member must be set" + cls.rorepo = cls.RepoCls(rorepo_dir()) def _make_file(self, rela_path, data, repo=None): """ |
