Skip to content

Commit 2decbe4

Browse files
committed
Test that redefined Diffable.Index should be compatible
This tests the most important characteristics of Diffable.Index that must be (and are) preserved in making it an alias of the enumeration constant INDEX instead of a nested class definition. Adding this additional test also allows commit.INDEX to be used in place of commit.Index in the existing test (since part of what this tests is that they are the same object). That change is also made, along with some very minor cleanup of immediately nearby test code.
1 parent ad00c77 commit 2decbe4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Diff for: test/test_diff.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import ddt
1313
import pytest
1414

15-
from git import NULL_TREE, Diff, DiffIndex, GitCommandError, Repo, Submodule
15+
from git import NULL_TREE, Diff, DiffIndex, Diffable, GitCommandError, Repo, Submodule
1616
from git.cmd import Git
1717
from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory
1818

@@ -352,15 +352,15 @@ def test_diff_submodule(self):
352352
self.assertIsInstance(diff.b_blob.size, int)
353353

354354
def test_diff_interface(self):
355-
# Test a few variations of the main diff routine.
355+
"""Test a few variations of the main diff routine."""
356356
assertion_map = {}
357357
for i, commit in enumerate(self.rorepo.iter_commits("0.1.6", max_count=2)):
358358
diff_item = commit
359359
if i % 2 == 0:
360360
diff_item = commit.tree
361361
# END use tree every second item
362362

363-
for other in (None, NULL_TREE, commit.Index, commit.parents[0]):
363+
for other in (None, NULL_TREE, commit.INDEX, commit.parents[0]):
364364
for paths in (None, "CHANGES", ("CHANGES", "lib")):
365365
for create_patch in range(2):
366366
diff_index = diff_item.diff(other=other, paths=paths, create_patch=create_patch)
@@ -406,10 +406,22 @@ def test_diff_interface(self):
406406
diff_index = c.diff(cp, ["does/not/exist"])
407407
self.assertEqual(len(diff_index), 0)
408408

409+
def test_diff_interface_stability(self):
410+
"""Test that the Diffable.Index redefinition should not break compatibility."""
411+
self.assertIs(
412+
Diffable.Index,
413+
Diffable.INDEX,
414+
"The old and new class attribute names must be aliases.",
415+
)
416+
self.assertIs(
417+
type(Diffable.INDEX).__eq__,
418+
object.__eq__,
419+
"Equality comparison must be reference-based.",
420+
)
421+
409422
@with_rw_directory
410423
def test_rename_override(self, rw_dir):
411-
"""Test disabling of diff rename detection"""
412-
424+
"""Test disabling of diff rename detection."""
413425
# Create and commit file_a.txt.
414426
repo = Repo.init(rw_dir)
415427
file_a = osp.join(rw_dir, "file_a.txt")

0 commit comments

Comments
 (0)