diff options
author | Sam Saccone <samccone@google.com> | 2022-11-15 23:57:22 +0000 |
---|---|---|
committer | Sam Saccone <samccone@google.com> | 2022-11-16 18:26:49 +0000 |
commit | d686365449ade2480a23f86531a5b6630fcbb7a0 (patch) | |
tree | 513799b440eea76c1dc6736a9258d5128ba95f46 /tests | |
parent | d3cadf18569afa3918be4bbc3f502cd70b650d59 (diff) | |
download | git-repo-d686365449ade2480a23f86531a5b6630fcbb7a0.tar.gz |
Extract env building into a testable helper.v2.30
Previously env dict building was untested and mixed with other mutative
actions. Extract the dict building into a dedicated function and author
tests to ensure the functionality is working as expected.
BUG: b/255376186
BUG: https://crbug.com/gerrit/16247
Change-Id: I0c88e53eb285c5c3fb27f8e6b3a903aedb8e02a8
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351874
Reviewed-by: LaMont Jones <lamontjones@google.com>
Tested-by: Sam Saccone <samccone@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_git_command.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_git_command.py b/tests/test_git_command.py index 93300a6f..aaf21219 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py | |||
@@ -15,6 +15,7 @@ | |||
15 | """Unittests for the git_command.py module.""" | 15 | """Unittests for the git_command.py module.""" |
16 | 16 | ||
17 | import re | 17 | import re |
18 | import os | ||
18 | import unittest | 19 | import unittest |
19 | 20 | ||
20 | try: | 21 | try: |
@@ -26,6 +27,38 @@ import git_command | |||
26 | import wrapper | 27 | import wrapper |
27 | 28 | ||
28 | 29 | ||
30 | class GitCommandTest(unittest.TestCase): | ||
31 | """Tests the GitCommand class (via git_command.git).""" | ||
32 | |||
33 | def setUp(self): | ||
34 | |||
35 | def realpath_mock(val): | ||
36 | return val | ||
37 | |||
38 | mock.patch.object(os.path, 'realpath', side_effect=realpath_mock).start() | ||
39 | |||
40 | def tearDown(self): | ||
41 | mock.patch.stopall() | ||
42 | |||
43 | def test_alternative_setting_when_matching(self): | ||
44 | r = git_command._build_env( | ||
45 | objdir = 'zap/objects', | ||
46 | gitdir = 'zap' | ||
47 | ) | ||
48 | |||
49 | self.assertIsNone(r.get('GIT_ALTERNATE_OBJECT_DIRECTORIES')) | ||
50 | self.assertEqual(r.get('GIT_OBJECT_DIRECTORY'), 'zap/objects') | ||
51 | |||
52 | def test_alternative_setting_when_different(self): | ||
53 | r = git_command._build_env( | ||
54 | objdir = 'wow/objects', | ||
55 | gitdir = 'zap' | ||
56 | ) | ||
57 | |||
58 | self.assertEqual(r.get('GIT_ALTERNATE_OBJECT_DIRECTORIES'), 'zap/objects') | ||
59 | self.assertEqual(r.get('GIT_OBJECT_DIRECTORY'), 'wow/objects') | ||
60 | |||
61 | |||
29 | class GitCallUnitTest(unittest.TestCase): | 62 | class GitCallUnitTest(unittest.TestCase): |
30 | """Tests the _GitCall class (via git_command.git).""" | 63 | """Tests the _GitCall class (via git_command.git).""" |
31 | 64 | ||