예제 #1
0
    def test_basic_csv_cache(self):
        cache_name = self.check_cache_gone('csvcache', csv_path=True)

        cache = CSVCache(cache_name, cache_manager=self.manager)
        cache['foo'] = 'bar'
        cache.save()

        self.check_cache(cache_name, True, csv_path=True)
        cache.load() # Reload
        self.check_cache(cache_name, True, csv_path=True)
        self.assertEqual(cache['foo'], 'bar')

        cache.delete_saved_content()
        self.check_cache_gone(cache_name, csv_path=True)
        cache.load_or_build()
        self.assert_contents_equal(cache, {})
예제 #2
0
    def test_custom_row_builder_reader(self):
        def tuple_key_expander(key, value):
            return list(key) + [value]

        def tuple_key_extractor(row):
            key = tuple(row[:-1])
            value = float(row[-1])
            return key, value

        cache_name = self.check_cache_gone('custom_builder', csv_path=True)

        cache = CSVCache(cache_name, cache_manager=self.manager,
                row_builder=tuple_key_expander, row_reader=tuple_key_extractor)
        cache[('foo', 'bar')] = 1
        cache.save()

        self.check_cache(cache_name, True, csv_path=True)
        cache.load() # Reload
        self.check_cache(cache_name, True, csv_path=True)
        self.assertEqual(cache[('foo', 'bar')], 1)