From 919164df96d9f956c8be712f33a9a037b097745b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 16 Oct 2009 13:05:01 +0200 Subject: repo.untracked_files added including test --- test/git/test_repo.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 96d08b91..250974a5 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -225,3 +225,28 @@ class TestRepo(object): assert_true( tlist ) assert_true( isinstance( tlist[0], basestring ) ) assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug + + def test_untracked_files(self): + base = self.repo.git.git_dir + files = (base+"/__test_myfile", base+"/__test_other_file") + num_recently_untracked = 0 + try: + for fpath in files: + fd = open(fpath,"wb") + fd.close() + # END for each filename + untracked_files = self.repo.untracked_files + num_recently_untracked = len(untracked_files) + + # assure we have all names - they are relative to the git-dir + num_test_untracked = 0 + for utfile in untracked_files: + num_test_untracked += os.path.join(base, utfile) in files + assert len(files) == num_test_untracked + finally: + for fpath in files: + if os.path.isfile(fpath): + os.remove(fpath) + # END handle files + + assert len(self.repo.untracked_files) == (num_recently_untracked - len(files)) -- cgit v1.2.1 From bb24f67e64b4ebe11c4d3ce7df021a6ad7ca98f2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 16 Oct 2009 16:09:07 +0200 Subject: Fixed object bug that would cause object ids not to be resolved to sha's as this was assumed - now there is a test for it as well repo: removed diff and commit_diff methods, added 'head' property returning the current head as Reference object --- test/git/test_repo.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 250974a5..e0bda1c5 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -199,6 +199,9 @@ class TestRepo(object): assert_equal(self.repo.active_branch.name, 'major-refactoring') assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) + def test_head(self): + assert self.repo.head.object == self.repo.active_branch.object + @patch_object(Git, '_call_process') def test_should_display_blame_information(self, git): git.return_value = fixture('blame') -- cgit v1.2.1 From a5cf1bc1d3e38ab32a20707d66b08f1bb0beae91 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 17 Oct 2009 20:13:02 +0200 Subject: Removed a few diff-related test cases that fail now as the respective method is missing - these tests have to be redone in test-diff module accordingly --- test/git/test_repo.py | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index e0bda1c5..87332067 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -43,7 +43,7 @@ class TestRepo(object): git.return_value = ListProcessAdapter(fixture('rev_list')) commits = list( self.repo.iter_commits('master', max_count=10) ) - + c = commits[0] assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents]) @@ -116,40 +116,6 @@ class TestRepo(object): { 'template': '/awesome'})) assert_true(repo.called) - @patch_object(Git, '_call_process') - def test_diff(self, git): - self.repo.diff('master^', 'master') - - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--'), {})) - - self.repo.diff('master^', 'master', 'foo/bar') - - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar'), {})) - - self.repo.diff('master^', 'master', 'foo/bar', 'foo/baz') - - assert_true(git.called) - assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar', 'foo/baz'), {})) - - @patch_object(Git, '_call_process') - def test_diff_with_parents(self, git): - git.return_value = fixture('diff_p') - - diffs = self.repo.commit_diff('master') - assert_equal(15, len(diffs)) - assert_true(git.called) - - def test_archive(self): - args = ( tuple(), (self.repo.heads[-1],),(None,"hello") ) - for arg_list in args: - ftmp = os.tmpfile() - self.repo.archive(ftmp, *arg_list) - ftmp.seek(0,2) - assert ftmp.tell() - # END for each arg-list - @patch('git.utils.touch') def test_enable_daemon_serve(self, touch): self.repo.daemon_serve = False -- cgit v1.2.1 From 9513aa01fab73f53e4fe18644c7d5b530a66c6a1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 18 Oct 2009 23:15:55 +0200 Subject: Added frame for configuration reader involving a meta class, decorators and tests - most of which still has to be filled out --- test/git/test_repo.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 87332067..843a4b4e 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -8,9 +8,11 @@ import os, sys from test.testlib import * from git import * -class TestRepo(object): - def setup(self): - self.repo = Repo(GIT_REPO) +class TestRepo(TestCase): + + @classmethod + def setUpAll(cls): + cls.repo = Repo(GIT_REPO) @raises(InvalidGitRepositoryError) def test_new_should_raise_on_invalid_repo_location(self): @@ -219,3 +221,13 @@ class TestRepo(object): # END handle files assert len(self.repo.untracked_files) == (num_recently_untracked - len(files)) + + def test_config_reader(self): + reader = self.repo.config_reader + assert reader.read_only + + def test_config_writer(self): + for config_level in self.repo.config_level: + writer = self.repo.config_writer(config_level) + assert not writer.read_only + # END for each config level -- cgit v1.2.1 From 26029c29765043376370a2877b7e635c17f5e76d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Oct 2009 15:03:44 +0200 Subject: added additional testing for the configuration, concurrent access and config reading, all tests work --- test/git/test_repo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 843a4b4e..0d8a473d 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -228,6 +228,11 @@ class TestRepo(TestCase): def test_config_writer(self): for config_level in self.repo.config_level: - writer = self.repo.config_writer(config_level) - assert not writer.read_only + try: + writer = self.repo.config_writer(config_level) + assert not writer.read_only + except IOError: + # its okay not to get a writer for some configuration files if we + # have no permissions + pass # END for each config level -- cgit v1.2.1 From 0b3ecf2dcace76b65765ddf1901504b0b4861b08 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Oct 2009 22:49:52 +0200 Subject: commit.count: is an instance method now repo: added head , tag and iter_trees methods for completeness changes: headlines now sorted chronologically --- test/git/test_repo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 0d8a473d..197a29cb 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -67,6 +67,16 @@ class TestRepo(TestCase): assert_true(git.called) + def test_trees(self): + mc = 30 + num_trees = 0 + for tree in self.repo.iter_trees('0.1.5', max_count=mc): + num_trees += 1 + assert isinstance(tree, Tree) + # END for each tree + assert num_trees == mc + + @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') def test_init(self, git, repo): @@ -170,6 +180,9 @@ class TestRepo(TestCase): def test_head(self): assert self.repo.head.object == self.repo.active_branch.object + def test_tag(self): + assert self.repo.tag('0.1.5').commit + @patch_object(Git, '_call_process') def test_should_display_blame_information(self, git): git.return_value = fixture('blame') -- cgit v1.2.1 From 989671780551b7587d57e1d7cb5eb1002ade75b4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Oct 2009 23:44:18 +0200 Subject: Implemneted IterableLists for refs, commits and remote objects including simple tests --- test/git/test_repo.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 197a29cb..f9d81c69 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -39,6 +39,9 @@ class TestRepo(TestCase): assert head.name assert isinstance(head.commit,Commit) # END for each head + + assert isinstance(self.repo.heads.master, Head) + assert isinstance(self.repo.heads['master'], Head) @patch_object(Git, '_call_process') def test_commits(self, git): -- cgit v1.2.1 From e64957d8e52d7542310535bad1e77a9bbd7b4857 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 00:04:10 +0200 Subject: Improved is_dirty including test --- test/git/test_repo.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index f9d81c69..7ad68414 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -160,19 +160,17 @@ class TestRepo(TestCase): self.repo.bare = True assert_false(self.repo.is_dirty) - @patch_object(Git, '_call_process') - def test_is_dirty_with_clean_working_dir(self, git): - self.repo.bare = False - git.return_value = '' - assert_false(self.repo.is_dirty) - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) - - @patch_object(Git, '_call_process') - def test_is_dirty_with_dirty_working_dir(self, git): + def test_is_dirty(self): self.repo.bare = False - git.return_value = '''-aaa\n+bbb''' - assert_true(self.repo.is_dirty) - assert_equal(git.call_args, (('diff', 'HEAD', '--'), {})) + for index in (0,1): + for working_tree in (0,1): + for untracked_files in (0,1): + assert self.repo.is_dirty in (True, False) + # END untracked files + # END working tree + # END index + self.repo.bare = True + assert self.repo.is_dirty == False @patch_object(Git, '_call_process') def test_active_branch(self, git): -- cgit v1.2.1 From aa5e366889103172a9829730de1ba26d3dcbc01b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 10:11:16 +0200 Subject: Moved specialized methods like dashify, touch and is_git_dir to module to the respective modules that use them fixed repo.daemon_export which did not work anymore due to incorrect touch implementation and wrong property names --- test/git/test_repo.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 7ad68414..b91244c9 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -131,14 +131,13 @@ class TestRepo(TestCase): { 'template': '/awesome'})) assert_true(repo.called) - @patch('git.utils.touch') - def test_enable_daemon_serve(self, touch): - self.repo.daemon_serve = False - assert_false(self.repo.daemon_serve) - - def test_disable_daemon_serve(self): - self.repo.daemon_serve = True - assert_true(self.repo.daemon_serve) + + def test_daemon_export(self): + orig_val = self.repo.daemon_export + self.repo.daemon_export = not orig_val + assert self.repo.daemon_export == ( not orig_val ) + self.repo.daemon_export = orig_val + assert self.repo.daemon_export == orig_val @patch_object(os.path, 'exists') def test_alternates_no_file(self, os): -- cgit v1.2.1 From dd76b9e72b21d2502a51e3605e5e6ab640e5f0bd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 10:45:40 +0200 Subject: Fixed bare repository handling - bare is now a property to prevent writing it --- test/git/test_repo.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index b91244c9..c89bcde3 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -91,6 +91,9 @@ class TestRepo(TestCase): assert_true(git.called) assert_true(repo.called) + + def test_bare_property(self): + self.repo.bare @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') @@ -156,11 +159,11 @@ class TestRepo(TestCase): assert_equal('' % path, repr(self.repo)) def test_is_dirty_with_bare_repository(self): - self.repo.bare = True + self.repo._bare = True assert_false(self.repo.is_dirty) def test_is_dirty(self): - self.repo.bare = False + self.repo._bare = False for index in (0,1): for working_tree in (0,1): for untracked_files in (0,1): @@ -168,7 +171,7 @@ class TestRepo(TestCase): # END untracked files # END working tree # END index - self.repo.bare = True + self.repo._bare = True assert self.repo.is_dirty == False @patch_object(Git, '_call_process') @@ -236,7 +239,9 @@ class TestRepo(TestCase): assert len(self.repo.untracked_files) == (num_recently_untracked - len(files)) def test_config_reader(self): - reader = self.repo.config_reader + reader = self.repo.config_reader() # all config files + assert reader.read_only + reader = self.repo.config_reader("repository") # single config file assert reader.read_only def test_config_writer(self): -- cgit v1.2.1 From 35a09c0534e89b2d43ec4101a5fb54576b577905 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 11:17:39 +0200 Subject: repo.alternates test cheked for correctness and bugfixed - totally mocked tests bare the risk that things do not work properly outside of the sandbox. --- test/git/test_repo.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index c89bcde3..bc2c7094 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -142,17 +142,15 @@ class TestRepo(TestCase): self.repo.daemon_export = orig_val assert self.repo.daemon_export == orig_val - @patch_object(os.path, 'exists') - def test_alternates_no_file(self, os): - os.return_value = False - assert_equal([], self.repo.alternates) - - assert_true(os.called) - - @patch_object(os, 'remove') - def test_alternates_setter_empty(self, os): + def test_alternates(self): + cur_alternates = self.repo.alternates + # empty alternates self.repo.alternates = [] - assert_true(os.called) + assert self.repo.alternates == [] + alts = [ "other/location", "this/location" ] + self.repo.alternates = alts + assert alts == self.repo.alternates + self.repo.alternates = cur_alternates def test_repr(self): path = os.path.join(os.path.abspath(GIT_REPO), '.git') -- cgit v1.2.1 From f62c9b9c0c9bda792c3fa531b18190e97eb53509 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 12:24:36 +0200 Subject: Git.cmd: removed with_raw_output option repo.archive: made it work with new way of custom output streams added test for repo.archive which was missing for some reason --- test/git/test_repo.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index bc2c7094..ff10f6a6 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -184,6 +184,11 @@ class TestRepo(TestCase): def test_tag(self): assert self.repo.tag('0.1.5').commit + def test_archive(self): + tmpfile = os.tmpfile() + self.repo.archive(tmpfile, '0.1.5') + assert tmpfile.tell() + @patch_object(Git, '_call_process') def test_should_display_blame_information(self, git): git.return_value = fixture('blame') -- cgit v1.2.1 From b197b2dbb527de9856e6e808339ab0ceaf0a512d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 16:20:24 +0200 Subject: Adjusted all remaining test suites to use the new TestBase class where appropriate --- test/git/test_repo.py | 88 ++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 46 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index ff10f6a6..02eea7de 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -8,11 +8,7 @@ import os, sys from test.testlib import * from git import * -class TestRepo(TestCase): - - @classmethod - def setUpAll(cls): - cls.repo = Repo(GIT_REPO) +class TestRepo(TestBase): @raises(InvalidGitRepositoryError) def test_new_should_raise_on_invalid_repo_location(self): @@ -27,27 +23,27 @@ class TestRepo(TestCase): def test_description(self): txt = "Test repository" - self.repo.description = txt - assert_equal(self.repo.description, txt) + self.rorepo.description = txt + assert_equal(self.rorepo.description, txt) def test_heads_should_return_array_of_head_objects(self): - for head in self.repo.heads: + for head in self.rorepo.heads: assert_equal(Head, head.__class__) def test_heads_should_populate_head_data(self): - for head in self.repo.heads: + for head in self.rorepo.heads: assert head.name assert isinstance(head.commit,Commit) # END for each head - assert isinstance(self.repo.heads.master, Head) - assert isinstance(self.repo.heads['master'], Head) + assert isinstance(self.rorepo.heads.master, Head) + assert isinstance(self.rorepo.heads['master'], Head) @patch_object(Git, '_call_process') def test_commits(self, git): git.return_value = ListProcessAdapter(fixture('rev_list')) - commits = list( self.repo.iter_commits('master', max_count=10) ) + commits = list( self.rorepo.iter_commits('master', max_count=10) ) c = commits[0] assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) @@ -73,7 +69,7 @@ class TestRepo(TestCase): def test_trees(self): mc = 30 num_trees = 0 - for tree in self.repo.iter_trees('0.1.5', max_count=mc): + for tree in self.rorepo.iter_trees('0.1.5', max_count=mc): num_trees += 1 assert isinstance(tree, Tree) # END for each tree @@ -93,7 +89,7 @@ class TestRepo(TestCase): assert_true(repo.called) def test_bare_property(self): - self.repo.bare + self.rorepo.bare @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') @@ -113,7 +109,7 @@ class TestRepo(TestCase): git.return_value = None repo.return_value = None - self.repo.clone("repos/foo/bar.git") + self.rorepo.clone("repos/foo/bar.git") assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') @@ -126,7 +122,7 @@ class TestRepo(TestCase): git.return_value = None repo.return_value = None - self.repo.clone("repos/foo/bar.git", **{'template': '/awesome'}) + self.rorepo.clone("repos/foo/bar.git", **{'template': '/awesome'}) assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') @@ -136,63 +132,63 @@ class TestRepo(TestCase): def test_daemon_export(self): - orig_val = self.repo.daemon_export - self.repo.daemon_export = not orig_val - assert self.repo.daemon_export == ( not orig_val ) - self.repo.daemon_export = orig_val - assert self.repo.daemon_export == orig_val + orig_val = self.rorepo.daemon_export + self.rorepo.daemon_export = not orig_val + assert self.rorepo.daemon_export == ( not orig_val ) + self.rorepo.daemon_export = orig_val + assert self.rorepo.daemon_export == orig_val def test_alternates(self): - cur_alternates = self.repo.alternates + cur_alternates = self.rorepo.alternates # empty alternates - self.repo.alternates = [] - assert self.repo.alternates == [] + self.rorepo.alternates = [] + assert self.rorepo.alternates == [] alts = [ "other/location", "this/location" ] - self.repo.alternates = alts - assert alts == self.repo.alternates - self.repo.alternates = cur_alternates + self.rorepo.alternates = alts + assert alts == self.rorepo.alternates + self.rorepo.alternates = cur_alternates def test_repr(self): path = os.path.join(os.path.abspath(GIT_REPO), '.git') - assert_equal('' % path, repr(self.repo)) + assert_equal('' % path, repr(self.rorepo)) def test_is_dirty_with_bare_repository(self): - self.repo._bare = True - assert_false(self.repo.is_dirty) + self.rorepo._bare = True + assert_false(self.rorepo.is_dirty) def test_is_dirty(self): - self.repo._bare = False + self.rorepo._bare = False for index in (0,1): for working_tree in (0,1): for untracked_files in (0,1): - assert self.repo.is_dirty in (True, False) + assert self.rorepo.is_dirty in (True, False) # END untracked files # END working tree # END index - self.repo._bare = True - assert self.repo.is_dirty == False + self.rorepo._bare = True + assert self.rorepo.is_dirty == False @patch_object(Git, '_call_process') def test_active_branch(self, git): git.return_value = 'refs/heads/major-refactoring' - assert_equal(self.repo.active_branch.name, 'major-refactoring') + assert_equal(self.rorepo.active_branch.name, 'major-refactoring') assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) def test_head(self): - assert self.repo.head.object == self.repo.active_branch.object + assert self.rorepo.head.object == self.rorepo.active_branch.object def test_tag(self): - assert self.repo.tag('0.1.5').commit + assert self.rorepo.tag('0.1.5').commit def test_archive(self): tmpfile = os.tmpfile() - self.repo.archive(tmpfile, '0.1.5') + self.rorepo.archive(tmpfile, '0.1.5') assert tmpfile.tell() @patch_object(Git, '_call_process') def test_should_display_blame_information(self, git): git.return_value = fixture('blame') - b = self.repo.blame( 'master', 'lib/git.py') + b = self.rorepo.blame( 'master', 'lib/git.py') assert_equal(13, len(b)) assert_equal( 2, len(b[0]) ) # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b)) @@ -217,7 +213,7 @@ class TestRepo(TestCase): assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug def test_untracked_files(self): - base = self.repo.git.git_dir + base = self.rorepo.git.git_dir files = (base+"/__test_myfile", base+"/__test_other_file") num_recently_untracked = 0 try: @@ -225,7 +221,7 @@ class TestRepo(TestCase): fd = open(fpath,"wb") fd.close() # END for each filename - untracked_files = self.repo.untracked_files + untracked_files = self.rorepo.untracked_files num_recently_untracked = len(untracked_files) # assure we have all names - they are relative to the git-dir @@ -239,18 +235,18 @@ class TestRepo(TestCase): os.remove(fpath) # END handle files - assert len(self.repo.untracked_files) == (num_recently_untracked - len(files)) + assert len(self.rorepo.untracked_files) == (num_recently_untracked - len(files)) def test_config_reader(self): - reader = self.repo.config_reader() # all config files + reader = self.rorepo.config_reader() # all config files assert reader.read_only - reader = self.repo.config_reader("repository") # single config file + reader = self.rorepo.config_reader("repository") # single config file assert reader.read_only def test_config_writer(self): - for config_level in self.repo.config_level: + for config_level in self.rorepo.config_level: try: - writer = self.repo.config_writer(config_level) + writer = self.rorepo.config_writer(config_level) assert not writer.read_only except IOError: # its okay not to get a writer for some configuration files if we -- cgit v1.2.1 From b7a5c05875a760c0bf83af6617c68061bda6cfc5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 23:31:26 +0200 Subject: Adjusted tests to deal with API changes --- test/git/test_repo.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 02eea7de..b02610f4 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -168,17 +168,11 @@ class TestRepo(TestBase): self.rorepo._bare = True assert self.rorepo.is_dirty == False - @patch_object(Git, '_call_process') - def test_active_branch(self, git): - git.return_value = 'refs/heads/major-refactoring' - assert_equal(self.rorepo.active_branch.name, 'major-refactoring') - assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) - def test_head(self): - assert self.rorepo.head.object == self.rorepo.active_branch.object + assert self.rorepo.head.reference.object == self.rorepo.active_branch.object def test_tag(self): - assert self.rorepo.tag('0.1.5').commit + assert self.rorepo.tag('refs/tags/0.1.5').commit def test_archive(self): tmpfile = os.tmpfile() -- cgit v1.2.1 From 3d3a24b22d340c62fafc0e75a349c0ffe34d99d7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 23 Oct 2009 11:07:04 +0200 Subject: Added repo.index property including simple test, and additional ideas in the TODO list --- test/git/test_repo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index b02610f4..4995d901 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -170,7 +170,11 @@ class TestRepo(TestBase): def test_head(self): assert self.rorepo.head.reference.object == self.rorepo.active_branch.object - + + def test_index(self): + index = self.rorepo.index + assert isinstance(index, IndexFile) + def test_tag(self): assert self.rorepo.tag('refs/tags/0.1.5').commit -- cgit v1.2.1 From 6bca9899b5edeed7f964e3124e382c3573183c68 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 3 Nov 2009 15:20:28 +0100 Subject: repo.is_dirty: is a method now - the property based interface didn't allow all parameters to be used. The test would not test everything either, and I would consider this a bug that slipped through --- test/git/test_repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 4995d901..464cb43f 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -154,19 +154,19 @@ class TestRepo(TestBase): def test_is_dirty_with_bare_repository(self): self.rorepo._bare = True - assert_false(self.rorepo.is_dirty) + assert_false(self.rorepo.is_dirty()) def test_is_dirty(self): self.rorepo._bare = False for index in (0,1): for working_tree in (0,1): for untracked_files in (0,1): - assert self.rorepo.is_dirty in (True, False) + assert self.rorepo.is_dirty(index, working_tree, untracked_files) in (True, False) # END untracked files # END working tree # END index self.rorepo._bare = True - assert self.rorepo.is_dirty == False + assert self.rorepo.is_dirty() == False def test_head(self): assert self.rorepo.head.reference.object == self.rorepo.active_branch.object -- cgit v1.2.1 From dbc18b92362f60afc05d4ddadd6e73902ae27ec7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 3 Nov 2009 15:52:45 +0100 Subject: repo: added create_* and delete_* methods for refs ( head, tag, remote ) as a convenient shortcut to using the classes manually --- test/git/test_repo.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 464cb43f..146cff1a 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -251,3 +251,15 @@ class TestRepo(TestBase): # have no permissions pass # END for each config level + + def test_creation_deletion(self): + # just a very quick test to assure it generally works. There are + # specialized cases in the test_refs module + head = self.rorepo.create_head("new_head", "HEAD~1") + self.rorepo.delete_head(head) + + tag = self.rorepo.create_tag("new_tag", "HEAD~2") + self.rorepo.delete_tag(tag) + + remote = self.rorepo.create_remote("new_remote", "git@server:repo.git") + self.rorepo.delete_remote(remote) -- cgit v1.2.1 From 3cb5ba18ab1a875ef6b62c65342de476be47871b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 3 Nov 2009 16:35:33 +0100 Subject: object: renamed id attribute to sha as it in fact is always being rewritten as sha, even if the passed in id was a ref. This is done to assure objects are uniquely identified and will compare correctly --- test/git/test_repo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 146cff1a..df495e71 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -46,9 +46,9 @@ class TestRepo(TestBase): commits = list( self.rorepo.iter_commits('master', max_count=10) ) c = commits[0] - assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id) - assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents]) - assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id) + assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.sha) + assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.sha for p in c.parents]) + assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.sha) assert_equal("Tom Preston-Werner", c.author.name) assert_equal("tom@mojombo.com", c.author.email) assert_equal(1191999972, c.authored_date) @@ -61,7 +61,7 @@ class TestRepo(TestBase): assert_equal(tuple(), c.parents) c = commits[2] - assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) + assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.sha, c.parents)) assert_equal("Merge branch 'site'", c.summary) assert_true(git.called) @@ -195,7 +195,7 @@ class TestRepo(TestBase): assert_true(git.called) assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id) + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.sha) assert_equal('Tom Preston-Werner', c.author.name) assert_equal('tom@mojombo.com', c.author.email) assert_equal(1191997100, c.authored_date) -- cgit v1.2.1 From f41d42ee7e264ce2fc32cea555e5f666fa1b1fe9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 4 Nov 2009 13:17:37 +0100 Subject: Improved cmd error handling in case an invalid revision is specified for an object repo.tree: improved to be less restricting --- test/git/test_repo.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/git/test_repo.py') diff --git a/test/git/test_repo.py b/test/git/test_repo.py index df495e71..0b196a1f 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -38,6 +38,14 @@ class TestRepo(TestBase): assert isinstance(self.rorepo.heads.master, Head) assert isinstance(self.rorepo.heads['master'], Head) + + def test_tree_from_revision(self): + tree = self.rorepo.tree('0.1.6') + assert tree.type == "tree" + assert self.rorepo.tree(tree) == tree + + # try from invalid revision that does not exist + self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') @patch_object(Git, '_call_process') def test_commits(self, git): -- cgit v1.2.1