Pyolian: better equality test, new hierarchy prop and some tests

This commit is contained in:
Davide Andreoli 2018-01-01 08:35:39 +01:00
parent dd97383887
commit e7a26af330
3 changed files with 50 additions and 7 deletions

View File

@ -272,7 +272,14 @@ class EolianBaseObject(object):
type(c_obj_pointer), self.__class__.__name__))
def __eq__(self, other):
return self._obj.value == other._obj.value
if isinstance(other, EolianBaseObject):
return self._obj.value == other._obj.value
elif isinstance(other, str):
if hasattr(self, 'full_name'):
return self.full_name == other
elif hasattr(self, 'name'):
return self.name == other
return False
def __hash__(self):
return self._obj.value
@ -498,6 +505,15 @@ class Class(EolianBaseObject):
do_class_recursive(self)
return L
@property
def hierarchy(self):
L = []
base = self.base_class
while base:
L.append(base)
base = base.base_class
return L
@property
def base_class(self):
inherits = list(self.inherits)
@ -884,9 +900,6 @@ class Implement(EolianBaseObject):
def is_method(self):
return not self.is_property
def is_overridden(self, cls):
return cls.name == self.class_.name # TODO equality inside class
class Type(EolianBaseObject): # OK (4 eolian issue)
def __repr__(self):

View File

@ -30,12 +30,27 @@ class TestBaseObject(unittest.TestCase):
self.assertIsInstance(cls1, eolian.Class)
self.assertIsInstance(cls2, eolian.Class)
self.assertEqual(cls1, cls2)
self.assertEqual(cls1, 'Efl.Loop.Timer')
self.assertEqual(cls2, 'Efl.Loop.Timer')
self.assertNotEqual(cls1, 'another string')
self.assertNotEqual(cls1, 1234)
self.assertNotEqual(cls1, None)
self.assertNotEqual(cls1, 0)
enum1 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
enum2 = state.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
self.assertIsInstance(enum1, eolian.Typedecl)
self.assertIsInstance(enum2, eolian.Typedecl)
self.assertEqual(enum1, enum2)
self.assertEqual(enum1, 'Efl.Ui.Focus.Direction')
self.assertEqual(enum2, 'Efl.Ui.Focus.Direction')
self.assertNotEqual(enum1, 'another string')
self.assertNotEqual(enum1, 1234)
self.assertNotEqual(enum1, None)
self.assertNotEqual(enum1, 0)
self.assertNotEqual(cls1, enum1)
class TestEolianUnit(unittest.TestCase):
@ -152,7 +167,10 @@ class TestEolianClass(unittest.TestCase):
self.assertIsNone(cls.eo_prefix) # TODO fin a class with a value
self.assertIsNone(cls.event_prefix) # TODO same as above
self.assertIsNone(cls.data_type) # TODO same as above
self.assertEqual(len(list(cls.inherits)), 1)
self.assertEqual(cls.base_class.full_name, 'Efl.Loop.Consumer')
self.assertEqual([c.full_name for c in cls.inherits], ['Efl.Loop.Consumer'])
self.assertEqual([c.full_name for c in cls.inherits_full], ['Efl.Loop.Consumer', 'Efl.Object'])
self.assertEqual([c.full_name for c in cls.hierarchy], ['Efl.Loop.Consumer', 'Efl.Object'])
self.assertFalse(cls.ctor_enable)
self.assertFalse(cls.dtor_enable)
self.assertEqual(cls.c_get_function_name, 'efl_loop_timer_class_get')
@ -225,6 +243,8 @@ class TestEolianImplement(unittest.TestCase):
self.assertFalse(im.is_pure_virtual())
self.assertFalse(im.is_prop_set)
self.assertFalse(im.is_prop_get)
self.assertFalse(im.is_property)
self.assertTrue(im.is_method)
class TestEolianEvent(unittest.TestCase):

View File

@ -4,8 +4,10 @@ Class: ${cls.full_name}$
================================================================================
Class type: ${cls.type}$
Base Class: ${cls.base_class.full_name if cls.base_class else None}$
Inherits: ${list(cls.inherits)}$
InheritsFull: ${cls.inherits_full}$
Inherits: ${', '.join([i.full_name for i in cls.inherits])}$
Hierarchy: ${' => '.join([i.full_name for i in cls.hierarchy])}$
InheritsFull: ${', '.join([i.full_name for i in cls.inherits_full])}$
Namespace: ${cls.namespace}$
Namespaces: ${list(cls.namespaces)}$
File: ${cls.file}$
Ctor enable: ${cls.ctor_enable}$
@ -35,6 +37,14 @@ Properties:
no properties available
<!--(end)-->
Implements:
===========
<!--(for i in cls.implements)-->
* ${i.full_name}$
<!--(else)-->
no implements available
<!--(end)-->
Events:
=======
<!--(for event in cls.events)-->