From 9ee31065abea645cbc2cf3e54b691d5983a228b2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 11:01:12 +0200 Subject: 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 --- test/git/test_base.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/git/test_base.py (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py new file mode 100644 index 00000000..46869f63 --- /dev/null +++ b/test/git/test_base.py @@ -0,0 +1,36 @@ +# 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 * + +class TestBase(object): + + type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"), + ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"), + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c") ) + + def setup(self): + self.repo = Repo(GIT_REPO) + + def test_base(self): + # test interface of base classes + fcreators = (self.repo.blob, self.repo.tree, self.repo.commit ) + assert len(fcreators) == len(self.type_tuples) + for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): + item = fcreator(hexsha) + assert item.id == hexsha + assert item.type == typename + assert item.size + # END for each object type to create + + assert False,"TODO: Test for all types" + + def test_tags(self): + # tag refs can point to tag objects or to commits + assert False, "TODO: Tag handling" + -- cgit v1.2.3 From 20f202d83bdf1f332a3cb8f010bcf8bf3c2807bd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 16:36:51 +0200 Subject: 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 --- test/git/test_base.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index 46869f63..787b92b6 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -7,6 +7,7 @@ import time from test.testlib import * from git import * +import git.base as base class TestBase(object): @@ -33,4 +34,11 @@ class TestBase(object): def test_tags(self): # tag refs can point to tag objects or to commits assert False, "TODO: Tag handling" + + 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" ) -- cgit v1.2.3 From c68459a17ff59043d29c90020fffe651b2164e6a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 22:50:07 +0200 Subject: Added remaining tests for new base classes and removed some methods whose existance was doubtful or unsafe --- test/git/test_base.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index 787b92b6..8f522cec 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -8,32 +8,66 @@ 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") ) + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c"), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10") ) def setup(self): self.repo = Repo(GIT_REPO) - def test_base(self): - # test interface of base classes - fcreators = (self.repo.blob, self.repo.tree, self.repo.commit ) + 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) - for fcreator, (typename, hexsha) in zip(fcreators, 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 - assert False,"TODO: Test for all types" + # 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 - assert False, "TODO: Tag handling" + 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: -- cgit v1.2.3 From f2834177c0fdf6b1af659e460fd3348f468b8ab0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 11:50:14 +0200 Subject: Reorganized package structure and cleaned up imports --- test/git/test_base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index 8f522cec..a153eb83 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -7,8 +7,10 @@ import time from test.testlib import * from git import * -import git.base as base +import git.objects.base as base +import git.refs as refs from itertools import chain +from git.objects.util import get_object_type_by_name class TestBase(object): @@ -60,7 +62,7 @@ class TestBase(object): ref_count = 0 for ref in chain(self.repo.tags, self.repo.heads): ref_count += 1 - assert isinstance(ref, base.Ref) + assert isinstance(ref, refs.Ref) assert str(ref) == ref.name assert repr(ref) assert ref == ref @@ -69,10 +71,10 @@ class TestBase(object): # END for each ref assert len(s) == ref_count - def test_get_type_by_name(self): + def test_get_object_type_by_name(self): for tname in base.Object.TYPES: - assert base.Object in base.Object.get_type_by_name(tname).mro() + assert base.Object in get_object_type_by_name(tname).mro() # END for each known type - assert_raises( ValueError, base.Object.get_type_by_name, "doesntexist" ) + assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) -- cgit v1.2.3 From ff3d142387e1f38b0ed390333ea99e2e23d96e35 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Oct 2009 18:02:07 +0200 Subject: test_base: Improved basic object creation as well as set hash tests --- test/git/test_base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index a153eb83..aff0947d 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -24,14 +24,14 @@ class TestBase(object): 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) + types = (Blob, Tree, Commit, TagObject) + assert len(types) == 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) + for obj_type, (typename, hexsha) in zip(types, self.type_tuples): + item = obj_type(self.repo,hexsha) num_objs += 1 assert item.id == hexsha assert item.type == typename @@ -53,6 +53,7 @@ class TestBase(object): # each has a unique sha assert len(s) == num_objs + assert len(s|s) == num_objs assert num_index_objs == 2 @@ -70,6 +71,7 @@ class TestBase(object): s.add(ref) # END for each ref assert len(s) == ref_count + assert len(s|s) == ref_count def test_get_object_type_by_name(self): for tname in base.Object.TYPES: -- cgit v1.2.3 From 5eb0f2c241718bc7462be44e5e8e1e36e35f9b15 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 13 Oct 2009 17:50:26 +0200 Subject: unified name of utils module, recently it was named util and utils in different packages --- test/git/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index aff0947d..97dfc255 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -10,7 +10,7 @@ from git import * import git.objects.base as base import git.refs as refs from itertools import chain -from git.objects.util import get_object_type_by_name +from git.objects.utils import get_object_type_by_name class TestBase(object): -- cgit v1.2.3 From 6745f4542cfb74bbf3b933dba7a59ef2f54a4380 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 19:34:45 +0200 Subject: test_blob: removed many redundant tests that would fail now as the mock cannot handle the complexity of the command backend All objects but Tree now use the persistent command to read their object information - Trees get binary data and would need their own pretty-printing or they need to parse the data themselves which is my favorite --- test/git/test_base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index 97dfc255..6e3aad7f 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -73,6 +73,16 @@ class TestBase(object): assert len(s) == ref_count assert len(s|s) == ref_count + def test_heads(self): + # see how it dynmically updates its object + for head in self.repo.heads: + head.name + head.path + cur_obj = head.object + del( head.object ) + assert cur_obj == head.object + # END for each head + def test_get_object_type_by_name(self): for tname in base.Object.TYPES: assert base.Object in get_object_type_by_name(tname).mro() -- cgit v1.2.3 From 832b56394b079c9f6e4c777934447a9e224facfe Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 14 Oct 2009 19:46:24 +0200 Subject: Refs are now truly dynamic - this costs a little bit of (persistent command) work, but assures refs behave as expected --- test/git/test_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/git/test_base.py') diff --git a/test/git/test_base.py b/test/git/test_base.py index 6e3aad7f..402cdba3 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -78,9 +78,10 @@ class TestBase(object): for head in self.repo.heads: head.name head.path - cur_obj = head.object - del( head.object ) - assert cur_obj == head.object + prev_object = head.object + cur_object = head.object + assert prev_object == cur_object # represent the same git object + assert prev_object is not cur_object # but are different instances # END for each head def test_get_object_type_by_name(self): -- cgit v1.2.3