class TestMemorizedObject(TestCase):
    def setUp(self):
        self.wrapped_object = [1, 2, 3]
        self.instance = MemorizedObject(self.wrapped_object)

    def test_reduce(self):
        pickle.dumps(self.wrapped_object)
        with self.assertRaises(pickle.PicklingError):
            UNPICKLEABLE = type('UNPICKLEABLE', (ObjectProxy,), {})
            pickle.dumps(MemorizedObject(UNPICKLEABLE(self.wrapped_object)))

    def test_repr(self):
        eq_(self.instance.__repr__(), self.instance.__wrapped__.__repr__())

    def test_from_cache(self):
        eq_(self.instance.from_cache, False)
        self.instance.from_cache = True
        eq_(self.instance.from_cache, True)
        self.instance.from_cache = False
        eq_(self.instance.from_cache, False)
        with self.assertRaises(RuntimeError):
            self.instance.from_cache = 'string'

    def test_cache_key(self):
        DUMMY_KEY = 'abc123'
        eq_(self.instance.cache_key, None)
        self.instance.cache_key = DUMMY_KEY
        eq_(self.instance.cache_key, DUMMY_KEY)
        with self.assertRaises(RuntimeError):
            self.instance.cache_key = True
class TestMemorizedObject(TestCase):
    def setUp(self):
        self.wrapped_object = [1, 2, 3]
        self.instance = MemorizedObject(self.wrapped_object)

    def test_reduce(self):
        pickle.dumps(self.wrapped_object)
        with self.assertRaises(pickle.PicklingError):
            UNPICKLEABLE = type('UNPICKLEABLE', (ObjectProxy, ), {})
            pickle.dumps(MemorizedObject(UNPICKLEABLE(self.wrapped_object)))

    def test_repr(self):
        eq_(self.instance.__repr__(), self.instance.__wrapped__.__repr__())

    def test_from_cache(self):
        eq_(self.instance.from_cache, False)
        self.instance.from_cache = True
        eq_(self.instance.from_cache, True)
        self.instance.from_cache = False
        eq_(self.instance.from_cache, False)
        with self.assertRaises(RuntimeError):
            self.instance.from_cache = 'string'

    def test_cache_key(self):
        DUMMY_KEY = 'abc123'
        eq_(self.instance.cache_key, None)
        self.instance.cache_key = DUMMY_KEY
        eq_(self.instance.cache_key, DUMMY_KEY)
        with self.assertRaises(RuntimeError):
            self.instance.cache_key = True
 def setUp(self):
     self.wrapped_object = [1, 2, 3]
     self.instance = MemorizedObject(self.wrapped_object)
 def test_reduce(self):
     pickle.dumps(self.wrapped_object)
     with self.assertRaises(pickle.PicklingError):
         UNPICKLEABLE = type('UNPICKLEABLE', (ObjectProxy, ), {})
         pickle.dumps(MemorizedObject(UNPICKLEABLE(self.wrapped_object)))
 def setUp(self):
     self.wrapped_object = [1, 2, 3]
     self.instance = MemorizedObject(self.wrapped_object)