diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/diff_new_mode | 2 | ||||
-rw-r--r-- | test/git/test_base.py | 164 | ||||
-rw-r--r-- | test/git/test_blob.py | 10 | ||||
-rw-r--r-- | test/git/test_commit.py | 35 | ||||
-rw-r--r-- | test/git/test_fun.py | 25 | ||||
-rw-r--r-- | test/git/test_index.py | 6 | ||||
-rw-r--r-- | test/git/test_remote.py | 1 | ||||
-rw-r--r-- | test/git/test_repo.py | 10 | ||||
-rw-r--r-- | test/git/test_tree.py | 10 | ||||
-rw-r--r-- | test/testlib/helper.py | 15 |
10 files changed, 144 insertions, 134 deletions
diff --git a/test/fixtures/diff_new_mode b/test/fixtures/diff_new_mode index 663c9099..29705386 100644 --- a/test/fixtures/diff_new_mode +++ b/test/fixtures/diff_new_mode @@ -1,7 +1,7 @@ diff --git a/conf/global_settings.py b/conf/global_settings.py old mode 100644 new mode 100755 -index 9ec1bac..1c4f83b +index 9ec1bac000000000000000000000000000000000..1c4f83b000000000000000000000000000000000 --- a/conf/global_settings.py +++ b/conf/global_settings.py @@ -58,6 +58,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/test/git/test_base.py b/test/git/test_base.py index 81931ad0..1b01cda3 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -12,87 +12,91 @@ from test.testlib import * from git import * from itertools import chain from git.objects.utils import get_object_type_by_name +from gitdb.util import hex_to_bin import tempfile class TestBase(TestBase): - - type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070", "blob.py"), - ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79", "directory"), - ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c", None), - ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10", None) ) - - def test_base_object(self): - # test interface of base object classes - types = (Blob, Tree, Commit, TagObject) - assert len(types) == len(self.type_tuples) - - s = set() - num_objs = 0 - num_index_objs = 0 - for obj_type, (typename, hexsha, path) in zip(types, self.type_tuples): - item = None - if path is None: - item = obj_type(self.rorepo,hexsha) - else: - item = obj_type(self.rorepo,hexsha, 0, path) - num_objs += 1 - 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.sha - 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 - - # 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 - assert len(s) == num_objs - assert len(s|s) == num_objs - assert num_index_objs == 2 - - 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() - # END for each known type - - assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) + + type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070", "blob.py"), + ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79", "directory"), + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c", None), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10", None) ) + + def test_base_object(self): + # test interface of base object classes + types = (Blob, Tree, Commit, TagObject) + assert len(types) == len(self.type_tuples) + + s = set() + num_objs = 0 + num_index_objs = 0 + for obj_type, (typename, hexsha, path) in zip(types, self.type_tuples): + binsha = hex_to_bin(hexsha) + item = None + if path is None: + item = obj_type(self.rorepo,binsha) + else: + item = obj_type(self.rorepo,binsha, 0, path) + # END handle index objects + num_objs += 1 + assert item.hexsha == hexsha + assert item.type == typename + assert item.size + if isinstance(item, Blob): + assert item.data + assert item == item + assert not item != item + assert str(item) == item.hexsha + 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 + + # 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 + assert len(s) == num_objs + assert len(s|s) == num_objs + assert num_index_objs == 2 + + 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() + # END for each known type + + 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.git_dir,'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.working_tree_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.working_tree_dir,'lib')) + 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.git_dir,'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.working_tree_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.working_tree_dir,'lib')) diff --git a/test/git/test_blob.py b/test/git/test_blob.py index cf70cb8c..e5fca0a6 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -6,25 +6,23 @@ from test.testlib import * from git import * +from gitdb.util import hex_to_bin class TestBlob(TestBase): def test_should_cache_data(self): bid = 'a802c139d4767c89dcad79d836d05f7004d39aac' - blob = Blob(self.rorepo, bid) + blob = Blob(self.rorepo, hex_to_bin(bid)) blob.data assert blob.data blob.size blob.size def test_mime_type_should_return_mime_type_for_known_types(self): - blob = Blob(self.rorepo, **{'sha': 'abc', 'path': 'foo.png'}) + blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA, 'path': 'foo.png'}) assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): - blob = Blob(self.rorepo, **{'sha': 'abc','path': 'something'}) + blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA,'path': 'something'}) assert_equal("text/plain", blob.mime_type) - def test_should_return_appropriate_representation(self): - blob = Blob(self.rorepo, **{'sha': 'abc'}) - assert_equal('<git.Blob "abc">', repr(blob)) diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 8629e625..31ce2c4e 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -7,6 +7,7 @@ from test.testlib import * from git import * from gitdb import IStream +from gitdb.util import hex_to_bin from cStringIO import StringIO import time @@ -33,9 +34,9 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False) stream.seek(0) istream = rwrepo.odb.store(IStream(Commit.type, streamlen, stream)) - assert istream.sha == cm.sha + assert istream.hexsha == cm.hexsha - nc = Commit(rwrepo, Commit.NULL_HEX_SHA, cm.tree.sha, + nc = Commit(rwrepo, Commit.NULL_BIN_SHA, cm.tree, cm.author, cm.authored_date, cm.author_tz_offset, cm.committer, cm.committed_date, cm.committer_tz_offset, cm.message, cm.parents, cm.encoding) @@ -50,11 +51,11 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False) # reuse istream istream.size = streamlen istream.stream = stream - istream.sha = None - nc.sha = rwrepo.odb.store(istream).sha + istream.binsha = None + nc.binsha = rwrepo.odb.store(istream).binsha # if it worked, we have exactly the same contents ! - assert nc.sha == cm.sha + assert nc.hexsha == cm.hexsha # END check commits elapsed = time.time() - st @@ -67,7 +68,7 @@ class TestCommit(TestBase): def test_bake(self): - commit = Commit(self.rorepo, '2454ae89983a4496a445ce347d7a41c0bb0ea7ae') + commit = self.rorepo.commit('2454ae89983a4496a445ce347d7a41c0bb0ea7ae') commit.author # bake assert_equal("Sebastian Thiel", commit.author.name) @@ -79,7 +80,7 @@ class TestCommit(TestBase): def test_stats(self): - commit = Commit(self.rorepo, '33ebe7acec14b25c5f84f35a664803fcab2f7781') + commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') stats = commit.stats def check_entries(d): @@ -158,7 +159,7 @@ class TestCommit(TestBase): assert all_commits == list(self.rorepo.iter_commits()) # this includes merge commits - mcomit = Commit(self.rorepo, 'd884adc80c80300b4cc05321494713904ef1df2d') + mcomit = self.rorepo.commit('d884adc80c80300b4cc05321494713904ef1df2d') assert mcomit in all_commits # we can limit the result to paths @@ -190,26 +191,26 @@ class TestCommit(TestBase): '933d23bf95a5bd1624fbcdf328d904e1fa173474' ) for sha1, commit in zip(expected_ids, commits): - assert_equal(sha1, commit.sha) + assert_equal(sha1, commit.hexsha) def test_count(self): assert self.rorepo.tag('refs/tags/0.1.5').commit.count( ) == 143 def test_list(self): - assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)['5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit) + assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)[hex_to_bin('5117c9c8a4d3af19a9958677e45cda9269de1541')], Commit) def test_str(self): - commit = Commit(self.rorepo, 'abc') - assert_equal ("abc", str(commit)) + commit = Commit(self.rorepo, Commit.NULL_BIN_SHA) + assert_equal(Commit.NULL_HEX_SHA, str(commit)) def test_repr(self): - commit = Commit(self.rorepo, 'abc') - assert_equal('<git.Commit "abc">', repr(commit)) + commit = Commit(self.rorepo, Commit.NULL_BIN_SHA) + assert_equal('<git.Commit "%s">' % Commit.NULL_HEX_SHA, repr(commit)) def test_equality(self): - commit1 = Commit(self.rorepo, 'abc') - commit2 = Commit(self.rorepo, 'abc') - commit3 = Commit(self.rorepo, 'zyx') + commit1 = Commit(self.rorepo, Commit.NULL_BIN_SHA) + commit2 = Commit(self.rorepo, Commit.NULL_BIN_SHA) + commit3 = Commit(self.rorepo, "\1"*20) assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) diff --git a/test/git/test_fun.py b/test/git/test_fun.py index dad9fcda..3fdc13fd 100644 --- a/test/git/test_fun.py +++ b/test/git/test_fun.py @@ -9,6 +9,7 @@ from git.index.fun import ( aggressive_tree_merge ) +from gitdb.util import bin_to_hex from gitdb.base import IStream from gitdb.typ import str_tree_type @@ -24,7 +25,7 @@ from cStringIO import StringIO class TestFun(TestBase): def _assert_index_entries(self, entries, trees): - index = IndexFile.from_tree(self.rorepo, *trees) + index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t)) for t in trees]) assert entries assert len(index.entries) == len(entries) for entry in entries: @@ -39,11 +40,11 @@ class TestFun(TestBase): B = HC.parents[0].tree # entries from single tree - trees = [H.sha] + trees = [H.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # from multiple trees - trees = [B.sha, H.sha] + trees = [B.binsha, H.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # three way, no conflict @@ -51,14 +52,14 @@ class TestFun(TestBase): B = tree("35a09c0534e89b2d43ec4101a5fb54576b577905") H = tree("4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4") M = tree("1f2b19de3301e76ab3a6187a49c9c93ff78bafbd") - trees = [B.sha, H.sha, M.sha] + trees = [B.binsha, H.binsha, M.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # three-way, conflict in at least one file, both modified B = tree("a7a4388eeaa4b6b94192dce67257a34c4a6cbd26") H = tree("f9cec00938d9059882bb8eabdaf2f775943e00e5") M = tree("44a601a068f4f543f73fd9c49e264c931b1e1652") - trees = [B.sha, H.sha, M.sha] + trees = [B.binsha, H.binsha, M.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # too many trees @@ -70,7 +71,7 @@ class TestFun(TestBase): tree_to_stream(entries, sio.write) sio.seek(0) istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) - return istream.sha + return istream.binsha @with_rw_repo('0.1.6') def test_three_way_merge(self, rwrepo): @@ -216,25 +217,25 @@ class TestFun(TestBase): B_old = self.rorepo.tree('1f66cfbbce58b4b552b041707a12d437cc5f400a') # old base tree # two very different trees - entries = traverse_trees_recursive(odb, [B_old.sha, H.sha], '') + entries = traverse_trees_recursive(odb, [B_old.binsha, H.binsha], '') self._assert_tree_entries(entries, 2) - oentries = traverse_trees_recursive(odb, [H.sha, B_old.sha], '') + oentries = traverse_trees_recursive(odb, [H.binsha, B_old.binsha], '') assert len(oentries) == len(entries) self._assert_tree_entries(oentries, 2) # single tree is_no_tree = lambda i, d: i.type != 'tree' - entries = traverse_trees_recursive(odb, [B.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha], '') assert len(entries) == len(list(B.traverse(predicate=is_no_tree))) self._assert_tree_entries(entries, 1) # two trees - entries = traverse_trees_recursive(odb, [B.sha, H.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha, H.binsha], '') self._assert_tree_entries(entries, 2) # tree trees - entries = traverse_trees_recursive(odb, [B.sha, H.sha, M.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha, H.binsha, M.binsha], '') self._assert_tree_entries(entries, 3) def test_tree_traversal_single(self): @@ -245,6 +246,6 @@ class TestFun(TestBase): if count >= max_count: break count += 1 - entries = traverse_tree_recursive(odb, commit.tree.sha, '') + entries = traverse_tree_recursive(odb, commit.tree.binsha, '') assert entries # END for each commit diff --git a/test/git/test_index.py b/test/git/test_index.py index e9f99f04..705d8029 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -354,7 +354,7 @@ class TestIndex(TestBase): if type_id == 0: # path yield entry.path elif type_id == 1: # blob - yield Blob(rw_repo, entry.hexsha, entry.mode, entry.path) + yield Blob(rw_repo, entry.binsha, entry.mode, entry.path) elif type_id == 2: # BaseIndexEntry yield BaseIndexEntry(entry[:4]) elif type_id == 3: # IndexEntry @@ -449,7 +449,7 @@ class TestIndex(TestBase): old_blob = new_commit.parents[0].tree.blobs[0] entries = index.reset(new_commit).add([old_blob], fprogress=self._fprogress_add) self._assert_fprogress(entries) - assert index.entries[(old_blob.path,0)].hexsha == old_blob.sha and len(entries) == 1 + assert index.entries[(old_blob.path,0)].hexsha == old_blob.hexsha and len(entries) == 1 # mode 0 not allowed null_hex_sha = Diff.NULL_HEX_SHA @@ -567,7 +567,7 @@ class TestIndex(TestBase): for fid in range(3): fname = 'newfile%i' % fid open(fname, 'wb').write("abcd") - yield Blob(rw_repo, Blob.NULL_HEX_SHA, 0100644, fname) + yield Blob(rw_repo, Blob.NULL_BIN_SHA, 0100644, fname) # END for each new file # END path producer paths = list(make_paths()) diff --git a/test/git/test_remote.py b/test/git/test_remote.py index 58fad308..9d4da034 100644 --- a/test/git/test_remote.py +++ b/test/git/test_remote.py @@ -6,6 +6,7 @@ from test.testlib import * from git import * +from git.utils import IterableList import tempfile import shutil import os diff --git a/test/git/test_repo.py b/test/git/test_repo.py index d2c7c742..a3ff564d 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -49,7 +49,7 @@ class TestRepo(TestBase): def test_tree_from_revision(self): tree = self.rorepo.tree('0.1.6') - assert len(tree.sha) == 40 + assert len(tree.hexsha) == 40 assert tree.type == "tree" assert self.rorepo.tree(tree) == tree @@ -62,9 +62,9 @@ class TestRepo(TestBase): assert len(commits) == mc c = commits[0] - assert_equal('9a4b1d4d11eee3c5362a4152216376e634bd14cf', c.sha) - assert_equal(["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.sha for p in c.parents]) - assert_equal("ce41fc29549042f1aa09cc03174896cf23f112e3", c.tree.sha) + assert_equal('9a4b1d4d11eee3c5362a4152216376e634bd14cf', c.hexsha) + assert_equal(["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.hexsha for p in c.parents]) + assert_equal("ce41fc29549042f1aa09cc03174896cf23f112e3", c.tree.hexsha) assert_equal("Michael Trier", c.author.name) assert_equal("mtrier@gmail.com", c.author.email) assert_equal(1232829715, c.authored_date) @@ -255,7 +255,7 @@ class TestRepo(TestBase): assert_true(git.called) assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.sha) + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.hexsha) assert_equal('Tom Preston-Werner', c.author.name) assert_equal('tom@mojombo.com', c.author.email) assert_equal(1191997100, c.authored_date) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index a443bd97..d08999bd 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -23,7 +23,7 @@ class TestTree(TestBase): continue # END skip non-trees tree = item - orig_data = tree.data + orig_data = tree.data_stream.read() orig_cache = tree._cache stream = StringIO() @@ -31,7 +31,7 @@ class TestTree(TestBase): assert stream.getvalue() == orig_data stream.seek(0) - testtree = Tree(self.rorepo, Tree.NULL_HEX_SHA, 0, '') + testtree = Tree(self.rorepo, Tree.NULL_BIN_SHA, 0, '') testtree._deserialize(stream) assert testtree._cache == orig_cache @@ -61,7 +61,7 @@ class TestTree(TestBase): # force it - replace existing one mod.add(hexsha, tree.mode, name, force=True) - assert testtree[name].sha == hexsha + assert testtree[name].hexsha == hexsha assert len(testtree) == cur_count # unchecked addition always works, even with invalid items @@ -137,7 +137,3 @@ class TestTree(TestBase): # END for each item assert found_slash - def test_repr(self): - tree = Tree(self.rorepo, 'abc') - assert_equal('<git.Tree "abc">', repr(tree)) - diff --git a/test/testlib/helper.py b/test/testlib/helper.py index 4399561c..0bfdfa69 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -74,10 +74,19 @@ def with_bare_rw_repo(func): rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=True) prev_cwd = os.getcwd() try: - return func(self, rw_repo) + try: + return func(self, rw_repo) + except: + # assure we keep the repo for debugging + print >> sys.stderr, "Keeping bare repo after failure: %s" % repo_dir + repo_dir = None + raise + # END handle exceptions finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + if repo_dir is not None: + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + # END remove repo dir # END cleanup # END bare repo creator bare_repo_creator.__name__ = func.__name__ @@ -99,7 +108,7 @@ def with_rw_repo(working_tree_ref): repo_dir = tempfile.mktemp("non_bare_%s" % func.__name__) rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=False, n=True) - rw_repo.head.commit = working_tree_ref + rw_repo.head.commit = rw_repo.commit(working_tree_ref) rw_repo.head.reference.checkout() prev_cwd = os.getcwd() |