Example #1
0
    def test_load_failure(self, mock_get_dict):
        cache = Cache(5, 60.0)

        mock_get_dict.return_value = None

        self.assertFalse(cache.load("somefile"))
        mock_get_dict.assert_called_once_with("somefile")
        self.assertEqual(cache._items, {})
Example #2
0
    def test_load_success(self, mock_get_dict):
        cache = Cache(5, 60.0)

        mock_get_dict.return_value = {"k1": ["v1", 0.5], "k2": ["v2", 0.8]}

        self.assertTrue(cache.load("somefile"))
        mock_get_dict.assert_called_once_with("somefile")
        self.assertEqual(cache._items, mock_get_dict.return_value)
Example #3
0
    def test_load_success_cache_smaller_than_file(self, mock_get_dict):
        cache = Cache(1, 60.0)

        mock_get_dict.return_value = {
            "k1": ["v1", 0.5],
            "k2": ["v2", 0.8],
            "k3": ["v3", 1.5]
        }

        self.assertTrue(cache.load("somefile"))
        mock_get_dict.assert_called_once_with("somefile")
        self.assertEqual(cache._items, {"k3": ["v3", 1.5]})