diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-11-15 16:53:12 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-11-15 16:53:12 +0100 |
commit | 00ce31ad308ff4c7ef874d2fa64374f47980c85c (patch) | |
tree | 3eed99866de01d4d8e150815eff1fd16c110b473 /test/git/test_submodule.py | |
parent | 4d36f8ff4d1274a8815e932285ad6dbd6b2888af (diff) | |
download | gitpython-00ce31ad308ff4c7ef874d2fa64374f47980c85c.tar.gz |
Objects: Constructor now manually checks and sets the input arguments to the local cache - previously a procedural approach was used, which was less code, but slower too. Especially in case of CommitObjects unrolling the loop manually makes a difference.
Submodule: Implemented query methods and did a bit of testing. More is to come, but the test works for now. As special addition, the submodule implementation uses the section name as submodule ID even though it seems to be just the path. This allows to make renames easier
Diffstat (limited to 'test/git/test_submodule.py')
-rw-r--r-- | test/git/test_submodule.py | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py index 7c8dffcb..f2bc43b5 100644 --- a/test/git/test_submodule.py +++ b/test/git/test_submodule.py @@ -2,14 +2,81 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php from test.testlib import * -from git import * +from git.exc import * +from git.objects.submodule import * class TestSubmodule(TestBase): - kCOTag = '0.1.6' + k_subm_changed = "394ed7006ee5dc8bddfd132b64001d5dfc0ffdd3" + k_no_subm_tag = "0.1.6" + def _do_base_tests(self, rwrepo): """Perform all tests in the given repository, it may be bare or nonbare""" + # manual instantiation + smm = Submodule(rwrepo, "\0"*20) + # name needs to be set in advance + self.failUnlessRaises(AttributeError, getattr, smm, 'name') + + # iterate - 1 submodule + sms = Submodule.list_items(rwrepo) + assert len(sms) == 1 + sm = sms[0] + + # at a different time, there is None + assert len(Submodule.list_items(rwrepo, self.k_no_subm_tag)) == 0 + + assert sm.path == 'lib/git/ext/gitdb' + assert sm.url == 'git://gitorious.org/git-python/gitdb.git' + assert sm.ref == 'master' # its unset in this case + assert sm.parent_commit == rwrepo.head.commit + + # some commits earlier we still have a submodule, but its at a different commit + smold = Submodule.iter_items(rwrepo, self.k_subm_changed).next() + assert smold.binsha != sm.binsha + assert smold != sm + + # force it to reread its information + del(smold._url) + smold.url == sm.url + + # test config_reader/writer methods + sm.config_reader() + sm.config_writer() + smold.config_reader() + # cannot get a writer on historical submodules + self.failUnlessRaises(ValueError, smold.config_writer) + + + # make the old into a new + prev_parent_commit = smold.parent_commit + smold.set_parent_commit('HEAD') + assert smold.parent_commit != prev_parent_commit + assert smold.binsha == sm.binsha + smold.set_parent_commit(prev_parent_commit) + assert smold.binsha != sm.binsha + + # raises if the sm didn't exist in new parent - it keeps its + # parent_commit unchanged + self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_no_subm_tag) + + # TEST TODO: if a path in the gitmodules file, but not in the index, it raises + + # module retrieval is not always possible + if rwrepo.bare: + self.failUnlessRaises(InvalidGitRepositoryError, sm.module) + else: + # its not checked out in our case + self.failUnlessRaises(InvalidGitRepositoryError, sm.module) + + # lets do it - its a recursive one too + + # delete the whole directory and re-initialize + # END handle bare mode + + + # Error if there is no submodule file here + self.failUnlessRaises(IOError, Submodule._config_parser, rwrepo, rwrepo.commit(self.k_no_subm_tag), True) # uncached path/url - retrieves information from .gitmodules file @@ -33,7 +100,7 @@ class TestSubmodule(TestBase): # Writing of historical submodule configurations must not work - @with_rw_repo(kCOTag) + @with_rw_repo('HEAD') def test_base_rw(self, rwrepo): self._do_base_tests(rwrepo) |