mirror of
https://github.com/yweber/lodel2.git
synced 2026-08-08 13:28:37 +02:00
Add tests for LeFactory generated code
This commit is contained in:
parent
961dfe1ea3
commit
f029a95214
2 changed files with 10 additions and 9 deletions
|
|
@ -94,7 +94,7 @@ class LeFactory(object):
|
||||||
return """
|
return """
|
||||||
{name}._fields = {fields}
|
{name}._fields = {fields}
|
||||||
{name}._superiors = {dsups}
|
{name}._superiors = {dsups}
|
||||||
{name}._leClass = {leclass}
|
{name}._leclass = {leclass}
|
||||||
""".format(
|
""".format(
|
||||||
name = LeFactory.name2classname(emtype.name),
|
name = LeFactory.name2classname(emtype.name),
|
||||||
fields = repr(type_fields),
|
fields = repr(type_fields),
|
||||||
|
|
@ -103,8 +103,10 @@ class LeFactory(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
## @brief Generate python code containing the LeObject API
|
## @brief Generate python code containing the LeObject API
|
||||||
# @param model_args dict : Dict of Model __init__ method arguments
|
# @param backend_cls Backend : A model backend class
|
||||||
# @param datasource_args dict : Dict of datasource __init__ method arguments
|
# @param backend_args dict : A dict representing arguments for backend_cls instanciation
|
||||||
|
# @param datasource_cls Datasource : A datasource class
|
||||||
|
# @param datasource_args dict : A dict representing arguments for datasource_cls instanciation
|
||||||
# @return A string representing python code
|
# @return A string representing python code
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_python(backend_cls, backend_args, datasource_cls, datasource_args):
|
def generate_python(backend_cls, backend_args, datasource_cls, datasource_args):
|
||||||
|
|
@ -139,7 +141,7 @@ class LeObject(_LeObject):
|
||||||
_datasource = %s(**%s)
|
_datasource = %s(**%s)
|
||||||
_me_uid = %s
|
_me_uid = %s
|
||||||
|
|
||||||
"""%(backend_constructor, datasource_cls.__name__, repr(datasource_args), repr(leobj_me_uid))
|
"""%(backend_constructor, datasource_cls.__module__+'.'+datasource_cls.__name__, repr(datasource_args), repr(leobj_me_uid))
|
||||||
|
|
||||||
emclass_l = model.components(EditorialModel.classes.EmClass)
|
emclass_l = model.components(EditorialModel.classes.EmClass)
|
||||||
emtype_l = model.components(EditorialModel.types.EmType)
|
emtype_l = model.components(EditorialModel.types.EmType)
|
||||||
|
|
@ -147,7 +149,7 @@ class LeObject(_LeObject):
|
||||||
#LeClass child classes definition
|
#LeClass child classes definition
|
||||||
for emclass in emclass_l:
|
for emclass in emclass_l:
|
||||||
result += """
|
result += """
|
||||||
class %s(LeObject,LeType):
|
class %s(LeObject,LeClass):
|
||||||
_class_id = %d
|
_class_id = %d
|
||||||
"""%(LeFactory.name2classname(emclass.name), emclass.uid)
|
"""%(LeFactory.name2classname(emclass.name), emclass.uid)
|
||||||
#LeType child classes definition
|
#LeType child classes definition
|
||||||
|
|
@ -168,6 +170,5 @@ class %s(%s,LeType):
|
||||||
LeObject._me_uid = %s
|
LeObject._me_uid = %s
|
||||||
"""%repr({ comp.uid:LeFactory.name2classname(comp.name) for comp in emclass_l + emtype_l })
|
"""%repr({ comp.uid:LeFactory.name2classname(comp.name) for comp in emclass_l + emtype_l })
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,9 @@ class LeType(object):
|
||||||
# @thorw A leo exception if invalid stuff
|
# @thorw A leo exception if invalid stuff
|
||||||
# @throw InvalidArgumentError if invalid argument
|
# @throw InvalidArgumentError if invalid argument
|
||||||
@classmethod
|
@classmethod
|
||||||
def insert(self, **datas):
|
def insert(cls, **datas):
|
||||||
self.check_datas_or_raise(datas, complete=True)
|
cls.check_datas_or_raise(datas, complete=True)
|
||||||
super(LeType, self).insert(typename=self.__class__.__name__, classname=self._leclass.__name__, **datas)
|
super(LeType, cls).insert(typename=cls.__name__, **datas)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## @brief Check that datas are valid for this type
|
## @brief Check that datas are valid for this type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue