Skip to content

Commit e85d8a8

Browse files
author
Stepa
committed
No issue: test_filecmp: Add tests for filecmp.cmp cache hit and overflow clearing
1 parent bc12b72 commit e85d8a8

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎Lib/test/test_filecmp.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ def test_cache_clear(self):
7676
self.assertTrue(len(filecmp._cache) == 0,
7777
"Cache not cleared after calling clear_cache")
7878

79+
def test_cmp_cache_hit(self):
80+
filecmp.clear_cache()
81+
res1 = filecmp.cmp(self.name, self.name_same)
82+
res2 = filecmp.cmp(self.name, self.name_same)
83+
self.assertTrue(res1)
84+
self.assertEqual(res1, res2)
85+
86+
def test_cmp_cache_clearing_on_overflow(self):
87+
filecmp.clear_cache()
88+
fake_sig = (33188, 100, 12345)
89+
for i in range(105):
90+
filecmp._cache[(f"fake_f1_{i}", f"fake_f2_{i}", fake_sig, fake_sig)] = True
91+
92+
self.assertGreater(len(filecmp._cache), 100)
93+
94+
# Вот тут должны быть РЕАЛЬНЫЕ файлы из setUp!
95+
filecmp.cmp(self.name, self.name_same_shallow, shallow=False)
96+
97+
self.assertEqual(len(filecmp._cache), 1)
98+
99+
100+
79101
class DirCompareTestCase(unittest.TestCase):
80102
def setUp(self):
81103
tmpdir = tempfile.gettempdir()
@@ -368,4 +390,4 @@ def _assert_report(self, dircmp_report, expected_report_lines):
368390

369391

370392
if __name__ == "__main__":
371-
unittest.main()
393+
unittest.main()

0 commit comments

Comments
 (0)