Skip to content
Closed
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
29 changes: 28 additions & 1 deletion Lib/test/test_filecmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ def test_cache_clear(self):
filecmp.clear_cache()
self.assertTrue(len(filecmp._cache) == 0,
"Cache not cleared after calling clear_cache")

filecmp.clear_cache()

# 1. Первый вызов (кэш пустой, outcome is None -> True)
res1 = filecmp.cmp(self.name, self.name_same, shallow=False)

# Проверяем, что в кэш действительно записалось ровно 1 значение
self.assertEqual(len(filecmp._cache), 1)

# 2. Второй вызов тех же файлов (outcome is None -> False)
# Он обязан вернуть значение из кэша и выполнить строку 68
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 +395,4 @@ def _assert_report(self, dircmp_report, expected_report_lines):


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