Ejemplo n.º 1
0
  def test_code_object_cache(self):

    def factory(x):
      def test_fn():
        return x + 1
      return test_fn

    c = cache.CodeObjectCache()

    f1 = factory(1)
    dummy = object()

    c[f1][1] = dummy

    self.assertTrue(c.has(f1, 1))
    self.assertFalse(c.has(f1, 2))
    self.assertIs(c[f1][1], dummy)
    self.assertEqual(len(c), 1)

    f2 = factory(2)

    self.assertTrue(c.has(f2, 1))
    self.assertIs(c[f2][1], dummy)
    self.assertEqual(len(c), 1)
Ejemplo n.º 2
0
 def __init__(self):
   self._cache_lock = threading.RLock()
   self._cache = cache.CodeObjectCache()