def test_glued_code(self): prop = PropertyMaker() PropertyMaker().migrateMethods(self.a) Mutator().rebind(prop.getPrivateMehtods, self.a) for methodProp, methodA in (zip(prop.getPrivateMehtods(), self.a.getPrivateMehtods())): self.assertEqual(inspect.getsource(methodProp), inspect.getsource(methodA))
def __init__(self, *args, **kwargs): PropertyMaker().buildProperty(self, 'persist_to', 'melta') \ .buildProperty(self, 'remove_on_cascade', False) \ .buildProperty(self, 'enable_transactions', True) \ .buildProperty(self, 'syncronization_strategy', None) for k, v in kwargs.items(): self._update_property_by_name(k, v)
def __init__(self, melta_object): original_class = melta_object.instance_name if melta_object.get_data_type( ) == INSTANCE_TYPE else melta_object.get_data_type() PropertyMaker().buildProperty(self, 'created_at', datetime.datetime.now()) \ .buildProperty(self, 'modified_at', datetime.datetime.now()) \ .buildProperty(self, 'melta_object', melta_object) \ .buildProperty(self, 'schema') \ .buildProperty(self, 'object_status', CLEAN_MELTAOBJECT_STATUS) \ .buildProperty(self, 'original_class', original_class) \ .buildProperty(self, 'object_references', set())
def __init__(self): super().__init__() PropertyMaker().buildProperty(self, 'another_attr', 130)
def add_property(self, property_name, property_value=None): PropertyMaker().buildProperty(self, property_name, property_value)
def tets_chained_boolean(self): PropertyMaker().buildProperty(self.a, 'somthg', False) \ .buildProperty(self.a, 'prop', 34) self.assertEqual(self.a.prop, 34) self.assertEqual(self.a.somthg, False)
def test_boolean_property(self): PropertyMaker().buildProperty(self.a, 'somthg', False) self.assertEqual(self.a.somthg, False) self.assertFalse(self.a.somthg)
def test_build_properties_chained(self): PropertyMaker().buildProperty(self.a, 'data', 3) \ .buildProperty(self.a, 'something', 'a') self.assertEqual(self.a.data, 3) self.assertEqual(self.a.something, 'a')
def __init__(self, schema, created_at=datetime.datetime.now()): PropertyMaker().buildProperty(self, 'schema', schema) #objects_name_space is a dictionary with Melta object name key and a set of melta objects with that name identifier. self.objects_name_space = {} PropertyMaker().buildProperty(self, 'created_at', created_at) \ .buildProperty(self, 'object_count', 0)
def test_assign_instance(self): b = B() PropertyMaker().buildProperty(self.a, 'instanceB', b) self.assertEqual(b, self.a.instanceB)
def test_build_properties(self): PropertyMaker().buildProperties(self.a, {'dato': "ddd", "saraza": 2}) self.assertEqual(self.a.dato, "ddd") self.assertEqual(self.a.saraza, 2)
def test_build_properties_string(self): PropertyMaker().buildProperty(self.a, 'dato', "ddd") self.assertEqual(self.a.dato, "ddd")
def test_build_property(self): PropertyMaker().buildProperty(self.a, 'saraza', 2) self.assertEqual(self.a.saraza, 2)
def __init__(self, atribute): PropertyMaker().buildProperty(self, 'attribute', atribute)
def __init__(self): #This class inherits from PyObjectSyncronize but it wasn't called the superclass deliberately PropertyMaker().buildProperty(self, "an_attr", 50)
def __init__(self): PropertyMaker().buildProperty(self, "un_atributo", 30) \ .buildProperty(self, "otro_atributo", "algo")
from melta.dynamic.propertyMaker import PropertyMaker property_maker = PropertyMaker() class Person: pass person1 = Person() property_maker.buildProperty(person1, "edad", 20) \ .buildProperty(person1, "altura", 180) \ .buildProperty(person1, "sexo", "male") class House: pass house1 = House() property_maker.buildProperty(house1, "antiguedad", 32) \ .buildProperty(house1, "tipo_casa", "bungalow") \ .buildProperty(house1, "mt2", 360) house2 = House() property_maker.buildProperty(house2, "building_age", 34) \ .buildProperty(house2, "material", "brick") \ .buildProperty(house2, "sq2mts", 453)