def test_extension_cache(): #set and get the attribute rand = _random.Random() value = rand.getrandbits(8) copy_reg._extension_cache['cache1'] = value result = copy_reg._extension_cache['cache1'] Assert(result == value, "The get and set of the attribute failed") value = rand.getrandbits(16) copy_reg._extension_cache['cache2'] = value result = copy_reg._extension_cache['cache2'] Assert(result == value, "The get and set of the attribute failed") #change the value of the attribue value2 = rand.getrandbits(4) copy_reg._extension_cache['cache1'] = value2 result = copy_reg._extension_cache['cache1'] Assert(result == value2, "The get and set of the attribute failed") if not copy_reg._extension_cache.has_key( 'cache1') or not copy_reg._extension_cache.has_key('cache2'): Fail("Set of the attribute failed") copy_reg.clear_extension_cache() if copy_reg._extension_cache.has_key( 'cache1') or copy_reg._extension_cache.has_key('cache2'): Fail("The method clear_extension_cache did not work correctly ")
def test_extension_cache(self): #set and get the attribute rand = random.Random() value = rand.getrandbits(8) copy_reg._extension_cache['cache1'] = value result = copy_reg._extension_cache['cache1'] self.assertTrue(result == value, "The get and set of the attribute failed") value = rand.getrandbits(16) copy_reg._extension_cache['cache2'] = value result = copy_reg._extension_cache['cache2'] self.assertTrue(result == value, "The get and set of the attribute failed") #change the value of the attribue value2 = rand.getrandbits(4) copy_reg._extension_cache['cache1'] = value2 result = copy_reg._extension_cache['cache1'] self.assertTrue(result == value2, "The get and set of the attribute failed") if not copy_reg._extension_cache.has_key('cache1') or not copy_reg._extension_cache.has_key('cache2'): Fail("Set of the attribute failed") copy_reg.clear_extension_cache() if copy_reg._extension_cache.has_key('cache1') or copy_reg._extension_cache.has_key('cache2'): Fail("The method clear_extension_cache did not work correctly ")
def trace_memory_clean_caches(self): """ Avoid polluting results with some builtin python caches """ urlparse.clear_cache() re.purge() linecache.clearcache() copy_reg.clear_extension_cache() if hasattr(fnmatch, "purge"): fnmatch.purge() # pylint: disable=no-member elif hasattr(fnmatch, "_purge"): fnmatch._purge() if hasattr(encodings, "_cache") and len(encodings._cache) > 0: encodings._cache = {} context.log.handler.flush()