Ejemplo n.º 1
0
    def _create_cache_key(self):
        sanitized_keys = [self.func_full_qualified_name]
        for key in self.keys:
            parts = key.split('.')
            current_object = self.function_arguments[parts[0]]
            str_attr = '.'.join(parts[1:])

            target_object = depth_getattr(current_object, str_attr)
            sanitized_keys.append(get_unique_representation(target_object))

        self.cache_key = '//'.join(sanitized_keys)
Ejemplo n.º 2
0
    def _create_cache_key(self):
        sanitized_keys = [self.func_full_qualified_name]
        for key in self.keys:
            parts = key.split('.')
            current_object = self.function_arguments[parts[0]]
            str_attr = '.'.join(parts[1:])

            target_object = depth_getattr(current_object, str_attr)
            sanitized_keys.append(get_unique_representation(target_object))

        self.cache_key = '//'.join(sanitized_keys)
Ejemplo n.º 3
0
    def test_common(self):
        something = 42
        some_class = namedtuple('some_class', ['child'])
        class1 = some_class(something)
        class2 = some_class(class1)

        self.assertEquals(depth_getattr(something, ''), something)
        self.assertEquals(depth_getattr(something, 'imag'), something.imag)

        self.assertEquals(depth_getattr(class1, ''), class1)
        self.assertEquals(depth_getattr(class1, 'child'), something)
        self.assertEquals(depth_getattr(class1, 'child.imag'), something.imag)

        self.assertEquals(depth_getattr(class2, ''), class2)
        self.assertEquals(depth_getattr(class2, 'child'), class1)
        self.assertEquals(depth_getattr(class2, 'child.child'), something)
        self.assertEquals(depth_getattr(class2, 'child.child.imag'), something.imag)
Ejemplo n.º 4
0
 def test_raise_exception_properly(self):
     something = 42
     with self.assertRaises(AttributeError) as e:
         depth_getattr(something, 'boom')
     self.assertEquals(str(e.exception), "'int' object has no attribute 'boom'")