summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-01-01 08:35:39 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-01-01 08:37:13 +0100
commite7a26af3302784ef30fe26cd1a5801cba155b1b2 (patch)
treecf7a1a6dc34d70f38070d5df0da8a6741c0e3291
parentdd97383887c2439f5edfc5651bee45a27b9af5d9 (diff)
Pyolian: better equality test, new hierarchy prop and some tests
-rw-r--r--src/scripts/pyolian/eolian.py21
-rwxr-xr-xsrc/scripts/pyolian/test_eolian.py22
-rw-r--r--src/scripts/pyolian/test_gen_class.template14
3 files changed, 50 insertions, 7 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index ced4934f2e..a5653a5120 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -272,7 +272,14 @@ class EolianBaseObject(object):
272 type(c_obj_pointer), self.__class__.__name__)) 272 type(c_obj_pointer), self.__class__.__name__))
273 273
274 def __eq__(self, other): 274 def __eq__(self, other):
275 return self._obj.value == other._obj.value 275 if isinstance(other, EolianBaseObject):
276 return self._obj.value == other._obj.value
277 elif isinstance(other, str):
278 if hasattr(self, 'full_name'):
279 return self.full_name == other
280 elif hasattr(self, 'name'):
281 return self.name == other
282 return False
276 283
277 def __hash__(self): 284 def __hash__(self):
278 return self._obj.value 285 return self._obj.value
@@ -499,6 +506,15 @@ class Class(EolianBaseObject):
499 return L 506 return L
500 507
501 @property 508 @property
509 def hierarchy(self):
510 L = []
511 base = self.base_class
512 while base:
513 L.append(base)
514 base = base.base_class
515 return L
516
517 @property
502 def base_class(self): 518 def base_class(self):
503 inherits = list(self.inherits) 519 inherits = list(self.inherits)
504 if len(inherits) > 0: 520 if len(inherits) > 0:
@@ -884,9 +900,6 @@ class Implement(EolianBaseObject):
884 def is_method(self): 900 def is_method(self):
885 return not self.is_property 901 return not self.is_property
886 902
887 def is_overridden(self, cls):
888 return cls.name == self.class_.name # TODO equality inside class
889
890 903
891class Type(EolianBaseObject): # OK (4 eolian issue) 904class Type(EolianBaseObject): # OK (4 eolian issue)
892 def __repr__(self): 905 def __repr__(self):
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
index 24b76c5686..76baf887f2 100755
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -30,12 +30,27 @@ class TestBaseObject(unittest.TestCase):
30 self.assertIsInstance(cls1, eolian.Class) 30 self.assertIsInstance(cls1, eolian.Class)
31 self.assertIsInstance(cls2, eolian.Class) 31 self.assertIsInstance(cls2, eolian.Class)
32 self.assertEqual(cls1, cls2) 32 self.assertEqual(cls1, cls2)
33 self.assertEqual(cls1, 'Efl.Loop.Timer')
34 self.assertEqual(cls2, 'Efl.Loop.Timer')
35 self.assertNotEqual(cls1, 'another string')
36 self.assertNotEqual(cls1, 1234)
37 self.assertNotEqual(cls1, None)
38 self.assertNotEqual(cls1, 0)
33 39
34 enum1 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction') 40 enum1 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
35 enum2 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction') 41 enum2 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
36 self.assertIsInstance(enum1, eolian.Typedecl) 42 self.assertIsInstance(enum1, eolian.Typedecl)
37 self.assertIsInstance(enum2, eolian.Typedecl) 43 self.assertIsInstance(enum2, eolian.Typedecl)
38 self.assertEqual(enum1, enum2) 44 self.assertEqual(enum1, enum2)
45 self.assertEqual(enum1, 'Efl.Ui.Focus.Direction')
46 self.assertEqual(enum2, 'Efl.Ui.Focus.Direction')
47 self.assertNotEqual(enum1, 'another string')
48 self.assertNotEqual(enum1, 1234)
49 self.assertNotEqual(enum1, None)
50 self.assertNotEqual(enum1, 0)
51
52 self.assertNotEqual(cls1, enum1)
53
39 54
40 55
41class TestEolianUnit(unittest.TestCase): 56class TestEolianUnit(unittest.TestCase):
@@ -152,7 +167,10 @@ class TestEolianClass(unittest.TestCase):
152 self.assertIsNone(cls.eo_prefix) # TODO fin a class with a value 167 self.assertIsNone(cls.eo_prefix) # TODO fin a class with a value
153 self.assertIsNone(cls.event_prefix) # TODO same as above 168 self.assertIsNone(cls.event_prefix) # TODO same as above
154 self.assertIsNone(cls.data_type) # TODO same as above 169 self.assertIsNone(cls.data_type) # TODO same as above
155 self.assertEqual(len(list(cls.inherits)), 1) 170 self.assertEqual(cls.base_class.full_name, 'Efl.Loop.Consumer')
171 self.assertEqual([c.full_name for c in cls.inherits], ['Efl.Loop.Consumer'])
172 self.assertEqual([c.full_name for c in cls.inherits_full], ['Efl.Loop.Consumer', 'Efl.Object'])
173 self.assertEqual([c.full_name for c in cls.hierarchy], ['Efl.Loop.Consumer', 'Efl.Object'])
156 self.assertFalse(cls.ctor_enable) 174 self.assertFalse(cls.ctor_enable)
157 self.assertFalse(cls.dtor_enable) 175 self.assertFalse(cls.dtor_enable)
158 self.assertEqual(cls.c_get_function_name, 'efl_loop_timer_class_get') 176 self.assertEqual(cls.c_get_function_name, 'efl_loop_timer_class_get')
@@ -225,6 +243,8 @@ class TestEolianImplement(unittest.TestCase):
225 self.assertFalse(im.is_pure_virtual()) 243 self.assertFalse(im.is_pure_virtual())
226 self.assertFalse(im.is_prop_set) 244 self.assertFalse(im.is_prop_set)
227 self.assertFalse(im.is_prop_get) 245 self.assertFalse(im.is_prop_get)
246 self.assertFalse(im.is_property)
247 self.assertTrue(im.is_method)
228 248
229 249
230class TestEolianEvent(unittest.TestCase): 250class TestEolianEvent(unittest.TestCase):
diff --git a/src/scripts/pyolian/test_gen_class.template b/src/scripts/pyolian/test_gen_class.template
index 7f03b5edd2..ff8c17de62 100644
--- a/src/scripts/pyolian/test_gen_class.template
+++ b/src/scripts/pyolian/test_gen_class.template
@@ -4,8 +4,10 @@ Class: ${cls.full_name}$
4================================================================================ 4================================================================================
5Class type: ${cls.type}$ 5Class type: ${cls.type}$
6Base Class: ${cls.base_class.full_name if cls.base_class else None}$ 6Base Class: ${cls.base_class.full_name if cls.base_class else None}$
7Inherits: ${list(cls.inherits)}$ 7Inherits: ${', '.join([i.full_name for i in cls.inherits])}$
8InheritsFull: ${cls.inherits_full}$ 8Hierarchy: ${' => '.join([i.full_name for i in cls.hierarchy])}$
9InheritsFull: ${', '.join([i.full_name for i in cls.inherits_full])}$
10Namespace: ${cls.namespace}$
9Namespaces: ${list(cls.namespaces)}$ 11Namespaces: ${list(cls.namespaces)}$
10File: ${cls.file}$ 12File: ${cls.file}$
11Ctor enable: ${cls.ctor_enable}$ 13Ctor enable: ${cls.ctor_enable}$
@@ -35,6 +37,14 @@ Properties:
35 no properties available 37 no properties available
36<!--(end)--> 38<!--(end)-->
37 39
40Implements:
41===========
42<!--(for i in cls.implements)-->
43 * ${i.full_name}$
44<!--(else)-->
45 no implements available
46<!--(end)-->
47
38Events: 48Events:
39======= 49=======
40<!--(for event in cls.events)--> 50<!--(for event in cls.events)-->