summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/git_config23
-rw-r--r--test/fixtures/git_config_global24
-rw-r--r--test/git/test_config.py89
-rw-r--r--test/git/test_repo.py23
4 files changed, 156 insertions, 3 deletions
diff --git a/test/fixtures/git_config b/test/fixtures/git_config
new file mode 100644
index 00000000..3c91985f
--- /dev/null
+++ b/test/fixtures/git_config
@@ -0,0 +1,23 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+[remote "origin"]
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ url = git://gitorious.org/~byron/git-python/byrons-clone.git
+ pushurl = git@gitorious.org:~byron/git-python/byrons-clone.git
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
+[remote "mainline"]
+ url = git://gitorious.org/git-python/mainline.git
+ fetch = +refs/heads/*:refs/remotes/mainline/*
+[remote "MartinMarcher"]
+ url = git://gitorious.org/~martin.marcher/git-python/serverhorror.git
+ fetch = +refs/heads/*:refs/remotes/MartinMarcher/*
+[gui]
+ geometry = 1316x820+219+243 207 192
+[branch "mainline_performance"]
+ remote = mainline
+ merge = refs/heads/master
diff --git a/test/fixtures/git_config_global b/test/fixtures/git_config_global
new file mode 100644
index 00000000..1a55397f
--- /dev/null
+++ b/test/fixtures/git_config_global
@@ -0,0 +1,24 @@
+[alias]
+ st = status
+ ci = commit
+ co = checkout
+ br = branch
+[color]
+ branch = auto
+ diff = auto
+ interactive = auto
+ status = auto
+[user]
+ name = Sebastian Thiel
+ email = byronimo@gmail.com
+[core]
+ editor = vim
+ autocrlf = false
+ packedGitLimit = 1g
+ packedGitWindowSize = 512m
+[pack]
+ windowMemory = 512m
+[merge]
+ tool = meld
+[diff]
+ tool = meld
diff --git a/test/git/test_config.py b/test/git/test_config.py
new file mode 100644
index 00000000..c5a8dc2c
--- /dev/null
+++ b/test/git/test_config.py
@@ -0,0 +1,89 @@
+# test_config.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
+
+from test.testlib import *
+from git import *
+import StringIO
+from copy import copy
+
+class TestBase(TestCase):
+
+ @classmethod
+ def setUpAll(cls):
+ cls.repo = Repo(GIT_REPO)
+
+ def _to_memcache(self, file_path):
+ fp = open(file_path, "r")
+ sio = StringIO.StringIO()
+ sio.write(fp.read())
+ sio.seek(0)
+ sio.name = file_path
+ return sio
+
+ def _parsers_equal_or_raise(self, lhs, rhs):
+ pass
+
+ def test_read_write(self):
+ # writer must create the exact same file as the one read before
+ for filename in ("git_config", "git_config_global"):
+ file_obj = self._to_memcache(fixture_path(filename))
+ file_obj_orig = copy(file_obj)
+ w_config = GitConfigParser(file_obj, read_only = False)
+ w_config.read() # enforce reading
+ assert w_config._sections
+ w_config.write() # enforce writing
+ assert file_obj.getvalue() == file_obj_orig.getvalue()
+
+ # creating an additional config writer must fail due to exclusive access
+ self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only = False)
+
+ # should still have a lock and be able to make changes
+ assert w_config._has_lock()
+
+ # changes should be written right away
+ sname = "my_section"
+ oname = "mykey"
+ val = "myvalue"
+ w_config.add_section(sname)
+ assert w_config.has_section(sname)
+ w_config.set(sname, oname, val)
+ assert w_config.has_option(sname,oname)
+ assert w_config.get(sname, oname) == val
+
+ file_obj.seek(0)
+ r_config = GitConfigParser(file_obj, read_only=True)
+ assert r_config.has_section(sname)
+ assert r_config.has_option(sname, oname)
+ assert r_config.get(sname, oname) == val
+
+ # END for each filename
+
+ def test_base(self):
+ path_repo = fixture_path("git_config")
+ path_global = fixture_path("git_config_global")
+ r_config = GitConfigParser([path_repo, path_global], read_only=True)
+ assert r_config.read_only
+ num_sections = 0
+ num_options = 0
+
+ # test reader methods
+ assert r_config._is_initialized == False
+ for section in r_config.sections():
+ num_sections += 1
+ for option in r_config.options(section):
+ num_options += 1
+ val = r_config.get(section, option)
+ assert val
+
+ # writing must fail
+ self.failUnlessRaises(IOError, r_config.set, section, option, None)
+ self.failUnlessRaises(IOError, r_config.remove_option, section, option )
+ # END for each option
+ self.failUnlessRaises(IOError, r_config.remove_section, section)
+ # END for each section
+ assert num_sections and num_options
+ assert r_config._is_initialized == True
+
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 87332067..0d8a473d 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,18 @@ 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:
+ 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