import unittest from geniusql import deparse class DeparserTests(unittest.TestCase): def test_deparser_sqlcache_limit(self): # asserts that the SqlCache class is actually length limited cache = deparse.SqlCache(max=3) self.assertEqual(len(cache), 0) for num in [1, 2, 3]: cache[num] = 'meh' self.assertEqual(len(cache), num) for key in ['O1', 'O2', 'O3', 'O4']: cache[key] = key # the number of entries in the cache should never be > 3 (the max) self.assertEqual(len(cache), 3) # and the entry we just cached must be there self.assertEqual(cache[key], key) if __name__ == "__main__": unittest.main(__name__)