diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 14:27:10 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 14:27:10 +0200 |
commit | 3fd37230e76a014cf5c45d55daf0be2caa6948b7 (patch) | |
tree | d94329c8f58e96066895e0e95a8550dfb58e5d0b /test/git/test_config.py | |
parent | 9513aa01fab73f53e4fe18644c7d5b530a66c6a1 (diff) | |
download | gitpython-3fd37230e76a014cf5c45d55daf0be2caa6948b7.tar.gz |
implemented config class as far as necessary, one check is still failing
Added odict module to get an OrderedDict to be used in the config parser, assuring the order of sections and options does not change
Diffstat (limited to 'test/git/test_config.py')
-rw-r--r-- | test/git/test_config.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/git/test_config.py b/test/git/test_config.py index ab08544f..c3080fb0 100644 --- a/test/git/test_config.py +++ b/test/git/test_config.py @@ -6,6 +6,8 @@ from test.testlib import * from git import * +import StringIO +from copy import copy class TestBase(TestCase): @@ -13,6 +15,54 @@ class TestBase(TestCase): 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() + # END for each filename + def test_base(self): - path = fixture_path("git_config") + 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 + + self.fail("TODO: Base config writer testing") |