summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/fixtures/git_config_multiple7
-rw-r--r--git/test/test_config.py109
-rw-r--r--git/test/test_remote.py2
-rw-r--r--git/test/test_repo.py16
-rw-r--r--git/test/test_util.py6
5 files changed, 138 insertions, 2 deletions
diff --git a/git/test/fixtures/git_config_multiple b/git/test/fixtures/git_config_multiple
new file mode 100644
index 00000000..03a97568
--- /dev/null
+++ b/git/test/fixtures/git_config_multiple
@@ -0,0 +1,7 @@
+[section0]
+ option0 = value0
+
+[section1]
+ option1 = value1a
+ option1 = value1b
+ other_option1 = other_value1
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 4d6c8236..93f94748 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -11,7 +11,7 @@ from git import (
GitConfigParser
)
from git.compat import string_types
-from git.config import cp
+from git.config import _OMD, cp
from git.test.lib import (
TestCase,
fixture_path,
@@ -265,3 +265,110 @@ class TestBase(TestCase):
with self.assertRaises(cp.NoOptionError):
cr.get_value('color', 'ui')
+
+ def test_multiple_values(self):
+ file_obj = self._to_memcache(fixture_path('git_config_multiple'))
+ with GitConfigParser(file_obj, read_only=False) as cw:
+ self.assertEqual(cw.get('section0', 'option0'), 'value0')
+ self.assertEqual(cw.get_values('section0', 'option0'), ['value0'])
+ self.assertEqual(cw.items('section0'), [('option0', 'value0')])
+
+ # Where there are multiple values, "get" returns the last.
+ self.assertEqual(cw.get('section1', 'option1'), 'value1b')
+ self.assertEqual(cw.get_values('section1', 'option1'),
+ ['value1a', 'value1b'])
+ self.assertEqual(cw.items('section1'),
+ [('option1', 'value1b'),
+ ('other_option1', 'other_value1')])
+ self.assertEqual(cw.items_all('section1'),
+ [('option1', ['value1a', 'value1b']),
+ ('other_option1', ['other_value1'])])
+ with self.assertRaises(KeyError):
+ cw.get_values('section1', 'missing')
+
+ self.assertEqual(cw.get_values('section1', 'missing', 1), [1])
+ self.assertEqual(cw.get_values('section1', 'missing', 's'), ['s'])
+
+ def test_multiple_values_rename(self):
+ file_obj = self._to_memcache(fixture_path('git_config_multiple'))
+ with GitConfigParser(file_obj, read_only=False) as cw:
+ cw.rename_section('section1', 'section2')
+ cw.write()
+ file_obj.seek(0)
+ cr = GitConfigParser(file_obj, read_only=True)
+ self.assertEqual(cr.get_value('section2', 'option1'), 'value1b')
+ self.assertEqual(cr.get_values('section2', 'option1'),
+ ['value1a', 'value1b'])
+ self.assertEqual(cr.items('section2'),
+ [('option1', 'value1b'),
+ ('other_option1', 'other_value1')])
+ self.assertEqual(cr.items_all('section2'),
+ [('option1', ['value1a', 'value1b']),
+ ('other_option1', ['other_value1'])])
+
+ def test_multiple_to_single(self):
+ file_obj = self._to_memcache(fixture_path('git_config_multiple'))
+ with GitConfigParser(file_obj, read_only=False) as cw:
+ cw.set_value('section1', 'option1', 'value1c')
+
+ cw.write()
+ file_obj.seek(0)
+ cr = GitConfigParser(file_obj, read_only=True)
+ self.assertEqual(cr.get_value('section1', 'option1'), 'value1c')
+ self.assertEqual(cr.get_values('section1', 'option1'), ['value1c'])
+ self.assertEqual(cr.items('section1'),
+ [('option1', 'value1c'),
+ ('other_option1', 'other_value1')])
+ self.assertEqual(cr.items_all('section1'),
+ [('option1', ['value1c']),
+ ('other_option1', ['other_value1'])])
+
+ def test_single_to_multiple(self):
+ file_obj = self._to_memcache(fixture_path('git_config_multiple'))
+ with GitConfigParser(file_obj, read_only=False) as cw:
+ cw.add_value('section1', 'other_option1', 'other_value1a')
+
+ cw.write()
+ file_obj.seek(0)
+ cr = GitConfigParser(file_obj, read_only=True)
+ self.assertEqual(cr.get_value('section1', 'option1'), 'value1b')
+ self.assertEqual(cr.get_values('section1', 'option1'),
+ ['value1a', 'value1b'])
+ self.assertEqual(cr.get_value('section1', 'other_option1'),
+ 'other_value1a')
+ self.assertEqual(cr.get_values('section1', 'other_option1'),
+ ['other_value1', 'other_value1a'])
+ self.assertEqual(cr.items('section1'),
+ [('option1', 'value1b'),
+ ('other_option1', 'other_value1a')])
+ self.assertEqual(
+ cr.items_all('section1'),
+ [('option1', ['value1a', 'value1b']),
+ ('other_option1', ['other_value1', 'other_value1a'])])
+
+ def test_add_to_multiple(self):
+ file_obj = self._to_memcache(fixture_path('git_config_multiple'))
+ with GitConfigParser(file_obj, read_only=False) as cw:
+ cw.add_value('section1', 'option1', 'value1c')
+ cw.write()
+ file_obj.seek(0)
+ cr = GitConfigParser(file_obj, read_only=True)
+ self.assertEqual(cr.get_value('section1', 'option1'), 'value1c')
+ self.assertEqual(cr.get_values('section1', 'option1'),
+ ['value1a', 'value1b', 'value1c'])
+ self.assertEqual(cr.items('section1'),
+ [('option1', 'value1c'),
+ ('other_option1', 'other_value1')])
+ self.assertEqual(cr.items_all('section1'),
+ [('option1', ['value1a', 'value1b', 'value1c']),
+ ('other_option1', ['other_value1'])])
+
+ def test_setlast(self):
+ # Test directly, not covered by higher-level tests.
+ omd = _OMD()
+ omd.setlast('key', 'value1')
+ self.assertEqual(omd['key'], 'value1')
+ self.assertEqual(omd.getall('key'), ['value1'])
+ omd.setlast('key', 'value2')
+ self.assertEqual(omd['key'], 'value2')
+ self.assertEqual(omd.getall('key'), ['value2'])
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index f3a214cb..99949b9e 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -638,7 +638,7 @@ class TestRemote(TestBase):
def test_fetch_error(self):
rem = self.rorepo.remote('origin')
- with self.assertRaisesRegex(GitCommandError, "Couldn't find remote ref __BAD_REF__"):
+ with self.assertRaisesRegex(GitCommandError, "[Cc]ouldn't find remote ref __BAD_REF__"):
rem.fetch('__BAD_REF__')
@with_rw_repo('0.1.6', bare=False)
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 7fc49f3b..0577bd58 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -229,6 +229,22 @@ class TestRepo(TestBase):
Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
+ @with_rw_directory
+ def test_clone_from_pathlib_withConfig(self, rw_dir):
+ if pathlib is None: # pythons bellow 3.4 don't have pathlib
+ raise SkipTest("pathlib was introduced in 3.4")
+
+ original_repo = Repo.init(osp.join(rw_dir, "repo"))
+
+ cloned = Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib_withConfig",
+ multi_options=["--recurse-submodules=repo",
+ "--config core.filemode=false",
+ "--config submodule.repo.update=checkout"])
+
+ assert_equal(cloned.config_reader().get_value('submodule', 'active'), 'repo')
+ assert_equal(cloned.config_reader().get_value('core', 'filemode'), False)
+ assert_equal(cloned.config_reader().get_value('submodule "repo"', 'update'), 'checkout')
+
@with_rw_repo('HEAD')
def test_max_chunk_size(self, repo):
class TestOutputStream(object):
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 9c993205..b5f9d222 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -212,6 +212,12 @@ class TestUtils(TestBase):
self.assertIsInstance(Actor.author(cr), Actor)
# END assure config reader is handled
+ def test_actor_from_string(self):
+ self.assertEqual(Actor._from_string("name"), Actor("name", None))
+ self.assertEqual(Actor._from_string("name <>"), Actor("name", ""))
+ self.assertEqual(Actor._from_string("name last another <some-very-long-email@example.com>"),
+ Actor("name last another", "some-very-long-email@example.com"))
+
@ddt.data(('name', ''), ('name', 'prefix_'))
def test_iterable_list(self, case):
name, prefix = case