diff --git a/test/unittest_analyze.py b/test/unittest_analyze.py index 355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_dGVzdC91bml0dGVzdF9hbmFseXplLnB5..46ea8a04429ce7bf7685f4cb98a7d6dc1d6211f8_dGVzdC91bml0dGVzdF9hbmFseXplLnB5 100644 --- a/test/unittest_analyze.py +++ b/test/unittest_analyze.py @@ -1,7 +1,6 @@ from logilab.common.testlib import TestCase, unittest_main from rql import RQLHelper, TypeResolverException -from rql.analyze import UnifyingETypeResolver, ETypeResolver FINAL_ETYPES = ('String', 'Boolean', 'Int', 'Float', 'Date', 'Datetime') @@ -5,7 +4,7 @@ FINAL_ETYPES = ('String', 'Boolean', 'Int', 'Float', 'Date', 'Datetime') -class ERSchema: +class ERSchema(object): def __cmp__(self, other): other = getattr(other, 'type', other) @@ -49,32 +48,28 @@ def is_final(self): return self.type in FINAL_ETYPES -class DummySchema: - _types = {} - for type in ['String', 'Boolean', 'Int', 'Float', 'Date', - 'Eetype', 'Person', 'Company', 'Address']: - _types[type] = EntitySchema(type) - - _relations = { - 'eid' : RelationSchema( ( ('Person', ('Int',) ), - ('Company', ('Int',) ), - ('Address', ('Int',) ), - ('Eetype', ('Int',) ), - ) - ), - 'creation_date' : RelationSchema( ( ('Person', ('Datetime',) ), - ('Company', ('Datetime',) ), - ('Address', ('Datetime',) ), - ('Eetype', ('Datetime',) ), - ) - ), - 'name' : RelationSchema( ( ('Person', ('String',) ), - ('Company', ('String',) ), - ) - ), - 'firstname' : RelationSchema( ( ('Person', ('String',) ), - ) - ), - 'work_for' : RelationSchema( ( ('Person', ('Company',) ), +class DummySchema(object): + + def __init__(self): + self._types = {} + for etype in ['String', 'Boolean', 'Int', 'Float', 'Date', + 'Eetype', 'Person', 'Company', 'Address']: + self._types[etype] = EntitySchema(etype) + + self._relations = { + 'eid' : RelationSchema( ( ('Person', ('Int',) ), + ('Company', ('Int',) ), + ('Address', ('Int',) ), + ('Eetype', ('Int',) ), + ) + ), + 'creation_date' : RelationSchema( ( ('Person', ('Datetime',) ), + ('Company', ('Datetime',) ), + ('Address', ('Datetime',) ), + ('Eetype', ('Datetime',) ), + ) + ), + 'name' : RelationSchema( ( ('Person', ('String',) ), + ('Company', ('String',) ), ) ), @@ -79,14 +74,13 @@ ) ), - 'is' : RelationSchema( ( ('Person', ('Eetype',) ), - ('Company', ('Eetype',) ), - ('Address', ('Eetype',) ), - ) - ), - 'connait' : RelationSchema( (('Person', ('Person',) ), - ), - symetric=True), - 'located' : RelationSchema( ( ('Person', ('Address',) ), - ('Company', ('Address',) ), + 'firstname' : RelationSchema( ( ('Person', ('String',) ), + ) + ), + 'work_for' : RelationSchema( ( ('Person', ('Company',) ), + ) + ), + 'is' : RelationSchema( ( ('Person', ('Eetype',) ), + ('Company', ('Eetype',) ), + ('Address', ('Eetype',) ), ) ), @@ -91,17 +85,25 @@ ) ), - 'owned_by' : RelationSchema( ( ('Person', ('Person',) ), - ('Company', ('Person',) ), - ('Eetype', ('Person',) ), - ) - ), - 'identity' : RelationSchema( ( ('Person', ('Person',) ), - ('Company', ('Company',) ), - ('Address', ('Address',) ), - ('Eetype', ('Eetype',) ), - ) - ), - } + 'connait' : RelationSchema( (('Person', ('Person',) ), + ), + symetric=True), + 'located' : RelationSchema( ( ('Person', ('Address',) ), + ('Company', ('Address',) ), + ) + ), + 'owned_by' : RelationSchema( ( ('Person', ('Person',) ), + ('Company', ('Person',) ), + ('Eetype', ('Person',) ), + ) + ), + 'identity' : RelationSchema( ( ('Person', ('Person',) ), + ('Company', ('Company',) ), + ('Address', ('Address',) ), + ('Eetype', ('Eetype',) ), + ) + ), + } + def entities(self): return self._types.values() diff --git a/test/unittest_compare.py b/test/unittest_compare.py index 355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_dGVzdC91bml0dGVzdF9jb21wYXJlLnB5..46ea8a04429ce7bf7685f4cb98a7d6dc1d6211f8_dGVzdC91bml0dGVzdF9jb21wYXJlLnB5 100644 --- a/test/unittest_compare.py +++ b/test/unittest_compare.py @@ -4,8 +4,4 @@ from unittest_analyze import RelationSchema, EntitySchema, DummySchema as BaseSchema class DummySchema(BaseSchema): - _types = BaseSchema._types - - for type in ['Note',]: - _types[type] = EntitySchema(type) @@ -11,15 +7,16 @@ - _relations = BaseSchema._relations - - _relations['a_faire_par'] = RelationSchema( ( ('Note', ('Person',)), - ) - ) - _relations['creation_date'] = RelationSchema( ( ('Note', ('Date',)), - ) - ) - _relations['nom'] = _relations['name'] - _relations['prenom'] = _relations['firstname'] - + def __init__(self): + super(DummySchema, self).__init__() + for etype in ['Note',]: + self._types[etype] = EntitySchema(etype) + relations = [('a_faire_par', (('Note', ('Person',)),)), + ('creation_date', (('Note', ('Date',)),)), + ] + for rel_name, rel_ent in relations: + self._relations[rel_name] = RelationSchema(rel_ent) + self._relations['nom'] = self._relations['name'] + self._relations['prenom'] = self._relations['firstname'] + class RQLCompareClassTest(TestCase): """ Compare RQL strings """