Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions Lib/test/test_filecmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,27 @@ def test_different(self):
"Mismatched file to shallow identical file compares as equal")

def test_cache_clear(self):
first_compare = filecmp.cmp(self.name, self.name_same, shallow=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this?

second_compare = filecmp.cmp(self.name, self.name_diff, shallow=False)
filecmp.cmp(self.name, self.name_same, shallow=False)
filecmp.cmp(self.name, self.name_diff, shallow=False)
filecmp.clear_cache()
self.assertTrue(len(filecmp._cache) == 0,
"Cache not cleared after calling clear_cache")
self.assertEqual(len(filecmp._cache), 0,
"Cache not cleared after calling clear_cache")
filecmp.clear_cache()
res1 = filecmp.cmp(self.name, self.name_same, shallow=False)
self.assertEqual(len(filecmp._cache), 1)
res2 = filecmp.cmp(self.name, self.name_same, shallow=False)
self.assertTrue(res1)
self.assertEqual(res1, res2)
self.assertEqual(len(filecmp._cache), 1)

def test_cmp_cache_clearing_on_overflow(self):
filecmp.clear_cache()
fake_sig = (33188, 100, 12345)
for i in range(105):
filecmp._cache[(f"fake_f1_{i}", f"fake_f2_{i}", fake_sig, fake_sig)] = True
self.assertGreater(len(filecmp._cache), 100)
filecmp.cmp(self.name, self.name_same_shallow, shallow=False)
self.assertEqual(len(filecmp._cache), 1)

class DirCompareTestCase(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -368,4 +384,4 @@ def _assert_report(self, dircmp_report, expected_report_lines):


if __name__ == "__main__":
unittest.main()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this?

unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added tests for filecmp.cmp cache behavior and overflow clearing.