diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 22:50:44 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 22:50:44 +0200 |
commit | 3c0a65226f038c58fc6d6ed525f38fc00b3579b7 (patch) | |
tree | a5b715a490d9cbd8f45eabc1968374c96bdea1c0 /test/git/test_base.py | |
parent | 9c0c2fc4ee2d8a5d0a2de50ba882657989dedc51 (diff) | |
parent | c68459a17ff59043d29c90020fffe651b2164e6a (diff) | |
download | gitpython-3c0a65226f038c58fc6d6ed525f38fc00b3579b7.tar.gz |
Merge branch 'hierarchyfix' into improvements
* hierarchyfix:
Added remaining tests for new base classes and removed some methods whose existance was doubtful or unsafe
Fixed remaining tests to deal with the changes
commit: fixed failing commit tests as the mocked git command would always return the same thing which does not work anymore - re-implemented it in a more dynamic manner, but in the end tests will have to be revised anyway
mode-only change for test system - this should be in a separate repository in fact so that changes are a little more self-contained and not depending on the actual source repository
fixed issue in Ref.name implementation which would not handle components properly
lazymixin system now supports per-attribute baking, it is up to the class whether it bakes more. This also leads to more efficient use of memory as values are only cached and set when required - the baking system does not require an own tracking variable anymore, and values are only to be cached once - then python will natively find the cache without involving any additional overhead. This works by using __getattr__ instead of __get_attribute__ which would always be called
put Tree and Blob onto a new base class suitable to deal with IndexObjects
blob tests fixed to deal with changes to the Blob type
converted all spaces to tabs ( 4 spaces = 1 tab ) just to allow me and my editor to work with the files properly. Can convert it back for releaes
Re-designed the tag testing - it does not use fixtures anymore but dyamically checks the existance of tags within the repository - it basically tests the interface and checks that expected return types are actually returned
Intermediate commit: commit,tree and blob objects now derive from object - test is in place which still fails on purpose. Need to integrate tags which can be objects or just a special form of a ref
Renamed lazy.py to base.py to have a file for base classes - lazy not yet changed to allow proper rename tracking
Diffstat (limited to 'test/git/test_base.py')
-rw-r--r-- | test/git/test_base.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/git/test_base.py b/test/git/test_base.py new file mode 100644 index 00000000..8f522cec --- /dev/null +++ b/test/git/test_base.py @@ -0,0 +1,78 @@ +# test_base.py +# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +import time +from test.testlib import * +from git import * +import git.base as base +from itertools import chain + +class TestBase(object): + + type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"), + ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"), + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c"), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10") ) + + def setup(self): + self.repo = Repo(GIT_REPO) + + def test_base_object(self): + # test interface of base object classes + fcreators = (self.repo.blob, self.repo.tree, self.repo.commit, lambda id: TagObject(self.repo,id) ) + assert len(fcreators) == len(self.type_tuples) + + s = set() + num_objs = 0 + num_index_objs = 0 + for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): + item = fcreator(hexsha) + num_objs += 1 + assert item.id == hexsha + assert item.type == typename + assert item.size + assert item.data + assert item == item + assert not item != item + assert str(item) == item.id + assert repr(item) + s.add(item) + + if isinstance(item, base.IndexObject): + num_index_objs += 1 + if hasattr(item,'path'): # never runs here + assert not item.path.startswith("/") # must be relative + assert isinstance(item.mode, int) + # END index object check + # END for each object type to create + + # each has a unique sha + assert len(s) == num_objs + assert num_index_objs == 2 + + + def test_tags(self): + # tag refs can point to tag objects or to commits + s = set() + ref_count = 0 + for ref in chain(self.repo.tags, self.repo.heads): + ref_count += 1 + assert isinstance(ref, base.Ref) + assert str(ref) == ref.name + assert repr(ref) + assert ref == ref + assert not ref != ref + s.add(ref) + # END for each ref + assert len(s) == ref_count + + def test_get_type_by_name(self): + for tname in base.Object.TYPES: + assert base.Object in base.Object.get_type_by_name(tname).mro() + # END for each known type + + assert_raises( ValueError, base.Object.get_type_by_name, "doesntexist" ) + |