Skip to content

Commit

Permalink
Decompose new fixture logic better
Browse files Browse the repository at this point in the history
This will be even more helpful when testing a deprecated member of
the Commit class (not yet done).
  • Loading branch information
EliahKagan committed Mar 28, 2024
1 parent bc111b7 commit e3728c3
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/deprecation/test_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,33 @@


@pytest.fixture
def single_diff(tmp_path):
"""Fixture to supply a single-file diff."""
# TODO: Consider making a fake diff rather than using a real repo and commit.
def commit(tmp_path):
"""Fixture to supply a one-commit repo's commit, enough for deprecation tests."""
(tmp_path / "a.txt").write_text("hello\n", encoding="utf-8")
repo = Repo.init(tmp_path)
repo.index.add(["a.txt"])
commit = repo.index.commit("Initial commit")
yield repo.index.commit("Initial commit")
del repo
gc.collect()


@pytest.fixture
def diff(commit):
"""Fixture to supply a single-file diff."""
# TODO: Consider making a fake diff rather than using a real repo and commit.
(diff,) = commit.diff(NULL_TREE) # Exactly one file in the diff.
yield diff
del repo, commit, diff
gc.collect()


def test_diff_renamed_warns(single_diff):
def test_diff_renamed_warns(diff):
"""The deprecated Diff.renamed property issues a deprecation warning."""
with pytest.deprecated_call():
single_diff.renamed
diff.renamed


def test_diff_renamed_file_does_not_warn(single_diff):
def test_diff_renamed_file_does_not_warn(diff):
"""The preferred Diff.renamed_file property issues no deprecation warning."""
with warnings.catch_warnings():
# FIXME: Refine this to filter for deprecation warnings from GitPython.
warnings.simplefilter("error", DeprecationWarning)
single_diff.renamed_file
diff.renamed_file

0 comments on commit e3728c3

Please sign in to comment.