summaryrefslogtreecommitdiff
path: root/test/git/test_base.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-11-04 19:53:42 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-11-04 19:53:42 +0100
commitd884adc80c80300b4cc05321494713904ef1df2d (patch)
tree3878d5e0282531596d42505d8725482dde002c20 /test/git/test_base.py
parent05d2687afcc78cd192714ee3d71fdf36a37d110f (diff)
parentace1fed6321bb8dd6d38b2f58d7cf815fa16db7a (diff)
downloadgitpython-d884adc80c80300b4cc05321494713904ef1df2d.tar.gz
Merge branch 'improvements'
Diffstat (limited to 'test/git/test_base.py')
-rw-r--r--test/git/test_base.py76
1 files changed, 39 insertions, 37 deletions
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 04222e2e..497f90fb 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -4,23 +4,23 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from test.testlib import *
-from git import *
import git.objects.base as base
import git.refs as refs
+import os
+
+from test.testlib import *
+from git import *
from itertools import chain
from git.objects.utils import get_object_type_by_name
+import tempfile
-class TestBase(object):
+class TestBase(TestBase):
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
types = (Blob, Tree, Commit, TagObject)
@@ -30,15 +30,15 @@ class TestBase(object):
num_objs = 0
num_index_objs = 0
for obj_type, (typename, hexsha) in zip(types, self.type_tuples):
- item = obj_type(self.repo,hexsha)
+ item = obj_type(self.rorepo,hexsha)
num_objs += 1
- assert item.id == hexsha
+ assert item.sha == hexsha
assert item.type == typename
assert item.size
assert item.data
assert item == item
assert not item != item
- assert str(item) == item.id
+ assert str(item) == item.sha
assert repr(item)
s.add(item)
@@ -48,6 +48,17 @@ class TestBase(object):
assert not item.path.startswith("/") # must be relative
assert isinstance(item.mode, int)
# END index object check
+
+ # read from stream
+ data_stream = item.data_stream
+ data = data_stream.read()
+ assert data
+
+ tmpfile = os.tmpfile()
+ assert item == item.stream_data(tmpfile)
+ tmpfile.seek(0)
+ assert tmpfile.read() == data
+ # END stream to file directly
# END for each object type to create
# each has a unique sha
@@ -55,34 +66,6 @@ class TestBase(object):
assert len(s|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, refs.Reference)
- 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
- 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
- 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):
for tname in base.Object.TYPES:
assert base.Object in get_object_type_by_name(tname).mro()
@@ -90,3 +73,22 @@ class TestBase(object):
assert_raises( ValueError, get_object_type_by_name, "doesntexist" )
+ def test_object_resolution(self):
+ # objects must be resolved to shas so they compare equal
+ assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
+
+ @with_bare_rw_repo
+ def test_with_bare_rw_repo(self, bare_rw_repo):
+ assert bare_rw_repo.config_reader("repository").getboolean("core", "bare")
+ assert os.path.isfile(os.path.join(bare_rw_repo.path,'HEAD'))
+
+ @with_rw_repo('0.1.6')
+ def test_with_rw_repo(self, rw_repo):
+ assert not rw_repo.config_reader("repository").getboolean("core", "bare")
+ assert os.path.isdir(os.path.join(rw_repo.git.git_dir,'lib'))
+
+ @with_rw_and_rw_remote_repo('0.1.6')
+ def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
+ assert not rw_repo.config_reader("repository").getboolean("core", "bare")
+ assert rw_remote_repo.config_reader("repository").getboolean("core", "bare")
+ assert os.path.isdir(os.path.join(rw_repo.git.git_dir,'lib'))