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_config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/git/test_config.py (limited to 'test/git/test_config.py') diff --git a/test/git/test_config.py b/test/git/test_config.py new file mode 100644 index 00000000..ab08544f --- /dev/null +++ b/test/git/test_config.py @@ -0,0 +1,18 @@ +# 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 * + +class TestBase(TestCase): + + @classmethod + def setUpAll(cls): + cls.repo = Repo(GIT_REPO) + + def test_base(self): + path = fixture_path("git_config") + self.fail("TODO: Base config writer testing") -- cgit v1.2.3 From 3fd37230e76a014cf5c45d55daf0be2caa6948b7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Oct 2009 14:27:10 +0200 Subject: 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 --- test/git/test_config.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'test/git/test_config.py') 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") -- cgit v1.2.3 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_config.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'test/git/test_config.py') diff --git a/test/git/test_config.py b/test/git/test_config.py index c3080fb0..c5a8dc2c 100644 --- a/test/git/test_config.py +++ b/test/git/test_config.py @@ -36,6 +36,29 @@ class TestBase(TestCase): 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): @@ -64,5 +87,3 @@ class TestBase(TestCase): assert num_sections and num_options assert r_config._is_initialized == True - - self.fail("TODO: Base config writer testing") -- cgit v1.2.3 From 345d6be7829c6dab359390ebc5e1a7ae0c6d48bb Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Oct 2009 20:17:36 +0200 Subject: config: fixed serious issues that would cause it to see initial tabs as continuation lines - this leads to very incorrect results when parsing git config files. Now the complete reading is overridden to make it work as there was no other way --- test/git/test_config.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/git/test_config.py') diff --git a/test/git/test_config.py b/test/git/test_config.py index c5a8dc2c..843da723 100644 --- a/test/git/test_config.py +++ b/test/git/test_config.py @@ -77,6 +77,8 @@ class TestBase(TestCase): num_options += 1 val = r_config.get(section, option) assert val + assert "\n" not in option + assert "\n" not in val # writing must fail self.failUnlessRaises(IOError, r_config.set, section, option, None) -- cgit v1.2.3 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_config.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/git/test_config.py') diff --git a/test/git/test_config.py b/test/git/test_config.py index 843da723..c2909b8f 100644 --- a/test/git/test_config.py +++ b/test/git/test_config.py @@ -11,10 +11,6 @@ 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() -- cgit v1.2.3