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__load_cache_bad_data(self):
# Arrange
with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(b"Invalid JSON!")
# Act
data = pypistats._load_cache(Path(f.name))
# Assert
self.assertEqual(data, {})
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 test__load_cache_not_exist(self):
# Arrange
filename = Path("file-does-not-exist")
# Act
data = pypistats._load_cache(filename)
# Assert
self.assertEqual(data, {})