Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cache_round_trip(self):
# Arrange
filename = pypistats.CACHE_DIR / "test_cache_round_trip.json"
data = "test data"
# Act
pypistats._save_cache(filename, data)
new_data = pypistats._load_cache(filename)
# Tidy up
filename.unlink()
# Assert
self.assertEqual(new_data, data)
def setUp(self):
# Stub caching. Caches are tested in another class.
self.original__cache_filename = pypistats._cache_filename
self.original__save_cache = pypistats._save_cache
pypistats._cache_filename = stub__cache_filename
pypistats._save_cache = stub__save_cache
def setUp(self):
# Stub caching. Caches are tested in another class.
self.original__cache_filename = pypistats._cache_filename
self.original__save_cache = pypistats._save_cache
pypistats._cache_filename = stub__cache_filename
pypistats._save_cache = stub__save_cache
def test__clear_cache(self):
# Arrange
# Create old cache file
cache_file = pypistats.CACHE_DIR / "2018-11-26-old-cache-file.json"
pypistats._save_cache(cache_file, data={})
self.assertTrue(cache_file.exists())
# Act
pypistats._clear_cache()
# Assert
self.assertFalse(cache_file.exists())
def tearDown(self):
# Unstub caching
pypistats._cache_filename = self.original__cache_filename
pypistats._save_cache = self.original__save_cache