diff options
Diffstat (limited to 'git/test')
-rw-r--r-- | git/test/db/base.py | 14 | ||||
-rw-r--r-- | git/test/db/dulwich/__init__.py | 4 | ||||
-rw-r--r-- | git/test/db/dulwich/lib.py | 23 | ||||
-rw-r--r-- | git/test/db/dulwich/test_base.py | 33 | ||||
-rw-r--r-- | git/test/db/lib.py | 3 | ||||
-rw-r--r-- | git/test/lib/helper.py | 76 | ||||
-rw-r--r-- | git/test/objects/test_submodule.py | 4 | ||||
-rw-r--r-- | git/test/performance/db/test_looseodb_dulwich.py | 6 | ||||
-rw-r--r-- | git/test/performance/db/test_odb_dulwich.py | 6 | ||||
-rw-r--r-- | git/test/test_remote.py | 8 |
10 files changed, 168 insertions, 9 deletions
diff --git a/git/test/db/base.py b/git/test/db/base.py index 5291ba03..2f8f50e2 100644 --- a/git/test/db/base.py +++ b/git/test/db/base.py @@ -601,20 +601,26 @@ class RepoBase(TestDBBase): self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}") def test_submodules(self): - assert len(self.rorepo.submodules) == 1 # non-recursive + assert len(self.rorepo.submodules) == 2 # non-recursive # in previous configurations, we had recursive repositories so this would compare to 2 - # now there is only one left, as gitdb was merged - assert len(list(self.rorepo.iter_submodules())) == 1 + # now there is only one left, as gitdb was merged, but we have smmap instead + assert len(list(self.rorepo.iter_submodules())) == 2 - assert isinstance(self.rorepo.submodule("git/ext/async"), Submodule) + assert isinstance(self.rorepo.submodule("async"), Submodule) self.failUnlessRaises(ValueError, self.rorepo.submodule, "doesn't exist") @with_rw_repo('HEAD', bare=False) def test_submodule_update(self, rwrepo): # fails in bare mode rwrepo._bare = True + # special handling: there are repo implementations which have a bare attribute. IN that case, set it directly + if not rwrepo.bare: + rwrepo.bare = True self.failUnlessRaises(InvalidGitRepositoryError, rwrepo.submodule_update) rwrepo._bare = False + if rwrepo.bare: + rwrepo.bare = False + #END special repo handling # test create submodule sm = rwrepo.submodules[0] diff --git a/git/test/db/dulwich/__init__.py b/git/test/db/dulwich/__init__.py new file mode 100644 index 00000000..8a681e42 --- /dev/null +++ b/git/test/db/dulwich/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# This module is part of GitDB and is released under +# the New BSD License: http://www.opensource.org/licenses/bsd-license.php diff --git a/git/test/db/dulwich/lib.py b/git/test/db/dulwich/lib.py new file mode 100644 index 00000000..56734064 --- /dev/null +++ b/git/test/db/dulwich/lib.py @@ -0,0 +1,23 @@ +"""dulwich specific utilities, as well as all the default ones""" + +from git.test.lib import ( + InheritedTestMethodsOverrideWrapperMetaClsAutoMixin, + needs_module_or_skip + ) + +__all__ = ['needs_dulwich_or_skip', 'DulwichRequiredMetaMixin'] + +#{ Decoorators + +def needs_dulwich_or_skip(func): + """Skip this test if we have no dulwich - print warning""" + return needs_module_or_skip('dulwich')(func) + +#}END decorators + +#{ MetaClasses + +class DulwichRequiredMetaMixin(InheritedTestMethodsOverrideWrapperMetaClsAutoMixin): + decorator = [needs_dulwich_or_skip] + +#} END metaclasses diff --git a/git/test/db/dulwich/test_base.py b/git/test/db/dulwich/test_base.py new file mode 100644 index 00000000..50e64131 --- /dev/null +++ b/git/test/db/dulwich/test_base.py @@ -0,0 +1,33 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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.test.lib import TestBase, with_rw_repo +from git.test.db.base import RepoBase + + + +try: + import dulwich +except ImportError: + # om this case, all other dulwich tests will be skipped + # Need to properly initialize the class though, otherwise it would fail + from git.db.complex import PureCompatibilityGitDB as DulwichDB +else: + # now we know dulwich is available, to do futher imports + from git.db.dulwich.complex import DulwichCompatibilityGitDB as DulwichDB + +#END handle imports + +class TestPyDBBase(RepoBase): + __metaclass__ = DulwichRequiredMetaMixin + RepoCls = DulwichDB + + @needs_dulwich_or_skip + @with_rw_repo('HEAD', bare=False) + def test_basics(self, rw_repo): + db = DulwichDB(rw_repo.working_tree_dir) + print db.git_dir + + diff --git a/git/test/db/lib.py b/git/test/db/lib.py index 499ca252..2b3ddde5 100644 --- a/git/test/db/lib.py +++ b/git/test/db/lib.py @@ -70,7 +70,8 @@ class TestDBBase(TestBase): each test type has its own repository """ if cls.needs_ro_repo: - assert cls.RepoCls is not None, "RepoCls class member must be set" + if cls is not TestDBBase: + assert cls.RepoCls is not None, "RepoCls class member must be set in %s" % cls cls.rorepo = cls.RepoCls(rorepo_dir()) #END handle rorepo diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index d9a92a52..2045f9d3 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -12,6 +12,9 @@ import tempfile import shutil import cStringIO +import warnings +from nose import SkipTest + from base import ( maketemp, rorepo_dir @@ -19,8 +22,8 @@ from base import ( __all__ = ( - 'StringProcessAdapter', 'GlobalsItemDeletorMetaCls', - 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', + 'StringProcessAdapter', 'GlobalsItemDeletorMetaCls', 'InheritedTestMethodsOverrideWrapperMetaClsAutoMixin', + 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'needs_module_or_skip' ) @@ -191,6 +194,27 @@ def with_rw_and_rw_remote_repo(working_tree_ref): return argument_passer +def needs_module_or_skip(module): + """Decorator to be used for test cases only. + Print a warning if the given module could not be imported, and skip the test. + Otherwise run the test as usual + :param module: the name of the module to skip""" + def argpasser(func): + def wrapper(self, *args, **kwargs): + try: + __import__(module) + except ImportError: + msg = "Module %r is required to run this test - skipping" % module + warnings.warn(msg) + raise SkipTest(msg) + #END check import + return func(self, *args, **kwargs) + #END wrapper + wrapper.__name__ = func.__name__ + return wrapper + #END argpasser + return argpasser + #} END decorators #{ Meta Classes @@ -207,10 +231,56 @@ class GlobalsItemDeletorMetaCls(type): 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) + try: + delattr(mod, metacls.ModuleToDelete) + except AttributeError: + pass + #END skip case that people import our base without actually using it #END handle deletion return new_type + +class InheritedTestMethodsOverrideWrapperMetaClsAutoMixin(object): + """Automatically picks up the actual metaclass of the the type to be created, + that is the one inherited by one of the bases, and patch up its __new__ to use + the InheritedTestMethodsOverrideWrapperInstanceDecorator with our configured decorator""" + + #{ Configuration + # decorator function to use when wrapping the inherited methods. Put it into a list as first member + # to hide it from being created as class method + decorator = [] + #}END configuration + + @classmethod + def _find_metacls(metacls, bases): + """emulate pythons lookup""" + mcls_attr = '__metaclass__' + for base in bases: + if hasattr(base, mcls_attr): + return getattr(base, mcls_attr) + return metacls._find_metacls(base.__bases__) + #END for each base + raise AssertionError("base class had not metaclass attached") + + @classmethod + def _patch_methods_recursive(metacls, bases, clsdict): + """depth-first patching of methods""" + for base in bases: + metacls._patch_methods_recursive(base.__bases__, clsdict) + for name, item in base.__dict__.iteritems(): + if not name.startswith('test_'): + continue + #END skip non-tests + clsdict[name] = metacls.decorator[0](item) + #END for each item + #END for each base + + def __new__(metacls, name, bases, clsdict): + assert metacls.decorator, "'decorator' member needs to be set in subclass" + base_metacls = metacls._find_metacls(bases) + metacls._patch_methods_recursive(bases, clsdict) + return base_metacls.__new__(base_metacls, name, bases, clsdict) + #} END meta classes class TestBase(TestCase): diff --git a/git/test/objects/test_submodule.py b/git/test/objects/test_submodule.py index e5adedbc..2b7c7f40 100644 --- a/git/test/objects/test_submodule.py +++ b/git/test/objects/test_submodule.py @@ -284,7 +284,9 @@ class TestSubmodule(TestObjectBase): # make sure sub-submodule is not modified by forcing it to update # to the revision it is supposed to point to. - csm.update() + for subitem in sm.traverse(): + subitem.update() + #END checkout to right commit # this would work assert sm.remove(dry_run=True) is sm diff --git a/git/test/performance/db/test_looseodb_dulwich.py b/git/test/performance/db/test_looseodb_dulwich.py new file mode 100644 index 00000000..cf27a528 --- /dev/null +++ b/git/test/performance/db/test_looseodb_dulwich.py @@ -0,0 +1,6 @@ +from git.db.dulwich.complex import DulwichGitODB +from looseodb_impl import TestLooseDBWPerformanceBase + +class TestPureLooseDB(TestLooseDBWPerformanceBase): + LooseODBCls = DulwichGitODB + diff --git a/git/test/performance/db/test_odb_dulwich.py b/git/test/performance/db/test_odb_dulwich.py new file mode 100644 index 00000000..069c5b43 --- /dev/null +++ b/git/test/performance/db/test_odb_dulwich.py @@ -0,0 +1,6 @@ +from git.db.dulwich.complex import DulwichCompatibilityGitDB +from odb_impl import TestObjDBPerformanceBase + +class TestPureDB(TestObjDBPerformanceBase): + RepoCls = DulwichCompatibilityGitDB + diff --git a/git/test/test_remote.py b/git/test/test_remote.py index cef8687b..30bd1232 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -21,6 +21,8 @@ from git.refs import ( SymbolicReference ) +from nose import SkipTest + import tempfile import shutil import os @@ -352,7 +354,13 @@ class TestRemote(TestBase): # the same repository TagReference.delete(rw_repo, new_tag, other_tag) remote.push(":%s" % other_tag.path) + + def test_todo(self): + # If you see this, plesase remind yourself, that all this needs to be run + # per repository type ! + raise SkipTest("todo") + @with_rw_and_rw_remote_repo('0.1.6') def test_base(self, rw_repo, remote_repo): num_remotes = 0 |