Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b2771d

Browse files
committed
Add regression tests of the git.util aliasing situation
Although this situation is not inherently desirable, for backwardcompatibility it cannot change at this time. It may be possible tochange it in the next major version of GitPython, but even then itshould not be changed accidentally, which can easily happen whilerefactoring imports.This tests the highest-risk accidental change (of those that arecurrently known) of the kind that the temporary modattrs.py scriptexists to help safeguard against. That script will be removed whenthe immediately forthcoming import refactoring is complete, whereasthese test cases can be kept.For information about the specific situation this helps ensureisn't changed accidentally, see the new test cases' docstrings, aswell as the next commit (which will test modattrs.py and these testcases by performing an incomplete change that would be a bug untilcompleted).This commit adds three test cases. The first tests the unintuitiveaspect of the current situation:- test_git_util_attribute_is_git_index_utilThe other two test the intuitive aspects of it, i.e., they testthat changes (perhaps in an attempt to preserve the aspect neededfor 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_existsThe latter tests should also clarify, for readers of the tests, thelimited nature of the condition the first test asserts.
1 parent1e5a944 commit5b2771d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎test/test_imports.py

Lines changed: 32 additions & 0 deletions
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+
importsys
5+
6+
importgit
7+
8+
9+
deftest_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+
assertgit.utilisgit.index.util
19+
20+
21+
deftest_git_index_util_attribute_is_git_index_util():
22+
"""Nothing unusual is happening with git.index.util itself."""
23+
assertgit.index.utilissys.modules["git.index.util"]
24+
25+
26+
deftest_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+
assertsys.modules["git.util"]isnotsys.modules["git.index.util"]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp