Skip to content

Commit 5b2771d

Browse files
committed
Add regression tests of the git.util aliasing situation
Although this situation is not inherently desirable, for backward compatibility it cannot change at this time. It may be possible to change it in the next major version of GitPython, but even then it should not be changed accidentally, which can easily happen while refactoring imports. This tests the highest-risk accidental change (of those that are currently known) of the kind that the temporary modattrs.py script exists to help safeguard against. That script will be removed when the immediately forthcoming import refactoring is complete, whereas these test cases can be kept. For information about the specific situation this helps ensure isn't changed accidentally, see the new test cases' docstrings, as well as the next commit (which will test modattrs.py and these test cases by performing an incomplete change that would be a bug until completed). This commit adds three test cases. The first tests the unintuitive aspect of the current situation: - test_git_util_attribute_is_git_index_util The other two test the intuitive aspects of it, i.e., they test that changes (perhaps in an attempt to preserve the aspect needed for backward compatibility) do not make `git.util` unusual in new (and themselves incompatible) ways: - test_git_index_util_attribute_is_git_index_util - test_separate_git_util_module_exists The latter tests should also clarify, for readers of the tests, the limited nature of the condition the first test asserts.
1 parent 1e5a944 commit 5b2771d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/test_imports.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This module is part of GitPython and is released under the
2+
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
3+
4+
import sys
5+
6+
import git
7+
8+
9+
def test_git_util_attribute_is_git_index_util():
10+
"""The top-level module's ``util`` attribute is really :mod:`git.index.util`.
11+
12+
Although this situation is unintuitive and not a design goal, this has historically
13+
been the case, and it should not be changed without considering the effect on
14+
backward compatibility. In practice, it cannot be changed at least until the next
15+
major version of GitPython. This test checks that it is not accidentally changed,
16+
which could happen when refactoring imports.
17+
"""
18+
assert git.util is git.index.util
19+
20+
21+
def test_git_index_util_attribute_is_git_index_util():
22+
"""Nothing unusual is happening with git.index.util itself."""
23+
assert git.index.util is sys.modules["git.index.util"]
24+
25+
26+
def test_separate_git_util_module_exists():
27+
"""The real git.util and git.index.util modules really are separate.
28+
29+
The real git.util module can be accessed to import a name ``...` by writing
30+
``from git.util import ...``, and the module object can be accessed in sys.modules.
31+
"""
32+
assert sys.modules["git.util"] is not sys.modules["git.index.util"]

0 commit comments

Comments
 (0)