def test_create_patches_3(self): def filter(name, value): return 'method' in name destination = _tomodule obj = _frommodule patches = gorilla.create_patches(destination, obj, filter=filter, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'unbound_class_method', gorilla.get_attribute(obj, 'unbound_class_method')), gorilla.Patch(destination, 'unbound_method', gorilla.get_attribute(obj, 'unbound_method')), gorilla.Patch(destination, 'unbound_static_method', gorilla.get_attribute(obj, 'unbound_static_method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, filter=filter, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'class_method', gorilla.get_attribute(obj, 'class_method')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'static_method', gorilla.get_attribute(obj, 'static_method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Parent obj = _frommodule.Parent patches = gorilla.create_patches(destination, obj, filter=filter, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Child obj = _frommodule.Child patches = gorilla.create_patches(destination, obj, filter=filter, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), ] self.assertEqual(patches, expected_patches)
def test_create_patches_2(self): destination = _tomodule obj = _frommodule patches = gorilla.create_patches(destination, obj, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'Child', gorilla.get_attribute(obj, 'Child')), gorilla.Patch(destination, 'Class', gorilla.get_attribute(obj, 'Class')), gorilla.Patch(destination, 'Parent', gorilla.get_attribute(obj, 'Parent')), gorilla.Patch(destination, 'function', gorilla.get_attribute(obj, 'function')), gorilla.Patch(destination, 'global_variable', gorilla.get_attribute(obj, 'global_variable')), gorilla.Patch(destination, 'unbound_class_method', gorilla.get_attribute(obj, 'unbound_class_method')), gorilla.Patch(destination, 'unbound_method', gorilla.get_attribute(obj, 'unbound_method')), gorilla.Patch(destination, 'unbound_static_method', gorilla.get_attribute(obj, 'unbound_static_method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'Inner', gorilla.get_attribute(obj, 'Inner')), gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'class_method', gorilla.get_attribute(obj, 'class_method')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'static_method', gorilla.get_attribute(obj, 'static_method')), gorilla.Patch(destination, 'value', gorilla.get_attribute(obj, 'value')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Parent obj = _frommodule.Parent patches = gorilla.create_patches(destination, obj, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'from_value', gorilla.get_attribute(obj, 'from_value')), gorilla.Patch(destination, 'instance_value', gorilla.get_attribute(obj, 'instance_value')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'parent_value', gorilla.get_attribute(obj, 'parent_value')), gorilla.Patch(destination, 'to_value', gorilla.get_attribute(obj, 'to_value')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Child obj = _frommodule.Child patches = gorilla.create_patches(destination, obj, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'child_value', gorilla.get_attribute(obj, 'child_value')), gorilla.Patch(destination, 'from_value', gorilla.get_attribute(obj, 'from_value')), gorilla.Patch(destination, 'instance_value', gorilla.get_attribute(obj, 'instance_value')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'parent_value', gorilla.get_attribute(obj, 'parent_value')), gorilla.Patch(destination, 'to_value', gorilla.get_attribute(obj, 'to_value')), ] self.assertEqual(patches, expected_patches)
def test_create_patches_5(self): destination = _tomodule obj = _frommodule gorilla.name('function')(gorilla.get_attribute(obj, 'Class')) gorilla.name('dummy_1')(gorilla.get_attribute(obj, 'Parent')) gorilla.name('dummy_2')(gorilla.get_attribute(obj, 'Child')) patches = gorilla.create_patches(destination, obj) expected_patches = [ gorilla.Patch(destination, 'dummy_2', gorilla.get_attribute(obj, 'Child')), gorilla.Patch(destination, 'function', gorilla.get_attribute(obj, 'Class')), gorilla.Patch(destination, 'dummy_1', gorilla.get_attribute(obj, 'Parent')), gorilla.Patch(destination, 'function', gorilla.get_attribute(obj, 'function')), gorilla.Patch(destination, 'global_variable', gorilla.get_attribute(obj, 'global_variable')), gorilla.Patch(destination, 'whatever', gorilla.get_attribute(obj, 'unbound_class_method')), gorilla.Patch(destination, 'unbound_static_method', gorilla.get_attribute(obj, 'unbound_static_method'), settings=gorilla.Settings(allow_hit=True)), ] self.assertEqual(patches, expected_patches)
def test_create_patches_4(self): def filter(name, value): return 'method' in name destination = _tomodule obj = _frommodule patches = gorilla.create_patches(destination, obj, filter=filter) expected_patches = [ gorilla.Patch(destination, 'function', gorilla.get_attribute(obj, 'function')), gorilla.Patch(destination, 'whatever', gorilla.get_attribute(obj, 'unbound_class_method')), gorilla.Patch(destination, 'unbound_static_method', gorilla.get_attribute(obj, 'unbound_static_method'), settings=gorilla.Settings(allow_hit=True)) ] self.assertEqual(patches, expected_patches) destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, filter=filter) expected_patches = [ gorilla.Patch(destination, 'class_method', gorilla.get_attribute(obj, 'class_method')), gorilla.Patch(destination, 'whatever', gorilla.get_attribute(obj, 'method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Parent obj = _frommodule.Parent patches = gorilla.create_patches(destination, obj, filter=filter) expected_patches = [ gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Child obj = _frommodule.Child patches = gorilla.create_patches(destination, obj, filter=filter) expected_patches = [ gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), ] self.assertEqual(patches, expected_patches)
def test_create_patches_6(self): destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, filter=None, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, name, value) for name, value in sorted(_iteritems(obj.__dict__))] self.assertEqual(patches, expected_patches)
def test_create_patches_6(self): destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, filter=None, recursive=False, use_decorators=False) expected_patches = [ gorilla.Patch(destination, name, value) for name, value in sorted(_iteritems(obj.__dict__)) ] self.assertEqual(patches, expected_patches)
def test_create_patches_1(self): destination = _tomodule obj = _frommodule patches = gorilla.create_patches(destination, obj, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'function', gorilla.get_attribute(obj, 'function')), gorilla.Patch(destination, 'global_variable', gorilla.get_attribute(obj, 'global_variable')), gorilla.Patch(destination, 'unbound_class_method', gorilla.get_attribute(obj, 'unbound_class_method')), gorilla.Patch(destination, 'unbound_method', gorilla.get_attribute(obj, 'unbound_method')), gorilla.Patch(destination, 'unbound_static_method', gorilla.get_attribute(obj, 'unbound_static_method')), gorilla.Patch(destination.Child, 'STATIC_VALUE', gorilla.get_attribute(obj.Child, 'STATIC_VALUE')), gorilla.Patch(destination.Child, 'child_value', gorilla.get_attribute(obj.Child, 'child_value')), gorilla.Patch(destination.Child, 'from_value', gorilla.get_attribute(obj.Child, 'from_value')), gorilla.Patch(destination.Child, 'instance_value', gorilla.get_attribute(obj.Child, 'instance_value')), gorilla.Patch(destination.Child, 'method', gorilla.get_attribute(obj.Child, 'method')), gorilla.Patch(destination.Child, 'parent_value', gorilla.get_attribute(obj.Child, 'parent_value')), gorilla.Patch(destination.Child, 'to_value', gorilla.get_attribute(obj.Child, 'to_value')), gorilla.Patch(destination.Class, 'STATIC_VALUE', gorilla.get_attribute(obj.Class, 'STATIC_VALUE')), gorilla.Patch(destination.Class, 'class_method', gorilla.get_attribute(obj.Class, 'class_method')), gorilla.Patch(destination.Class, 'method', gorilla.get_attribute(obj.Class, 'method')), gorilla.Patch(destination.Class, 'static_method', gorilla.get_attribute(obj.Class, 'static_method')), gorilla.Patch(destination.Class, 'value', gorilla.get_attribute(obj.Class, 'value')), gorilla.Patch(destination.Parent, 'STATIC_VALUE', gorilla.get_attribute(obj.Parent, 'STATIC_VALUE')), gorilla.Patch(destination.Parent, 'from_value', gorilla.get_attribute(obj.Parent, 'from_value')), gorilla.Patch(destination.Parent, 'instance_value', gorilla.get_attribute(obj.Parent, 'instance_value')), gorilla.Patch(destination.Parent, 'method', gorilla.get_attribute(obj.Parent, 'method')), gorilla.Patch(destination.Parent, 'parent_value', gorilla.get_attribute(obj.Parent, 'parent_value')), gorilla.Patch(destination.Parent, 'to_value', gorilla.get_attribute(obj.Parent, 'to_value')), gorilla.Patch( destination.Class.Inner, 'STATIC_VALUE', gorilla.get_attribute(obj.Class.Inner, 'STATIC_VALUE')), gorilla.Patch(destination.Class.Inner, 'method', gorilla.get_attribute(obj.Class.Inner, 'method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Class obj = _frommodule.Class patches = gorilla.create_patches(destination, obj, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'class_method', gorilla.get_attribute(obj, 'class_method')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'static_method', gorilla.get_attribute(obj, 'static_method')), gorilla.Patch(destination, 'value', gorilla.get_attribute(obj, 'value')), gorilla.Patch(destination.Inner, 'STATIC_VALUE', gorilla.get_attribute(obj.Inner, 'STATIC_VALUE')), gorilla.Patch(destination.Inner, 'method', gorilla.get_attribute(obj.Inner, 'method')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Parent obj = _frommodule.Parent patches = gorilla.create_patches(destination, obj, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'from_value', gorilla.get_attribute(obj, 'from_value')), gorilla.Patch(destination, 'instance_value', gorilla.get_attribute(obj, 'instance_value')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'parent_value', gorilla.get_attribute(obj, 'parent_value')), gorilla.Patch(destination, 'to_value', gorilla.get_attribute(obj, 'to_value')), ] self.assertEqual(patches, expected_patches) destination = _tomodule.Child obj = _frommodule.Child patches = gorilla.create_patches(destination, obj, use_decorators=False) expected_patches = [ gorilla.Patch(destination, 'STATIC_VALUE', gorilla.get_attribute(obj, 'STATIC_VALUE')), gorilla.Patch(destination, 'child_value', gorilla.get_attribute(obj, 'child_value')), gorilla.Patch(destination, 'from_value', gorilla.get_attribute(obj, 'from_value')), gorilla.Patch(destination, 'instance_value', gorilla.get_attribute(obj, 'instance_value')), gorilla.Patch(destination, 'method', gorilla.get_attribute(obj, 'method')), gorilla.Patch(destination, 'parent_value', gorilla.get_attribute(obj, 'parent_value')), gorilla.Patch(destination, 'to_value', gorilla.get_attribute(obj, 'to_value')), ] self.assertEqual(patches, expected_patches)