Skip to content

Commit 2382891

Browse files
committed
Test that deprecated Diff.renamed property warns
This starts on a test.deprecation subpackage for deprecation tests. Having these tests in a separate directory inside the test suite may or may not be how they will ultimately be orgnaized, but it has two advantages: - Once all the tests are written, it should be easy to see what in GitPython is deprecated. - Some deprecation warnings -- those on module or class attribute access -- will require the introduction of new dynamic behavior, and thus run the risk of breaking static type checking. So that should be checked for, where applicable. But currently the test suite has no type annotations and is not checked by mypy. Having deprecation-related tests under the same path will make it easier to enable mypy for just this part of the test suite (for now). It is also for this latter reason that the one test so far is written without using the GitPython test suite's existing fixtures whose uses are harder to annotate. This may be changed if warranted, though some of the more complex deprecation-related tests may benefit from being written as pure pytest tests. Although a number of deprecated features in GitPython do already issue warnings, Diff.renamed is one of the features that does not yet do so. So the newly introduced test will fail until that is fixed in the next commit.
1 parent 64ec0b1 commit 2382891

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/deprecation/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This module is part of GitPython and is released under the
2+
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

test/deprecation/test_various.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
"""Tests of assorted deprecation warnings with no extra subtleties to check."""
5+
6+
from git.diff import NULL_TREE
7+
from git.repo import Repo
8+
9+
import pytest
10+
11+
12+
def test_diff_renamed_warns(tmp_path):
13+
(tmp_path / "a.txt").write_text("hello\n", encoding="utf-8")
14+
repo = Repo.init(tmp_path)
15+
repo.index.add(["a.txt"])
16+
commit = repo.index.commit("Initial commit")
17+
(diff,) = commit.diff(NULL_TREE) # Exactly one file in the diff.
18+
19+
with pytest.deprecated_call():
20+
diff.renamed

0 commit comments

Comments
 (0)