def test_get_file_history_cache(self): """Test the cache mechanism of get_file_history.""" with mock.patch.object(self.site, 'loadimageinfo', autospec=True): page = pywikibot.FilePage(self.site, 'File:Foo.jpg') _file_revisions = page.get_file_history() # On the first call the history is loaded via API self.assertEqual(_file_revisions, {}) # Fill the cache _file_revisions['foo'] = 'bar' # On the second call page._file_revisions is returned self.assertEqual(page.get_file_history(), {'foo': 'bar'}) self.site.loadimageinfo.assert_called_once_with(page, history=True)