def load_page(url): try: return cache.read(url) except IOError: html = _read_page(url) cache.write(url, html) return html
def test_read_file_exists(self): uri = 'http://www.jeuxvideo.com/' filename = _url_to_filename(uri) path = os.path.join(CACHEDIR, filename) expected = '{data}' # mock open with some data and check it was called with patch('franck.io.cache.open', mock_open(read_data=expected), create=True) as m: actual = read(uri) m.assert_called_once_with(path) self.assertEqual(actual, expected)