From 70b50e068dc2496d923ee336901ed55d212fc83d Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 3 Aug 2021 19:16:41 +0100 Subject: Fix test --- test/test_util.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/test_util.py b/test/test_util.py index ddc5f628..3058dc74 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -238,16 +238,16 @@ class TestUtils(TestBase): @mock.patch("getpass.getuser") def test_actor_get_uid_laziness_called(self, mock_get_uid): mock_get_uid.return_value = "user" - for cr in (None, self.rorepo.config_reader()): - committer = Actor.committer(cr) - author = Actor.author(cr) - if cr is None: # otherwise, use value from config_reader - self.assertEqual(committer.name, 'user') - self.assertTrue(committer.email.startswith('user@')) - self.assertEqual(author.name, 'user') - self.assertTrue(committer.email.startswith('user@')) + committer = Actor.committer(None) + author = Actor.author(None) + # We can't test with `self.rorepo.config_reader()` here, as the uuid laziness + # depends on whether the user running the test has their user.name config set. + self.assertEqual(committer.name, 'user') + self.assertTrue(committer.email.startswith('user@')) + self.assertEqual(author.name, 'user') + self.assertTrue(committer.email.startswith('user@')) self.assertTrue(mock_get_uid.called) - self.assertEqual(mock_get_uid.call_count, 4) + self.assertEqual(mock_get_uid.call_count, 2) def test_actor_from_string(self): self.assertEqual(Actor._from_string("name"), Actor("name", None)) -- cgit v1.2.1 From d490d66e4b82d94b378daa9ad1e1a286e0e09258 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Wed, 4 Aug 2021 10:15:42 +0100 Subject: Try a better test --- test/test_util.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_util.py b/test/test_util.py index 3058dc74..e9701f0c 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -217,8 +217,23 @@ class TestUtils(TestBase): self.assertIsInstance(Actor.author(cr), Actor) # END assure config reader is handled + @with_rw_repo('HEAD') @mock.patch("getpass.getuser") - def test_actor_get_uid_laziness_not_called(self, mock_get_uid): + def test_actor_get_uid_laziness_not_called(self, rwrepo, mock_get_uid): + with rwrepo.config_writer() as cw: + cw.set_value("user", "name", "John Config Doe") + cw.set_value("user", "email", "jcdoe@example.com") + + cr = rwrepo.config_reader() + committer = Actor.committer(cr) + author = Actor.author(cr) + + self.assertEqual(committer.name, 'John Config Doe') + self.assertEqual(committer.email, 'jcdoe@example.com') + self.assertEqual(author.name, 'John Config Doe') + self.assertEqual(author.email, 'jcdoe@example.com') + self.assertFalse(mock_get_uid.called) + env = { "GIT_AUTHOR_NAME": "John Doe", "GIT_AUTHOR_EMAIL": "jdoe@example.com", @@ -226,7 +241,7 @@ class TestUtils(TestBase): "GIT_COMMITTER_EMAIL": "jane@example.com", } os.environ.update(env) - for cr in (None, self.rorepo.config_reader()): + for cr in (None, rwrepo.config_reader()): committer = Actor.committer(cr) author = Actor.author(cr) self.assertEqual(committer.name, 'Jane Doe') @@ -241,7 +256,7 @@ class TestUtils(TestBase): committer = Actor.committer(None) author = Actor.author(None) # We can't test with `self.rorepo.config_reader()` here, as the uuid laziness - # depends on whether the user running the test has their user.name config set. + # depends on whether the user running the test has their global user.name config set. self.assertEqual(committer.name, 'user') self.assertTrue(committer.email.startswith('user@')) self.assertEqual(author.name, 'user') -- cgit v1.2.1 From ec04ea01dbbab9c36105dfc3e34c94bbbbf298b2 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Wed, 4 Aug 2021 10:20:44 +0100 Subject: Update test_util.py --- test/test_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_util.py b/test/test_util.py index e9701f0c..3961ff35 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -22,7 +22,10 @@ from git.objects.util import ( parse_date, tzoffset, from_timestamp) -from test.lib import TestBase +from test.lib import ( + TestBase, + with_rw_repo, +) from git.util import ( LockFile, BlockingLockFile, -- cgit v1.2.1