davemds pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=4457a93ae51c62ae50b73090d29291ce6a3e8e77
commit 4457a93ae51c62ae50b73090d29291ce6a3e8e77 Author: Dave Andreoli <d...@gurumeditation.it> Date: Mon Oct 7 22:38:04 2019 +0200 Pyolian: implement some missing eolian functions with tests --- src/scripts/pyolian/eolian.py | 41 ++++++++++++++++++++++++++++++++++++++ src/scripts/pyolian/eolian_lib.py | 34 ++++++++++++++++++++++++++++++- src/scripts/pyolian/test_eolian.py | 20 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py index 70496debc0..c4425e37df 100644 --- a/src/scripts/pyolian/eolian.py +++ b/src/scripts/pyolian/eolian.py @@ -36,6 +36,10 @@ except ImportError: _already_halted = False +# This is the same as the EOLIAN_FILE_FORMAT_VERSION macro +file_format_version = lib.eolian_file_format_version_get() + + # Eolian Enums ############################################################## class Eolian_Object_Type(IntEnum): UNKNOWN = 0 @@ -352,11 +356,19 @@ class Eolian_Unit(EolianBaseObject): def file(self): return _str_to_py(lib.eolian_unit_file_get(self)) + @cached_property + def file_path(self): + return _str_to_py(lib.eolian_unit_file_path_get(self)) + @cached_property def state(self): c_state = lib.eolian_unit_state_get(self) return Eolian_State(c_state) if c_state else None + @cached_property + def version(self): + return lib.eolian_unit_version_get(self) + @property def objects(self): return Iterator(Object, lib.eolian_unit_objects_get(self)) @@ -504,6 +516,9 @@ class Eolian_State(Eolian_Unit): return Iterator(Typedecl, lib.eolian_state_enums_by_file_get(self, _str_to_bytes(file_name))) + def state_check(self): + return bool(lib.eolian_state_check(self)) + # Namespace Utility Class ################################################### @@ -616,6 +631,10 @@ class Object(EolianBaseObject): def name(self): return _str_to_py(lib.eolian_object_name_get(self)) + @cached_property + def c_name(self): + return _str_to_py(lib.eolian_object_c_name_get(self)) + @cached_property def short_name(self): return _str_to_py(lib.eolian_object_short_name_get(self)) @@ -819,6 +838,11 @@ class Event(Object): c_type = lib.eolian_event_type_get(self) return Type(c_type) if c_type else None + @cached_property + def class_(self): + c_cls = lib.eolian_event_class_get(self) + return Class(c_cls) if c_cls else None + @cached_property def documentation(self): c_doc = lib.eolian_event_documentation_get(self) @@ -935,6 +959,12 @@ class Function(Object): c_type = lib.eolian_function_return_type_get(self, ftype) return Type(c_type) if c_type else None + def return_c_type_get(self, ftype): + s = lib.eolian_function_return_c_type_get(self, ftype) + ret = _str_to_py(s) + lib.eina_stringshare_del(c_void_p(s)) + return ret + def return_default_value(self, ftype): c_expr = lib.eolian_function_return_default_value_get(self._obj, ftype) return Expression(c_expr) if c_expr else None @@ -1006,6 +1036,12 @@ class Function_Parameter(Object): c_expr = lib.eolian_parameter_default_value_get(self) return Expression(c_expr) if c_expr else None + def c_type_get(self, as_return=False): + s = lib.eolian_parameter_c_type_get(self, as_return) + ret = _str_to_py(s) + lib.eina_stringshare_del(c_void_p(s)) + return ret + class Implement(Object): def __repr__(self): @@ -1021,6 +1057,11 @@ class Implement(Object): c_cls = lib.eolian_implement_class_get(self) return Class(c_cls) if c_cls else None + @cached_property + def implementing_class(self): + c_cls = lib.eolian_implement_implementing_class_get(self) + return Class(c_cls) if c_cls else None + @cached_property def function(self): c_func = lib.eolian_implement_function_get(self, None) diff --git a/src/scripts/pyolian/eolian_lib.py b/src/scripts/pyolian/eolian_lib.py index 10098bf9b3..3e9c89111e 100644 --- a/src/scripts/pyolian/eolian_lib.py +++ b/src/scripts/pyolian/eolian_lib.py @@ -93,6 +93,10 @@ lib.eolian_state_all_eo_files_parse.restype = c_bool lib.eolian_state_all_eot_files_parse.argtypes = (c_void_p,) lib.eolian_state_all_eot_files_parse.restype = c_bool +# EAPI Eina_Bool eolian_state_check(const Eolian_State *state); +lib.eolian_state_check.argtypes = (c_void_p,) +lib.eolian_state_check.restype = c_bool + # EAPI const Eolian_Unit *eolian_state_unit_by_file_get(const Eolian_State *state, const char *file_name); lib.eolian_state_unit_by_file_get.argtypes = (c_void_p, c_char_p) lib.eolian_state_unit_by_file_get.restype = c_void_p @@ -140,6 +144,14 @@ lib.eolian_unit_state_get.restype = c_void_p lib.eolian_unit_file_get.argtypes = (c_void_p,) lib.eolian_unit_file_get.restype = c_char_p +# EAPI const char *eolian_unit_file_path_get(const Eolian_Unit *unit); +lib.eolian_unit_file_path_get.argtypes = (c_void_p,) +lib.eolian_unit_file_path_get.restype = c_char_p + +# EAPI unsigned short eolian_unit_version_get(const Eolian_Unit *unit); +lib.eolian_unit_version_get.argtypes = (c_void_p,) +lib.eolian_unit_version_get.restype = c_uint + # EAPI const Eolian_Object *eolian_unit_object_by_name_get(const Eolian_Unit *unit, const char *name); lib.eolian_unit_object_by_name_get.argtypes = (c_void_p, c_char_p) lib.eolian_unit_object_by_name_get.restype = c_void_p @@ -215,6 +227,10 @@ lib.eolian_object_column_get.restype = c_int lib.eolian_object_name_get.argtypes = (c_void_p,) lib.eolian_object_name_get.restype = c_char_p +# EAPI const char *eolian_object_c_name_get(const Eolian_Object *obj); +lib.eolian_object_c_name_get.argtypes = (c_void_p,) +lib.eolian_object_c_name_get.restype = c_char_p + # EAPI const char *eolian_object_short_name_get(const Eolian_Object *obj); lib.eolian_object_short_name_get.argtypes = (c_void_p,) lib.eolian_object_short_name_get.restype = c_char_p @@ -330,9 +346,13 @@ lib.eolian_function_is_static.argtypes = (c_void_p,) lib.eolian_function_is_static.restype = c_bool # EAPI Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass); -lib.eolian_function_is_constructor.argtypes = (c_void_p,c_void_p,) +lib.eolian_function_is_constructor.argtypes = (c_void_p, c_void_p) lib.eolian_function_is_constructor.restype = c_bool +# EAPI Eina_Stringshare *eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, Eina_Bool as_return); +lib.eolian_parameter_c_type_get.argtypes = (c_void_p, c_bool) +lib.eolian_parameter_c_type_get.restype = c_void_p # Stringshare TO BE FREED + # EAPI const Eolian_Type *eolian_function_return_type_get(const Eolian_Function *function_id, Eolian_Function_Type ftype); lib.eolian_function_return_type_get.argtypes = (c_void_p, c_int) lib.eolian_function_return_type_get.restype = c_void_p @@ -349,6 +369,10 @@ lib.eolian_function_return_documentation_get.restype = c_void_p lib.eolian_function_return_allow_unused.argtypes = (c_void_p, c_int) lib.eolian_function_return_allow_unused.restype = c_bool +# EAPI Eina_Stringshare *eolian_function_return_c_type_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype); +lib.eolian_function_return_c_type_get.argtypes = (c_void_p, c_int) +lib.eolian_function_return_c_type_get.restype = c_void_p # Stringshare TO BE FREED + # EAPI Eina_Bool eolian_function_object_is_const(const Eolian_Function *function_id); lib.eolian_function_object_is_const.argtypes = (c_void_p,) lib.eolian_function_object_is_const.restype = c_bool @@ -404,6 +428,10 @@ lib.eolian_parameter_is_optional.restype = c_bool lib.eolian_implement_class_get.argtypes = (c_void_p,) lib.eolian_implement_class_get.restype = c_void_p +# EAPI const Eolian_Class *eolian_implement_implementing_class_get(const Eolian_Implement *impl); +lib.eolian_implement_implementing_class_get.argtypes = (c_void_p,) +lib.eolian_implement_implementing_class_get.restype = c_void_p + # EAPI const Eolian_Function *eolian_implement_function_get(const Eolian_Implement *impl, Eolian_Function_Type *func_type); lib.eolian_implement_function_get.argtypes = (c_void_p, c_void_p) lib.eolian_implement_function_get.restype = c_void_p @@ -462,6 +490,10 @@ lib.eolian_event_type_get.restype = c_void_p lib.eolian_event_documentation_get.argtypes = (c_void_p,) lib.eolian_event_documentation_get.restype = c_void_p +# EAPI const Eolian_Class *eolian_event_class_get(const Eolian_Event *event); +lib.eolian_event_class_get.argtypes = (c_void_p,) +lib.eolian_event_class_get.restype = c_void_p + # EAPI Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event); lib.eolian_event_scope_get.argtypes = (c_void_p,) lib.eolian_event_scope_get.restype = c_int diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py index 3a101691a4..c6d8afe5c9 100755 --- a/src/scripts/pyolian/test_eolian.py +++ b/src/scripts/pyolian/test_eolian.py @@ -23,6 +23,13 @@ SCAN_FOLDER = os.path.join(root_path, 'src', 'lib') eolian_db = None +class TestEolian(unittest.TestCase): + def test_file_format(self): + v = eolian.file_format_version + self.assertIsInstance(v, int) + self.assertGreaterEqual(v, 1) + + class TestBaseObject(unittest.TestCase): def test_base_object_equality(self): cls1 = eolian_db.class_by_name_get('Efl.Loop_Timer') @@ -85,17 +92,24 @@ class TestEolianState(unittest.TestCase): count += 1 self.assertGreater(count, 1) + @unittest.skip('Should this return True?') + def test_integrity(self): + self.assertTrue(eolian_db.state_check()) + class TestEolianUnit(unittest.TestCase): def test_unit_get(self): unit = eolian_db.unit_by_file_get('efl_ui_win.eo') self.assertIsInstance(unit.state, eolian.Eolian_State) self.assertEqual(unit.state, eolian_db) + self.assertIsInstance(unit.version, int) + self.assertGreaterEqual(unit.version, 1) def test_file_get(self): unit = eolian_db.unit_by_file_get('efl_ui_win.eo') self.assertIsInstance(unit, eolian.Eolian_Unit) self.assertEqual(unit.file, 'efl_ui_win.eo') + self.assertTrue(unit.file_path.endswith('efl_ui_win.eo')) # full path can change @unittest.skip('Skipped until unit/state support is fixed') def test_children_listing(self): @@ -299,6 +313,7 @@ class TestEolianObject(unittest.TestCase): def test_name(self): obj = eolian_db.object_by_name_get('Efl.Ui.Frame') self.assertEqual(obj.name, 'Efl.Ui.Frame') + self.assertEqual(obj.c_name, 'Efl_Ui_Frame') def test_short_name(self): obj = eolian_db.object_by_name_get('Efl.Ui.Frame') @@ -387,6 +402,8 @@ class TestEolianFunction(unittest.TestCase): self.assertIsNone(p.default_value) self.assertFalse(p.is_optional) self.assertEqual(p.type.name, 'double') + self.assertEqual(p.c_type_get(False), 'double') + self.assertEqual(p.c_type_get(True), 'double') self.assertIsInstance(p.documentation, eolian.Documentation) @@ -399,6 +416,8 @@ class TestEolianImplement(unittest.TestCase): self.assertEqual(im.name, 'Efl.Loop_Timer.timer_delay') self.assertIsInstance(im.class_, eolian.Class) self.assertIsInstance(im.function, eolian.Function) + self.assertIsInstance(im.implementing_class, eolian.Class) + self.assertEqual(im.implementing_class.name, 'Efl.Loop_Timer') self.assertIsInstance(im.documentation_get(), eolian.Documentation) # TODO is UNRESOLVED correct ? self.assertFalse(im.is_auto()) self.assertFalse(im.is_empty()) @@ -431,6 +450,7 @@ class TestEolianEvent(unittest.TestCase): self.assertFalse(ev.is_beta) self.assertFalse(ev.is_hot) self.assertFalse(ev.is_restart) + self.assertEqual(ev.class_.name, cls.name) class TestEolianPart(unittest.TestCase): --