summaryrefslogtreecommitdiff
path: root/src/scripts/pyolian
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2019-10-08 22:50:55 +0200
committerDave Andreoli <dave@gurumeditation.it>2019-10-08 22:51:10 +0200
commitd2d1313f612f081195ec017f50f0dc4f29730bac (patch)
tree7448138000bfc2538be344101e12d1236f20f20f /src/scripts/pyolian
parentf09a3b5ca3b939c9683b0794eff35c73db75d24c (diff)
Pyolian: rewritten tests for the pytest framework
...much more readable now, worst the pain! :)
Diffstat (limited to 'src/scripts/pyolian')
-rwxr-xr-xsrc/scripts/pyolian/test_eolian.py895
1 files changed, 446 insertions, 449 deletions
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
index c6d8afe5c9..bc869c9370 100755
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -1,17 +1,19 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2# encoding: utf-8 2# encoding: utf-8
3""" 3"""
4Pyolian test suite. 4Pyolian test suite
5==================
5 6
6Just run this file to execute the full suite. 7to run all the tests:
7 8> pytest test_eolian.py
8A return value of 0 means all test passed successfully.
9 9
10""" 10"""
11import os 11import os
12import unittest 12import sys
13
14import pytest
13 15
14import eolian 16from . import eolian
15 17
16 18
17# Use .eo files from the source tree (not the installed ones) 19# Use .eo files from the source tree (not the installed ones)
@@ -19,207 +21,233 @@ script_path = os.path.dirname(os.path.realpath(__file__))
19root_path = os.path.abspath(os.path.join(script_path, '..', '..', '..')) 21root_path = os.path.abspath(os.path.join(script_path, '..', '..', '..'))
20SCAN_FOLDER = os.path.join(root_path, 'src', 'lib') 22SCAN_FOLDER = os.path.join(root_path, 'src', 'lib')
21 23
24
22# the main Eolian unit state 25# the main Eolian unit state
23eolian_db = None 26eolian_db = None
24 27
25 28
26class TestEolian(unittest.TestCase): 29@pytest.fixture(scope='module')
30def eolian_db():
31 db = eolian.Eolian_State()
32 if not isinstance(db, eolian.Eolian_State):
33 raise (RuntimeError('Eolian, failed to create Eolian state'))
34
35 # eolian system scan (BROKEN)
36 # if not eolian_db.system_directory_add():
37 # raise(RuntimeError('Eolian, failed to scan system directories'))
38
39 # eolian source tree scan
40 if not db.directory_add(SCAN_FOLDER):
41 raise (RuntimeError('Eolian, failed to scan source directory'))
42
43 # Parse all known eo files
44 if not db.all_eot_files_parse():
45 raise (RuntimeError('Eolian, failed to parse all EOT files'))
46
47 if not db.all_eo_files_parse():
48 raise (RuntimeError('Eolian, failed to parse all EO files'))
49
50 # tests are executed here
51 yield db
52
53 # cleanup eolian
54 del db
55
56
57class TestEolian(object):
27 def test_file_format(self): 58 def test_file_format(self):
28 v = eolian.file_format_version 59 v = eolian.file_format_version
29 self.assertIsInstance(v, int) 60 assert isinstance(v, int)
30 self.assertGreaterEqual(v, 1) 61 assert v >= 1
31 62
32 63
33class TestBaseObject(unittest.TestCase): 64class TestBaseObject(object):
34 def test_base_object_equality(self): 65 def test_base_object_equality(self, eolian_db):
35 cls1 = eolian_db.class_by_name_get('Efl.Loop_Timer') 66 cls1 = eolian_db.class_by_name_get('Efl.Loop_Timer')
36 cls2 = eolian_db.class_by_file_get('efl_loop_timer.eo') 67 cls2 = eolian_db.class_by_file_get('efl_loop_timer.eo')
37 self.assertIsInstance(cls1, eolian.Class) 68 assert isinstance(cls1, eolian.Class)
38 self.assertIsInstance(cls2, eolian.Class) 69 assert isinstance(cls2, eolian.Class)
39 self.assertEqual(cls1, cls2) 70 assert cls1 == cls2
40 self.assertEqual(cls1, 'Efl.Loop_Timer') 71 assert cls1 == 'Efl.Loop_Timer'
41 self.assertEqual(cls2, 'Efl.Loop_Timer') 72 assert cls2 == 'Efl.Loop_Timer'
42 self.assertNotEqual(cls1, 'another string') 73 assert cls1 != 'another string'
43 self.assertNotEqual(cls1, 1234) 74 assert cls1 != 1234
44 self.assertNotEqual(cls1, None) 75 assert cls1 is not None
45 self.assertNotEqual(cls1, 0) 76 assert cls1 != 0
46 77
47 enum1 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction') 78 enum1 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction')
48 enum2 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction') 79 enum2 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction')
49 self.assertIsInstance(enum1, eolian.Typedecl) 80 assert isinstance(enum1, eolian.Typedecl)
50 self.assertIsInstance(enum2, eolian.Typedecl) 81 assert isinstance(enum2, eolian.Typedecl)
51 self.assertEqual(enum1, enum2) 82 assert enum1 == enum2
52 self.assertEqual(enum1, 'Efl.Ui.Focus.Direction') 83 assert enum1 == 'Efl.Ui.Focus.Direction'
53 self.assertEqual(enum2, 'Efl.Ui.Focus.Direction') 84 assert enum2 == 'Efl.Ui.Focus.Direction'
54 self.assertNotEqual(enum1, 'another string') 85 assert enum1 != 'another string'
55 self.assertNotEqual(enum1, 1234) 86 assert enum1 != 1234
56 self.assertNotEqual(enum1, None) 87 assert enum1 is not None
57 self.assertNotEqual(enum1, 0) 88 assert enum1 != 0
58 89
59 self.assertNotEqual(cls1, enum1) 90 assert cls1 != enum1
60 91
61 92
62class TestEolianState(unittest.TestCase): 93class TestEolianState(object):
63 def test_unit_getters(self): 94 def test_unit_getters(self, eolian_db):
64 count = 0 95 count = 0
65 for unit in eolian_db.units: 96 for unit in eolian_db.units:
66 self.assertIsInstance(unit, eolian.Eolian_Unit) 97 assert isinstance(unit, eolian.Eolian_Unit)
67 self.assertTrue(unit.file.endswith(('.eo', '.eot'))) 98 assert unit.file.endswith(('.eo', '.eot'))
68 count += 1 99 count += 1
69 self.assertGreater(count, 400) 100 assert count > 400
70 101
71 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 102 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
72 self.assertIsInstance(unit, eolian.Eolian_Unit) 103 assert isinstance(unit, eolian.Eolian_Unit)
73 self.assertEqual(unit.file, 'efl_ui_win.eo') 104 assert unit.file == 'efl_ui_win.eo'
74 105
75 def test_object_getters(self): 106 def test_object_getters(self, eolian_db):
76 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 107 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
77 self.assertIsInstance(obj, eolian.Object) 108 assert isinstance(obj, eolian.Object)
78 self.assertFalse(type(obj) == eolian.Object) 109 assert type(obj) != eolian.Object
79 self.assertEqual(obj.name, 'Efl.Ui.Frame') 110 assert obj.name == 'Efl.Ui.Frame'
80 111
81 count = 0 112 count = 0
82 for obj in eolian_db.objects: 113 for obj in eolian_db.objects:
83 self.assertIsInstance(obj, eolian.Object) 114 assert isinstance(obj, eolian.Object)
84 self.assertFalse(type(obj) == eolian.Object) 115 assert type(obj) != eolian.Object
85 count += 1 116 count += 1
86 self.assertGreater(count, 800) 117 assert count > 800
87 118
88 count = 0 119 count = 0
89 for obj in eolian_db.objects_by_file_get('efl_loop.eo'): 120 for obj in eolian_db.objects_by_file_get('efl_loop.eo'):
90 self.assertIsInstance(obj, eolian.Object) 121 assert isinstance(obj, eolian.Object)
91 self.assertFalse(type(obj) == eolian.Object) 122 assert type(obj) != eolian.Object
92 count += 1 123 count += 1
93 self.assertGreater(count, 1) 124 assert count > 1
94 125
95 @unittest.skip('Should this return True?') 126 @pytest.mark.skip(reason='Should this return True sooner or later?')
96 def test_integrity(self): 127 def test_integrity(self, eolian_db):
97 self.assertTrue(eolian_db.state_check()) 128 assert eolian_db.state_check() is True
98 129
99 130
100class TestEolianUnit(unittest.TestCase): 131class TestEolianUnit(object):
101 def test_unit_get(self): 132 def test_unit_get(self, eolian_db):
102 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 133 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
103 self.assertIsInstance(unit.state, eolian.Eolian_State) 134 assert isinstance(unit.state, eolian.Eolian_State)
104 self.assertEqual(unit.state, eolian_db) 135 assert unit.state == eolian_db
105 self.assertIsInstance(unit.version, int) 136 assert isinstance(unit.version, int)
106 self.assertGreaterEqual(unit.version, 1) 137 assert unit.version >= 1
107 138
108 def test_file_get(self): 139 def test_file_get(self, eolian_db):
109 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 140 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
110 self.assertIsInstance(unit, eolian.Eolian_Unit) 141 assert isinstance(unit, eolian.Eolian_Unit)
111 self.assertEqual(unit.file, 'efl_ui_win.eo') 142 assert unit.file == 'efl_ui_win.eo'
112 self.assertTrue(unit.file_path.endswith('efl_ui_win.eo')) # full path can change 143 assert unit.file_path.endswith('efl_ui_win.eo') # full path can change
113 144
114 @unittest.skip('Skipped until unit/state support is fixed') 145 @pytest.mark.skip(reason='Skipped until unit/state support is fixed')
115 def test_children_listing(self): 146 def test_children_listing(self, eolian_db):
116 li = list(eolian_db.children) 147 li = list(eolian_db.children)
117 self.assertGreater(len(li), 500) 148 assert len(li) > 500
118 self.assertIsInstance(li[0], eolian.Eolian_Unit) 149 assert isinstance(li[0], eolian.Eolian_Unit)
119 150
120 def test_file_listing(self): 151 def test_file_listing(self, eolian_db):
121 li = list(eolian_db.eo_file_paths) 152 li = list(eolian_db.eo_file_paths)
122 self.assertGreater(len(li), 400) 153 assert len(li) > 400
123 self.assertTrue(li[0].endswith('.eo')) 154 assert li[0].endswith('.eo')
124 155
125 li = list(eolian_db.eo_files) 156 li = list(eolian_db.eo_files)
126 self.assertGreater(len(li), 400) 157 assert len(li) > 400
127 self.assertTrue(li[0].endswith('.eo')) 158 assert li[0].endswith('.eo')
128 159
129 li = list(eolian_db.eot_file_paths) 160 li = list(eolian_db.eot_file_paths)
130 self.assertGreater(len(li), 10) 161 assert len(li) > 10
131 self.assertTrue(li[0].endswith('.eot')) 162 assert li[0].endswith('.eot')
132 163
133 li = list(eolian_db.eot_files) 164 li = list(eolian_db.eot_files)
134 self.assertGreater(len(li), 10) 165 assert len(li) > 10
135 self.assertTrue(li[0].endswith('.eot')) 166 assert li[0].endswith('.eot')
136 167
137 def test_object_listing(self): 168 def test_object_listing(self, eolian_db):
138 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 169 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
139 self.assertIsNone(unit.object_by_name_get('Efl.Ui.Frame')) 170 assert unit.object_by_name_get('Efl.Ui.Frame') is None
140 171
141 obj = unit.object_by_name_get('Efl.Ui.Win') 172 obj = unit.object_by_name_get('Efl.Ui.Win')
142 self.assertIsInstance(obj, eolian.Object) 173 assert isinstance(obj, eolian.Object)
143 self.assertFalse(type(obj) == eolian.Object) 174 assert type(obj) != eolian.Object
144 self.assertEqual(obj.name, 'Efl.Ui.Win') 175 assert obj.name == 'Efl.Ui.Win'
145 176
146 count = 0 177 count = 0
147 for obj in unit.objects: 178 for obj in unit.objects:
148 self.assertIsInstance(obj, eolian.Object) 179 assert isinstance(obj, eolian.Object)
149 self.assertFalse(type(obj) == eolian.Object) 180 assert type(obj) != eolian.Object
150 count += 1 181 count += 1
151 self.assertGreater(count, 5) 182 assert count > 5
152 183
153 def test_enum_listing(self): 184 def test_enum_listing(self, eolian_db):
154 li = list(eolian_db.enums_by_file_get('efl_ui_win.eo')) 185 li = list(eolian_db.enums_by_file_get('efl_ui_win.eo'))
155 self.assertGreater(len(li), 5) 186 assert len(li) > 5
156 self.assertIsInstance(li[0], eolian.Typedecl) 187 assert isinstance(li[0], eolian.Typedecl)
157 self.assertEqual(li[0].type, eolian.Eolian_Typedecl_Type.ENUM) 188 assert li[0].type == eolian.Eolian_Typedecl_Type.ENUM
158 189
159 all_count = 0 190 all_count = 0
160 for enum in eolian_db.enums: 191 for enum in eolian_db.enums:
161 self.assertIsInstance(enum, eolian.Typedecl) 192 assert isinstance(enum, eolian.Typedecl)
162 self.assertEqual(enum.type, eolian.Eolian_Typedecl_Type.ENUM) 193 assert enum.type == eolian.Eolian_Typedecl_Type.ENUM
163 all_count += 1 194 all_count += 1
164 self.assertGreater(all_count, 50) 195 assert all_count > 50
165 196
166 def test_struct_listing(self): 197 def test_struct_listing(self, eolian_db):
167 li = list(eolian_db.structs_by_file_get('eina_types.eot')) 198 li = list(eolian_db.structs_by_file_get('eina_types.eot'))
168 self.assertGreater(len(li), 10) 199 assert len(li) > 10
169 self.assertIsInstance(li[0], eolian.Typedecl) 200 assert isinstance(li[0], eolian.Typedecl)
170 self.assertIn(li[0].type, ( 201 assert li[0].type in (eolian.Eolian_Typedecl_Type.STRUCT,
171 eolian.Eolian_Typedecl_Type.STRUCT, 202 eolian.Eolian_Typedecl_Type.STRUCT_OPAQUE)
172 eolian.Eolian_Typedecl_Type.STRUCT_OPAQUE))
173 203
174 all_count = 0 204 all_count = 0
175 for struct in eolian_db.structs: 205 for struct in eolian_db.structs:
176 self.assertIsInstance(struct, eolian.Typedecl) 206 assert isinstance(struct, eolian.Typedecl)
177 self.assertIn(struct.type, ( 207 assert struct.type in (eolian.Eolian_Typedecl_Type.STRUCT,
178 eolian.Eolian_Typedecl_Type.STRUCT, 208 eolian.Eolian_Typedecl_Type.STRUCT_OPAQUE)
179 eolian.Eolian_Typedecl_Type.STRUCT_OPAQUE))
180 all_count += 1 209 all_count += 1
181 self.assertGreater(all_count, 50) 210 assert all_count > 50
182 211
183 def test_alias_listing(self): 212 def test_alias_listing(self, eolian_db):
184 li = list(eolian_db.aliases_by_file_get('eina_types.eot')) 213 li = list(eolian_db.aliases_by_file_get('eina_types.eot'))
185 self.assertGreater(len(li), 2) 214 assert len(li) > 2
186 self.assertIsInstance(li[0], eolian.Typedecl) 215 assert isinstance(li[0], eolian.Typedecl)
187 216
188 all_count = 0 217 all_count = 0
189 for alias in eolian_db.aliases: 218 for alias in eolian_db.aliases:
190 self.assertIsInstance(alias, eolian.Typedecl) 219 assert isinstance(alias, eolian.Typedecl)
191 self.assertIn(alias.type, ( 220 assert alias.type in (eolian.Eolian_Typedecl_Type.ALIAS,
192 eolian.Eolian_Typedecl_Type.ALIAS, 221 eolian.Eolian_Typedecl_Type.FUNCTION_POINTER) # TODO is this correct ??
193 eolian.Eolian_Typedecl_Type.FUNCTION_POINTER)) # TODO is this correct ??
194 all_count += 1 222 all_count += 1
195 self.assertGreater(all_count, 10) 223 assert all_count > 10
196 224
197 def test_constant_listing(self): 225 def test_constant_listing(self, eolian_db):
198 li = list(eolian_db.constants) 226 li = list(eolian_db.constants)
199 self.assertGreater(len(li), 2) 227 assert len(li) > 2
200 self.assertIsInstance(li[0], eolian.Constant) 228 assert isinstance(li[0], eolian.Constant)
201 229
202 li = list(eolian_db.constants_by_file_get('efl_gfx_stack.eo')) 230 li = list(eolian_db.constants_by_file_get('efl_gfx_stack.eo'))
203 self.assertGreater(len(li), 1) 231 assert len(li) > 1
204 self.assertIsInstance(li[0], eolian.Constant) 232 assert isinstance(li[0], eolian.Constant)
205 233
206 def test_class_listing(self): 234 def test_class_listing(self, eolian_db):
207 all_count = 0 235 all_count = 0
208 for cls in eolian_db.classes: 236 for cls in eolian_db.classes:
209 self.assertIsInstance(cls, eolian.Class) 237 assert isinstance(cls, eolian.Class)
210 all_count += 1 238 all_count += 1
211 self.assertGreater(all_count, 400) 239 assert all_count > 400
212 240
213 241
214class TestEolianNamespace(unittest.TestCase): 242class TestEolianNamespace(object):
215 def test_all_namespace(self): 243 def test_all_namespace(self, eolian_db):
216 count = 0 244 count = 0
217 for ns in eolian_db.all_namespaces: 245 for ns in eolian_db.all_namespaces:
218 self.assertIsInstance(ns, eolian.Namespace) 246 assert isinstance(ns, eolian.Namespace)
219 count += 1 247 count += 1
220 self.assertGreater(count, 50) 248 assert count > 50
221 249
222 def test_namespace_vs_class_collision(self): 250 def test_namespace_vs_class_collision(self, eolian_db):
223 colliding_classes = ['Ecore.Audio', 251 colliding_classes = ['Ecore.Audio',
224 'Ecore.Audio.In', 252 'Ecore.Audio.In',
225 'Ecore.Audio.Out', 253 'Ecore.Audio.Out',
@@ -238,446 +266,415 @@ class TestEolianNamespace(unittest.TestCase):
238 cls = eolian_db.class_by_name_get(ns.name) 266 cls = eolian_db.class_by_name_get(ns.name)
239 # Some legacy classes are parsed and still make this fail. 267 # Some legacy classes are parsed and still make this fail.
240 if cls: 268 if cls:
241 self.assertIn(cls.name, colliding_classes) 269 assert cls.name in colliding_classes
242 else: 270 else:
243 self.assertIsNone(cls) 271 assert cls is None
244 272
245 def test_namespace_equality(self): 273 def test_namespace_equality(self, eolian_db):
246 ns1 = eolian.Namespace(eolian_db, 'Efl.Io') 274 ns1 = eolian.Namespace(eolian_db, 'Efl.Io')
247 ns2 = eolian.Namespace(eolian_db, 'Efl.Net') 275 ns2 = eolian.Namespace(eolian_db, 'Efl.Net')
248 self.assertIsInstance(ns1, eolian.Namespace) 276 assert isinstance(ns1, eolian.Namespace)
249 self.assertIsInstance(ns2, eolian.Namespace) 277 assert isinstance(ns2, eolian.Namespace)
250 self.assertNotEqual(ns1, ns2) 278 assert ns1 != ns2
251 self.assertEqual(ns1, eolian.Namespace(eolian_db, 'Efl.Io')) 279 assert ns1 == eolian.Namespace(eolian_db, 'Efl.Io')
252 self.assertEqual(ns2, eolian.Namespace(eolian_db, 'Efl.Net')) 280 assert ns2 == eolian.Namespace(eolian_db, 'Efl.Net')
253 281
254 def test_namespace_sorting(self): 282 def test_namespace_sorting(self, eolian_db):
255 nspaces = eolian_db.all_namespaces 283 nspaces = eolian_db.all_namespaces
256 nspaces.sort(reverse=True) 284 nspaces.sort(reverse=True)
257 self.assertGreater(nspaces[0], nspaces[-1]) 285 assert nspaces[0] > nspaces[-1]
258 self.assertLess(nspaces[1], nspaces[0]) 286 assert nspaces[1] < nspaces[0]
259 287
260 def test_namespace_by_name(self): 288 def test_namespace_by_name(self, eolian_db):
261 ns = eolian.Namespace(eolian_db, 'Efl.Net') 289 ns = eolian.Namespace(eolian_db, 'Efl.Net')
262 self.assertIsInstance(ns, eolian.Namespace) 290 assert isinstance(ns, eolian.Namespace)
263 self.assertEqual(ns.name, 'Efl.Net') 291 assert ns.name == 'Efl.Net'
264 self.assertEqual(ns.namespaces, ['Efl', 'Net']) 292 assert ns.namespaces == ['Efl', 'Net']
265 293
266 ns = eolian_db.namespace_get_by_name('Efl') 294 ns = eolian_db.namespace_get_by_name('Efl')
267 self.assertIsInstance(ns, eolian.Namespace) 295 assert isinstance(ns, eolian.Namespace)
268 self.assertEqual(ns.name, 'Efl') 296 assert ns.name == 'Efl'
269 297
270 self.assertGreater(len(ns.classes), 30) 298 assert len(ns.classes) > 30
271 for cls in ns.classes: 299 for cls in ns.classes:
272 self.assertIsInstance(cls, eolian.Class) 300 assert isinstance(cls, eolian.Class)
273 self.assertGreater(len(ns.regulars), 4) 301 assert len(ns.regulars) > 4
274 for cls in ns.regulars: 302 for cls in ns.regulars:
275 self.assertIsInstance(cls, eolian.Class) 303 assert isinstance(cls, eolian.Class)
276 self.assertEqual(cls.type, eolian.Eolian_Class_Type.REGULAR) 304 assert cls.type == eolian.Eolian_Class_Type.REGULAR
277 self.assertGreater(len(ns.mixins), 0) 305 assert len(ns.mixins) > 0
278 for cls in ns.mixins: 306 for cls in ns.mixins:
279 self.assertIsInstance(cls, eolian.Class) 307 assert isinstance(cls, eolian.Class)
280 self.assertEqual(cls.type, eolian.Eolian_Class_Type.MIXIN) 308 assert cls.type == eolian.Eolian_Class_Type.MIXIN
281 self.assertGreater(len(ns.interfaces), 15) 309 assert len(ns.interfaces) > 15
282 for cls in ns.interfaces: 310 for cls in ns.interfaces:
283 self.assertIsInstance(cls, eolian.Class) 311 assert isinstance(cls, eolian.Class)
284 self.assertEqual(cls.type, eolian.Eolian_Class_Type.INTERFACE) 312 assert cls.type == eolian.Eolian_Class_Type.INTERFACE
285 313
286 self.assertGreater(len(ns.enums), 1) 314 assert len(ns.enums) > 1
287 for td in ns.enums: 315 for td in ns.enums:
288 self.assertIsInstance(td, eolian.Typedecl) 316 assert isinstance(td, eolian.Typedecl)
289 self.assertEqual(td.type, eolian.Eolian_Typedecl_Type.ENUM) 317 assert td.type == eolian.Eolian_Typedecl_Type.ENUM
290 self.assertGreater(len(ns.aliases), 0) 318 assert len(ns.aliases) > 0
291 for td in ns.aliases: 319 for td in ns.aliases:
292 self.assertIsInstance(td, eolian.Typedecl) 320 assert isinstance(td, eolian.Typedecl)
293 # TODO eolian_typedecl_all_aliases_get also return FUNCTION_POINTER 321 # TODO eolian_typedecl_all_aliases_get also return FUNCTION_POINTER
294 # is this correct? or an eolian bug ? 322 # is this correct? or an eolian bug ?
295 # self.assertEqual(td.type, eolian.Eolian_Typedecl_Type.ALIAS) 323 # assert Equal(td.type, eolian.Eolian_Typedecl_Type.ALIAS)
296 self.assertGreater(len(ns.structs), 2) 324 assert len(ns.structs) > 2
297 for td in ns.structs: 325 for td in ns.structs:
298 self.assertIsInstance(td, eolian.Typedecl) 326 assert isinstance(td, eolian.Typedecl)
299 self.assertEqual(td.type, eolian.Eolian_Typedecl_Type.STRUCT) 327 assert td.type == eolian.Eolian_Typedecl_Type.STRUCT
300 328
301 329
302class TestEolianObject(unittest.TestCase): 330class TestEolianObject(object):
303 def test_object_instance(self): 331 def test_object_instance(self, eolian_db):
304 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 332 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
305 self.assertIsInstance(obj, eolian.Class) 333 assert isinstance(obj, eolian.Class)
306 self.assertEqual(obj.name, 'Efl.Ui.Frame') 334 assert obj.name == 'Efl.Ui.Frame'
307 335
308 def test_unit(self): 336 def test_unit(self, eolian_db):
309 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 337 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
310 self.assertIsInstance(obj.unit, eolian.Eolian_Unit) 338 assert isinstance(obj.unit, eolian.Eolian_Unit)
311 self.assertEqual(obj.unit.file, 'efl_ui_frame.eo') 339 assert obj.unit.file == 'efl_ui_frame.eo'
312 340
313 def test_name(self): 341 def test_name(self, eolian_db):
314 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 342 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
315 self.assertEqual(obj.name, 'Efl.Ui.Frame') 343 assert obj.name == 'Efl.Ui.Frame'
316 self.assertEqual(obj.c_name, 'Efl_Ui_Frame') 344 assert obj.c_name == 'Efl_Ui_Frame'
317 345
318 def test_short_name(self): 346 def test_short_name(self, eolian_db):
319 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 347 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
320 self.assertEqual(obj.short_name, 'Frame') 348 assert obj.short_name == 'Frame'
321 349
322 def test_file(self): 350 def test_file(self, eolian_db):
323 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 351 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
324 self.assertEqual(obj.file, 'efl_ui_frame.eo') 352 assert obj.file == 'efl_ui_frame.eo'
325 353
326 def test_line(self): 354 def test_line(self, eolian_db):
327 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 355 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
328 self.assertIsInstance(obj.line, int) 356 assert isinstance(obj.line, int)
329 self.assertGreater(obj.line, 0) 357 assert obj.line > 0
330 358
331 def test_column(self): 359 def test_column(self, eolian_db):
332 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 360 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
333 self.assertIsInstance(obj.column, int) 361 assert isinstance(obj.column, int)
334 self.assertGreater(obj.column, 0) 362 assert obj.column > 0
335 363
336 364
337class TestEolianClass(unittest.TestCase): 365class TestEolianClass(object):
338 def test_class(self): 366 def test_class(self, eolian_db):
339 cls = eolian_db.class_by_file_get('efl_loop_timer.eo') 367 cls = eolian_db.class_by_file_get('efl_loop_timer.eo')
340 self.assertIsInstance(cls, eolian.Class) 368 assert isinstance(cls, eolian.Class)
341 369
342 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 370 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
343 self.assertIsInstance(cls, eolian.Class) 371 assert isinstance(cls, eolian.Class)
344 372
345 self.assertEqual(cls.name, 'Efl.Loop_Timer') 373 assert cls.name == 'Efl.Loop_Timer'
346 self.assertEqual(cls.short_name, 'Loop_Timer') 374 assert cls.short_name == 'Loop_Timer'
347 self.assertEqual(cls.file, 'efl_loop_timer.eo') 375 assert cls.file == 'efl_loop_timer.eo'
348 self.assertEqual(list(cls.namespaces), ['Efl']) 376 assert list(cls.namespaces) == ['Efl']
349 self.assertEqual(cls.type, eolian.Eolian_Class_Type.REGULAR) 377 assert cls.type == eolian.Eolian_Class_Type.REGULAR
350 self.assertIsInstance(cls.documentation, eolian.Documentation) 378 assert isinstance(cls.documentation, eolian.Documentation)
351 self.assertIsNone(cls.c_prefix) # TODO fin a class with a value 379 assert cls.c_prefix is None # TODO fin a class with a value
352 self.assertIsNone(cls.event_c_prefix) # TODO same as above 380 assert cls.event_c_prefix is None # TODO same as above
353 self.assertIsNone(cls.data_type) # TODO same as above 381 assert cls.data_type is None # TODO same as above
354 self.assertEqual(cls.parent.name, 'Efl.Loop_Consumer') 382 assert cls.parent.name == 'Efl.Loop_Consumer'
355 self.assertEqual([c.name for c in cls.extensions], []) 383 assert [c.name for c in cls.extensions] == []
356 self.assertEqual([c.name for c in cls.hierarchy], ['Efl.Loop_Consumer', 'Efl.Object']) 384 assert [c.name for c in cls.hierarchy] == ['Efl.Loop_Consumer', 'Efl.Object']
357 self.assertFalse(cls.ctor_enable) 385 assert cls.ctor_enable is False
358 self.assertFalse(cls.dtor_enable) 386 assert cls.dtor_enable is False
359 self.assertEqual(cls.c_get_function_name, 'efl_loop_timer_class_get') 387 assert cls.c_get_function_name == 'efl_loop_timer_class_get'
360 self.assertEqual(cls.c_macro, 'EFL_LOOP_TIMER_CLASS') 388 assert cls.c_macro == 'EFL_LOOP_TIMER_CLASS'
361 self.assertEqual(cls.c_data_type, 'Efl_Loop_Timer_Data') 389 assert cls.c_data_type == 'Efl_Loop_Timer_Data'
362 self.assertEqual([f.name for f in cls.methods], ['timer_reset', 'timer_loop_reset', 'timer_delay']) 390 assert [f.name for f in cls.methods] == ['timer_reset', 'timer_loop_reset', 'timer_delay']
363 self.assertEqual([f.name for f in cls.properties], ['timer_interval', 'time_pending']) 391 assert [f.name for f in cls.properties] == ['timer_interval', 'time_pending']
364 self.assertGreater(len(list(cls.implements)), 5) 392 assert len(list(cls.implements)) > 5
365 self.assertIsInstance(list(cls.implements)[0], eolian.Implement) 393 assert isinstance(list(cls.implements)[0], eolian.Implement)
366 394
367 395
368class TestEolianFunction(unittest.TestCase): 396class TestEolianFunction(object):
369 def test_function(self): 397 def test_function(self, eolian_db):
370 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 398 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
371 f = cls.function_by_name_get('timer_delay') 399 f = cls.function_by_name_get('timer_delay')
372 self.assertIsInstance(f, eolian.Function) 400 assert isinstance(f, eolian.Function)
373 self.assertEqual(f.name, 'timer_delay') 401 assert f.name == 'timer_delay'
374 self.assertEqual(f.type, eolian.Eolian_Function_Type.METHOD) 402 assert f.type == eolian.Eolian_Function_Type.METHOD
375 self.assertEqual(f.method_scope, eolian.Eolian_Object_Scope.PUBLIC) 403 assert f.method_scope == eolian.Eolian_Object_Scope.PUBLIC
376 self.assertEqual(f.getter_scope, eolian.Eolian_Object_Scope.UNKNOWN) # TODO correct? 404 assert f.getter_scope == eolian.Eolian_Object_Scope.UNKNOWN # TODO correct ?
377 self.assertEqual(f.setter_scope, eolian.Eolian_Object_Scope.UNKNOWN) # TODO correct? 405 assert f.setter_scope == eolian.Eolian_Object_Scope.UNKNOWN # TODO correct ?
378 self.assertEqual(f.full_c_method_name, 'efl_loop_timer_delay') 406 assert f.full_c_method_name == 'efl_loop_timer_delay'
379 self.assertEqual(f.full_c_getter_name, 'efl_loop_timer_delay_get') 407 assert f.full_c_getter_name == 'efl_loop_timer_delay_get'
380 self.assertEqual(f.full_c_setter_name, 'efl_loop_timer_delay_set') 408 assert f.full_c_setter_name == 'efl_loop_timer_delay_set'
381 self.assertIsNone(f.method_return_type) # TODO correct ? 409 assert f.method_return_type is None # TODO correct ?
382 self.assertIsNone(f.setter_return_type) # TODO correct ? 410 assert f.setter_return_type is None # TODO correct ?
383 self.assertIsNone(f.getter_return_type) # TODO correct ? 411 assert f.getter_return_type is None # TODO correct ?
384 self.assertFalse(f.is_static) 412 assert f.is_static is False
385 self.assertFalse(f.is_beta) 413 assert f.is_beta is False
386 self.assertFalse(f.is_constructor(cls)) 414 assert f.is_constructor(cls) is False
387 # # #assert f.is_function_pointer == False # TODO broken somehow 415 # # #assert f.is_function_pointer == False # TODO broken somehow
388 self.assertEqual(len(list(f.getter_values)), 1) 416 assert len(list(f.getter_values)) == 1
389 self.assertEqual(len(list(f.getter_values)), 1) 417 assert len(list(f.getter_values)) == 1
390 self.assertEqual(len(list(f.parameters)), 1) 418 assert len(list(f.parameters)) == 1
391 self.assertTrue(f.return_allow_unused(eolian.Eolian_Function_Type.METHOD)) 419 assert f.return_allow_unused(eolian.Eolian_Function_Type.METHOD) is True
392 self.assertFalse(f.object_is_const) 420 assert f.object_is_const is False
393 self.assertEqual(f.class_.name, 'Efl.Loop_Timer') 421 assert f.class_.name == 'Efl.Loop_Timer'
394 self.assertIsInstance(f.implement, eolian.Implement) 422 assert isinstance(f.implement, eolian.Implement)
395 423
396 def test_function_parameter(self): 424 def test_function_parameter(self, eolian_db):
397 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 425 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
398 f = cls.function_by_name_get('timer_delay') 426 f = cls.function_by_name_get('timer_delay')
399 p = list(f.parameters)[0] 427 p = list(f.parameters)[0]
400 self.assertEqual(p.direction, eolian.Eolian_Parameter_Direction.IN) 428 assert p.direction == eolian.Eolian_Parameter_Direction.IN
401 self.assertEqual(p.name, 'add') 429 assert p.name == 'add'
402 self.assertIsNone(p.default_value) 430 assert p.default_value is None
403 self.assertFalse(p.is_optional) 431 assert p.is_optional is False
404 self.assertEqual(p.type.name, 'double') 432 assert p.type.name == 'double'
405 self.assertEqual(p.c_type_get(False), 'double') 433 assert p.c_type_get(False) == 'double'
406 self.assertEqual(p.c_type_get(True), 'double') 434 assert p.c_type_get(True) == 'double'
407 self.assertIsInstance(p.documentation, eolian.Documentation) 435 assert isinstance(p.documentation, eolian.Documentation)
408 436
409 437
410class TestEolianImplement(unittest.TestCase): 438class TestEolianImplement(object):
411 def test_implement(self): 439 def test_implement(self, eolian_db):
412 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 440 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
413 f = cls.function_by_name_get('timer_delay') 441 f = cls.function_by_name_get('timer_delay')
414 im = f.implement 442 im = f.implement
415 self.assertIsInstance(im, eolian.Implement) 443 assert isinstance(im, eolian.Implement)
416 self.assertEqual(im.name, 'Efl.Loop_Timer.timer_delay') 444 assert im.name == 'Efl.Loop_Timer.timer_delay'
417 self.assertIsInstance(im.class_, eolian.Class) 445 assert isinstance(im.class_, eolian.Class)
418 self.assertIsInstance(im.function, eolian.Function) 446 assert isinstance(im.function, eolian.Function)
419 self.assertIsInstance(im.implementing_class, eolian.Class) 447 assert isinstance(im.implementing_class, eolian.Class)
420 self.assertEqual(im.implementing_class.name, 'Efl.Loop_Timer') 448 assert im.implementing_class.name == 'Efl.Loop_Timer'
421 self.assertIsInstance(im.documentation_get(), eolian.Documentation) # TODO is UNRESOLVED correct ? 449 assert isinstance(im.documentation_get(), eolian.Documentation) # TODO is UNRESOLVED correct ?
422 self.assertFalse(im.is_auto()) 450 assert im.is_auto() is False
423 self.assertFalse(im.is_empty()) 451 assert im.is_empty() is False
424 self.assertFalse(im.is_pure_virtual()) 452 assert im.is_pure_virtual() is False
425 self.assertFalse(im.is_prop_set) 453 assert im.is_prop_set is False
426 self.assertFalse(im.is_prop_get) 454 assert im.is_prop_get is False
427 self.assertFalse(im.is_property) 455 assert im.is_property is False
428 self.assertTrue(im.is_method) 456 assert im.is_method is True
429 self.assertIsNone(im.parent) 457 assert im.parent is None
430 458
431 def test_implement_parent(self): 459 def test_implement_parent(self, eolian_db):
432 cls = eolian_db.class_by_name_get('Efl.Ui.Button') 460 cls = eolian_db.class_by_name_get('Efl.Ui.Button')
433 im = [im for im in cls.implements if im.short_name == 'content_unset'][0] 461 im = [im for im in cls.implements if im.short_name == 'content_unset'][0]
434 self.assertIsInstance(im, eolian.Implement) 462 assert isinstance(im, eolian.Implement)
435 self.assertEqual(im.name, 'Efl.Content.content_unset') # TODO is this right?? 463 assert im.name == 'Efl.Content.content_unset' # TODO is this right??
436 self.assertEqual(im.parent.name, 'Efl.Content.content_unset') 464 assert im.parent.name == 'Efl.Content.content_unset'
437 465
438 466
439class TestEolianEvent(unittest.TestCase): 467class TestEolianEvent(object):
440 def test_event(self): 468 def test_event(self, eolian_db):
441 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 469 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
442 self.assertEqual([e.name for e in cls.events], ['timer,tick']) 470 assert [e.name for e in cls.events] == ['timer,tick']
443 ev = cls.event_by_name_get('timer,tick') 471 ev = cls.event_by_name_get('timer,tick')
444 self.assertIsInstance(ev, eolian.Event) 472 assert isinstance(ev, eolian.Event)
445 self.assertEqual(ev.name, 'timer,tick') 473 assert ev.name == 'timer,tick'
446 self.assertEqual(ev.c_macro, 'EFL_LOOP_TIMER_EVENT_TIMER_TICK') 474 assert ev.c_macro == 'EFL_LOOP_TIMER_EVENT_TIMER_TICK'
447 self.assertIsNone(ev.type) # TODO is this correct 475 assert ev.type is None # TODO is this correct
448 self.assertIsInstance(ev.documentation, eolian.Documentation) 476 assert isinstance(ev.documentation, eolian.Documentation)
449 self.assertEqual(ev.scope, eolian.Eolian_Object_Scope.PUBLIC) 477 assert ev.scope == eolian.Eolian_Object_Scope.PUBLIC
450 self.assertFalse(ev.is_beta) 478 assert ev.is_beta is False
451 self.assertFalse(ev.is_hot) 479 assert ev.is_hot is False
452 self.assertFalse(ev.is_restart) 480 assert ev.is_restart is False
453 self.assertEqual(ev.class_.name, cls.name) 481 assert ev.class_.name == cls.name
454 482
455 483
456class TestEolianPart(unittest.TestCase): 484class TestEolianPart(object):
457 def test_part(self): 485 def test_part(self, eolian_db):
458 cls = eolian_db.class_by_name_get('Efl.Ui.Popup') 486 cls = eolian_db.class_by_name_get('Efl.Ui.Popup')
459 parts = list(cls.parts) 487 parts = list(cls.parts)
460 self.assertGreater(len(parts), 0) 488 assert len(parts) > 0
461 489
462 part = parts[0] 490 part = parts[0]
463 self.assertEqual(part.name, 'backwall') 491 assert part.name == 'backwall'
464 self.assertIsInstance(part.class_, eolian.Class) 492 assert isinstance(part.class_, eolian.Class)
465 self.assertEqual(part.class_.name, 'Efl.Ui.Popup_Part_Backwall') 493 assert part.class_.name == 'Efl.Ui.Popup_Part_Backwall'
466 self.assertIsInstance(part.documentation, eolian.Documentation) 494 assert isinstance(part.documentation, eolian.Documentation)
467 495
468 496
469class TestEolianConstructor(unittest.TestCase): 497class TestEolianConstructor(object):
470 def test_constructor(self): 498 def test_constructor(self, eolian_db):
471 cls = eolian_db.class_by_name_get('Efl.Ui.Win') 499 cls = eolian_db.class_by_name_get('Efl.Ui.Win')
472 ctors = list(cls.constructors) 500 ctors = list(cls.constructors)
473 self.assertGreater(len(ctors), 0) 501 assert len(ctors) > 0
474 ctor = ctors[0] 502 ctor = ctors[0]
475 self.assertIsInstance(ctor, eolian.Constructor) 503 assert isinstance(ctor, eolian.Constructor)
476 self.assertEqual(ctor.name, 'Efl.Ui.Win.win_name') 504 assert ctor.name == 'Efl.Ui.Win.win_name'
477 self.assertTrue(ctor.is_optional) 505 assert ctor.is_optional is True
478 self.assertIsInstance(ctor.class_, eolian.Class) 506 assert isinstance(ctor.class_, eolian.Class)
479 self.assertEqual(ctor.class_.name, 'Efl.Ui.Win') 507 assert ctor.class_.name == 'Efl.Ui.Win'
480 self.assertIsInstance(ctor.function, eolian.Function) 508 assert isinstance(ctor.function, eolian.Function)
481 self.assertEqual(ctor.function.name, 'win_name') 509 assert ctor.function.name == 'win_name'
482 510
483 511
484class TestEolianDocumentation(unittest.TestCase): 512class TestEolianDocumentation(object):
485 def test_documentation(self): 513 def test_documentation(self, eolian_db):
486 td = eolian_db.class_by_name_get('Efl.Object') 514 td = eolian_db.class_by_name_get('Efl.Object')
487 doc = td.documentation 515 doc = td.documentation
488 self.assertIsInstance(doc, eolian.Documentation) 516 assert isinstance(doc, eolian.Documentation)
489 self.assertIsInstance(doc.summary, str) 517 assert isinstance(doc.summary, str)
490 self.assertGreater(len(doc.summary), 10) 518 assert len(doc.summary) > 10
491 self.assertIsInstance(doc.description, str) 519 assert isinstance(doc.description, str)
492 self.assertGreater(len(doc.description), 20) 520 assert len(doc.description) > 20
493 self.assertEqual(doc.since, '1.22') 521 assert doc.since == '1.22'
494 522
495 523
496class TestEolianConstant(unittest.TestCase): 524class TestEolianConstant(object):
497 def test_constant(self): 525 def test_constant(self, eolian_db):
498 var = eolian_db.constant_by_name_get('Efl.Gfx.Hint_Expand') 526 var = eolian_db.constant_by_name_get('Efl.Gfx.Hint_Expand')
499 self.assertIsInstance(var, eolian.Constant) 527 assert isinstance(var, eolian.Constant)
500 self.assertEqual(var.name, 'Efl.Gfx.Hint_Expand') 528 assert var.name == 'Efl.Gfx.Hint_Expand'
501 self.assertEqual(var.short_name, 'Hint_Expand') 529 assert var.short_name == 'Hint_Expand'
502 self.assertEqual(var.file, 'efl_gfx_hint.eo') 530 assert var.file == 'efl_gfx_hint.eo'
503 self.assertFalse(var.is_extern) 531 assert var.is_extern is False
504 self.assertEqual(list(var.namespaces), ['Efl', 'Gfx']) 532 assert list(var.namespaces) == ['Efl', 'Gfx']
505 self.assertIsInstance(var.documentation, eolian.Documentation) 533 assert isinstance(var.documentation, eolian.Documentation)
506 self.assertIsInstance(var.type, eolian.Type) 534 assert isinstance(var.type, eolian.Type)
507 self.assertIsInstance(var.value, eolian.Expression) 535 assert isinstance(var.value, eolian.Expression)
508 self.assertEqual(float(var.value.serialize), +1.0) 536 assert float(var.value.serialize) == +1.0
509 537
510 538
511class TestEolianTypedecl(unittest.TestCase): 539class TestEolianTypedecl(object):
512 def test_typedecl_enum(self): 540 def test_typedecl_enum(self, eolian_db):
513 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version') 541 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
514 self.assertIsInstance(td, eolian.Typedecl) 542 assert isinstance(td, eolian.Typedecl)
515 self.assertEqual(td.name, 'Efl.Net.Http.Version') 543 assert td.name == 'Efl.Net.Http.Version'
516 self.assertEqual(td.short_name, 'Version') 544 assert td.short_name == 'Version'
517 self.assertEqual(td.file, 'efl_net_http_types.eot') 545 assert td.file == 'efl_net_http_types.eot'
518 self.assertEqual(list(td.namespaces), ['Efl', 'Net', 'Http']) 546 assert list(td.namespaces) == ['Efl', 'Net', 'Http']
519 self.assertIsInstance(td.documentation, eolian.Documentation) 547 assert isinstance(td.documentation, eolian.Documentation)
520 self.assertIsNone(td.base_type) # TODO find a better test 548 assert td.base_type is None # TODO find a better test
521 self.assertIsNone(td.free_func) # TODO find a better test 549 assert td.free_func is None # TODO find a better test
522 self.assertIsNone(td.function_pointer) # TODO find a better test 550 assert td.function_pointer is None # TODO find a better test
523 self.assertFalse(td.is_extern) 551 assert td.is_extern is False
524 self.assertEqual(len(list(td.enum_fields)), 3) 552 assert len(list(td.enum_fields)) == 3
525 self.assertEqual(td.c_type, 'enum Efl_Net_Http_Version { v1_0 = 100, v1_1 = 101, v2_0 = 200 }') 553 assert td.c_type == 'enum Efl_Net_Http_Version { v1_0 = 100, v1_1 = 101, v2_0 = 200 }'
526 554
527 def test_typedecl_enum_field(self): 555 def test_typedecl_enum_field(self, eolian_db):
528 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version') 556 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
529 field = td.enum_field_get('v1_0') 557 field = td.enum_field_get('v1_0')
530 self.assertIsInstance(field, eolian.Enum_Type_Field) 558 assert isinstance(field, eolian.Enum_Type_Field)
531 self.assertEqual(field.name, 'v1_0') 559 assert field.name == 'v1_0'
532 self.assertEqual(field.c_constant, 'EFL_NET_HTTP_VERSION_V1_0') 560 assert field.c_constant == 'EFL_NET_HTTP_VERSION_V1_0'
533 self.assertIsInstance(field.documentation, eolian.Documentation) 561 assert isinstance(field.documentation, eolian.Documentation)
534 self.assertIsInstance(field.value, eolian.Expression) 562 assert isinstance(field.value, eolian.Expression)
535 563
536 def test_typedecl_struct(self): 564 def test_typedecl_struct(self, eolian_db):
537 td = eolian_db.struct_by_name_get('Efl.Gfx.Color32') 565 td = eolian_db.struct_by_name_get('Efl.Gfx.Color32')
538 self.assertIsInstance(td, eolian.Typedecl) 566 assert isinstance(td, eolian.Typedecl)
539 self.assertEqual(td.name, 'Efl.Gfx.Color32') 567 assert td.name == 'Efl.Gfx.Color32'
540 self.assertEqual(td.short_name, 'Color32') 568 assert td.short_name == 'Color32'
541 self.assertEqual(td.file, 'efl_canvas_filter_internal.eo') 569 assert td.file == 'efl_canvas_filter_internal.eo'
542 self.assertEqual(list(td.namespaces), ['Efl', 'Gfx']) 570 assert list(td.namespaces) == ['Efl', 'Gfx']
543 self.assertIsInstance(td.documentation, eolian.Documentation) 571 assert isinstance(td.documentation, eolian.Documentation)
544 self.assertIsNone(td.base_type) # TODO find a better test 572 assert td.base_type is None # TODO find a better test
545 self.assertIsNone(td.free_func) # TODO find a better test 573 assert td.free_func is None # TODO find a better test
546 self.assertIsNone(td.function_pointer) # TODO find a better test 574 assert td.function_pointer is None # TODO find a better test
547 self.assertFalse(td.is_extern) 575 assert td.is_extern is False
548 self.assertEqual(len(list(td.struct_fields)), 4) 576 assert len(list(td.struct_fields)) == 4
549 self.assertEqual(td.c_type, 'struct Efl_Gfx_Color32 { uint8_t r; uint8_t g; uint8_t b; uint8_t a; }') 577 assert td.c_type == 'struct Efl_Gfx_Color32 { uint8_t r; uint8_t g; uint8_t b; uint8_t a; }'
550 578
551 def test_typedecl_struct_field(self): 579 def test_typedecl_struct_field(self, eolian_db):
552 td = eolian_db.struct_by_name_get('Efl.Gfx.Color32') 580 td = eolian_db.struct_by_name_get('Efl.Gfx.Color32')
553 field = td.struct_field_get('b') 581 field = td.struct_field_get('b')
554 self.assertIsInstance(field, eolian.Struct_Type_Field) 582 assert isinstance(field, eolian.Struct_Type_Field)
555 self.assertEqual(field.name, 'b') 583 assert field.name == 'b'
556 self.assertIsInstance(field.type, eolian.Type) 584 assert isinstance(field.type, eolian.Type)
557 self.assertIsInstance(field.documentation, eolian.Documentation) 585 assert isinstance(field.documentation, eolian.Documentation)
558 586
559 def test_typedecl_alias(self): 587 def test_typedecl_alias(self, eolian_db):
560 alias = eolian_db.alias_by_name_get('Eina.Error') 588 alias = eolian_db.alias_by_name_get('Eina.Error')
561 self.assertIsInstance(alias, eolian.Typedecl) 589 assert isinstance(alias, eolian.Typedecl)
562 self.assertEqual(alias.type, eolian.Eolian_Typedecl_Type.ALIAS) 590 assert alias.type == eolian.Eolian_Typedecl_Type.ALIAS
563 self.assertEqual(alias.name, 'Eina.Error') 591 assert alias.name == 'Eina.Error'
564 self.assertEqual(alias.short_name, 'Error') 592 assert alias.short_name == 'Error'
565 self.assertIsInstance(alias.aliased_base, eolian.Type) 593 assert isinstance(alias.aliased_base, eolian.Type)
566 self.assertEqual(alias.aliased_base.name, 'int') 594 assert alias.aliased_base.name == 'int'
567 self.assertEqual(alias.c_type, 'typedef int Eina_Error') 595 assert alias.c_type == 'typedef int Eina_Error'
568 596
569 597
570class TestEolianType(unittest.TestCase): 598class TestEolianType(object):
571 def test_type_regular_builtin(self): 599 def test_type_regular_builtin(self, eolian_db):
572 cls = eolian_db.class_by_name_get('Efl.Loop_Timer') 600 cls = eolian_db.class_by_name_get('Efl.Loop_Timer')
573 func = cls.function_by_name_get('timer_delay') 601 func = cls.function_by_name_get('timer_delay')
574 param = list(func.parameters)[0] 602 param = list(func.parameters)[0]
575 t = param.type # type double 603 t = param.type # type double
576 self.assertIsInstance(t, eolian.Type) 604 assert isinstance(t, eolian.Type)
577 self.assertEqual(t.name, 'double') 605 assert t.name == 'double'
578 self.assertEqual(t.short_name, 'double') 606 assert t.short_name == 'double'
579 self.assertEqual(t.type, eolian.Eolian_Type_Type.REGULAR) 607 assert t.type == eolian.Eolian_Type_Type.REGULAR
580 self.assertEqual(t.builtin_type, eolian.Eolian_Type_Builtin_Type.DOUBLE) 608 assert t.builtin_type == eolian.Eolian_Type_Builtin_Type.DOUBLE
581 self.assertEqual(t.file, 'efl_loop_timer.eo') # TODO is this correct ? 609 assert t.file == 'efl_loop_timer.eo' # TODO is this correct ?
582 self.assertIsNone(t.base_type) # TODO find a better test 610 assert t.base_type is None # TODO find a better test
583 self.assertIsNone(t.next_type) # TODO find a better test 611 assert t.next_type is None # TODO find a better test
584 self.assertFalse(t.is_const) 612 assert t.is_const is False
585 self.assertFalse(t.is_ptr) 613 assert t.is_ptr is False
586 self.assertEqual(list(t.namespaces), []) 614 assert list(t.namespaces) == []
587 self.assertIsNone(t.class_) 615 assert t.class_ is None
588 self.assertEqual(t, t.aliased_base) # TODO find a better test 616 assert t == t.aliased_base # TODO find a better test
589 617
590 def test_type_regular(self): 618 def test_type_regular(self, eolian_db):
591 cls = eolian_db.class_by_name_get('Efl.Gfx.Entity') 619 cls = eolian_db.class_by_name_get('Efl.Gfx.Entity')
592 func = cls.function_by_name_get('geometry') 620 func = cls.function_by_name_get('geometry')
593 param = list(func.setter_values)[0] 621 param = list(func.setter_values)[0]
594 t = param.type # type Eina.Rect 622 t = param.type # type Eina.Rect
595 self.assertIsInstance(t, eolian.Type) 623 assert isinstance(t, eolian.Type)
596 self.assertEqual(t.name, 'Eina.Rect') 624 assert t.name == 'Eina.Rect'
597 self.assertEqual(t.short_name, 'Rect') 625 assert t.short_name == 'Rect'
598 self.assertEqual(t.type, eolian.Eolian_Type_Type.REGULAR) 626 assert t.type == eolian.Eolian_Type_Type.REGULAR
599 self.assertEqual(t.builtin_type, eolian.Eolian_Type_Builtin_Type.INVALID) 627 assert t.builtin_type == eolian.Eolian_Type_Builtin_Type.INVALID
600 self.assertEqual(t.file, 'efl_gfx_entity.eo') # TODO is this correct ? 628 assert t.file == 'efl_gfx_entity.eo' # TODO is this correct ?
601 self.assertEqual(list(t.namespaces), ['Eina']) 629 assert list(t.namespaces) == ['Eina']
602 self.assertIsNone(t.class_) 630 assert t.class_ is None
603 self.assertEqual(t, t.aliased_base) 631 assert t == t.aliased_base
604 632
605 td = t.typedecl 633 td = t.typedecl
606 self.assertIsInstance(td, eolian.Typedecl) 634 assert isinstance(td, eolian.Typedecl)
607 self.assertEqual(td.name, 'Eina.Rect') 635 assert td.name == 'Eina.Rect'
608 636
609 def test_type_class(self): 637 def test_type_class(self, eolian_db):
610 cls = eolian_db.class_by_name_get('Efl.Content') 638 cls = eolian_db.class_by_name_get('Efl.Content')
611 func = cls.function_by_name_get('content') 639 func = cls.function_by_name_get('content')
612 param = list(func.setter_values)[0] 640 param = list(func.setter_values)[0]
613 t = param.type # type Efl.Gfx (class interface) 641 t = param.type # type Efl.Gfx (class interface)
614 self.assertIsInstance(t, eolian.Type) 642 assert isinstance(t, eolian.Type)
615 self.assertEqual(t.name, 'Efl.Gfx.Entity') 643 assert t.name == 'Efl.Gfx.Entity'
616 self.assertEqual(t.short_name, 'Entity') 644 assert t.short_name == 'Entity'
617 self.assertEqual(t.type, eolian.Eolian_Type_Type.CLASS) 645 assert t.type == eolian.Eolian_Type_Type.CLASS
618 self.assertEqual(t.builtin_type, eolian.Eolian_Type_Builtin_Type.INVALID) 646 assert t.builtin_type == eolian.Eolian_Type_Builtin_Type.INVALID
619 self.assertEqual(t.file, 'efl_content.eo') # TODO is this correct ? 647 assert t.file == 'efl_content.eo' # TODO is this correct ?
620 self.assertEqual(list(t.namespaces), ['Efl', 'Gfx']) 648 assert list(t.namespaces) == ['Efl', 'Gfx']
621 self.assertEqual(t, t.aliased_base) 649 assert t == t.aliased_base
622 650
623 cls = t.class_ 651 cls = t.class_
624 self.assertIsInstance(cls, eolian.Class) 652 assert isinstance(cls, eolian.Class)
625 self.assertEqual(cls.name, 'Efl.Gfx.Entity') 653 assert cls.name == 'Efl.Gfx.Entity'
626 654
627 655
628class TestEolianExpression(unittest.TestCase): 656class TestEolianExpression(object):
629 def test_expression_simple(self): 657 def test_expression_simple(self, eolian_db):
630 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version') 658 td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
631 field = td.enum_field_get('v1_0') 659 field = td.enum_field_get('v1_0')
632 exp = field.value 660 exp = field.value
633 self.assertIsInstance(exp, eolian.Expression) 661 assert isinstance(exp, eolian.Expression)
634 self.assertEqual(exp.type, eolian.Eolian_Expression_Type.INT) 662 assert exp.type == eolian.Eolian_Expression_Type.INT
635 self.assertEqual(exp.serialize, '100') 663 assert exp.serialize == '100'
636 664
637 def test_expression_unary(self): 665 def test_expression_unary(self, eolian_db):
638 var = eolian_db.constant_by_name_get('Efl.Gfx.Stack_Layer_Min') 666 var = eolian_db.constant_by_name_get('Efl.Gfx.Stack_Layer_Min')
639 exp = var.value 667 exp = var.value
640 self.assertIsInstance(exp, eolian.Expression) 668 assert isinstance(exp, eolian.Expression)
641 self.assertEqual(exp.type, eolian.Eolian_Expression_Type.UNARY) 669 assert exp.type == eolian.Eolian_Expression_Type.UNARY
642 self.assertEqual(float(exp.serialize), 32768.0) # TODO is this a bug? isn't -1.0 ? 670 assert float(exp.serialize) == 32768.0 # TODO is this a bug? isn't -1.0 =
643 self.assertEqual(exp.unary_operator, eolian.Eolian_Unary_Operator.UNM) # Invalid -> NOP 671 assert exp.unary_operator == eolian.Eolian_Unary_Operator.UNM # Invalid -> NO
644 unary = exp.unary_expression 672 unary = exp.unary_expression
645 self.assertIsInstance(unary, eolian.Expression) 673 assert isinstance(unary, eolian.Expression)
646 self.assertEqual(unary.type, eolian.Eolian_Expression_Type.INT) 674 assert unary.type == eolian.Eolian_Expression_Type.INT
647 self.assertEqual(float(exp.serialize), 32768.0) # Bug too? 675 assert float(exp.serialize) == 32768.0 # Bug too ?
648 676
649 # TODO test_expression_binary 677 # TODO test_expression_binary
650 # exp.binary_operator # TODO find a better test (only works for BINARY expr) 678 # exp.binary_operator # TODO find a better test (only works for BINARY expr)
651 # exp.binary_lhs # TODO find a better test (only works for BINARY expr) 679 # exp.binary_lhs # TODO find a better test (only works for BINARY expr)
652 # exp.binary_rhs # TODO find a better test (only works for BINARY expr) 680 # exp.binary_rhs # TODO find a better test (only works for BINARY expr)
653
654
655if __name__ == '__main__':
656 # create main eolian state
657 eolian_db = eolian.Eolian_State()
658 if not isinstance(eolian_db, eolian.Eolian_State):
659 raise(RuntimeError('Eolian, failed to create Eolian state'))
660
661 # eolian system scan (BROKEN)
662 # if not eolian_db.system_directory_add():
663 # raise(RuntimeError('Eolian, failed to scan system directories'))
664
665 # eolian source tree scan
666 if not eolian_db.directory_add(SCAN_FOLDER):
667 raise(RuntimeError('Eolian, failed to scan source directory'))
668
669 # Parse all known eo files
670 if not eolian_db.all_eot_files_parse():
671 raise(RuntimeError('Eolian, failed to parse all EOT files'))
672
673 if not eolian_db.all_eo_files_parse():
674 raise(RuntimeError('Eolian, failed to parse all EO files'))
675
676 # start the test suite
677 suite = unittest.main(verbosity=2, exit=False)
678
679 # cleanup (or it will segfault on gc, that happend after atexit)
680 del eolian_db
681
682 # exit 0 (success) or 1 (failure)
683 exit(0 if suite.result.wasSuccessful() else 1)