devtools/testlib.py
changeset 3720 5376aaadd16b
parent 3676 fa170564e1a0
parent 3689 deb13e88e037
child 3734 b2107f68176c
equal deleted inserted replaced
3678:29f74716fd70 3720:5376aaadd16b
    42     def do_view(self, arg):
    42     def do_view(self, arg):
    43         import webbrowser
    43         import webbrowser
    44         data = self._getval(arg)
    44         data = self._getval(arg)
    45         file('/tmp/toto.html', 'w').write(data)
    45         file('/tmp/toto.html', 'w').write(data)
    46         webbrowser.open('file:///tmp/toto.html')
    46         webbrowser.open('file:///tmp/toto.html')
    47 
       
    48 
    47 
    49 def line_context_filter(line_no, center, before=3, after=None):
    48 def line_context_filter(line_no, center, before=3, after=None):
    50     """return true if line are in context
    49     """return true if line are in context
    51 
    50 
    52     if after is None: after = before
    51     if after is None: after = before
   713     cardinality
   712     cardinality
   714     """
   713     """
   715     # compute how many entities by type we need to be able to satisfy relation constraint
   714     # compute how many entities by type we need to be able to satisfy relation constraint
   716     relmap = {}
   715     relmap = {}
   717     for rschema in schema.relations():
   716     for rschema in schema.relations():
   718         if rschema.is_final():
   717         if rschema.final:
   719             continue
   718             continue
   720         for subj, obj in rschema.iter_rdefs():
   719         for subj, obj in rschema.iter_rdefs():
   721             card = rschema.rproperty(subj, obj, 'cardinality')
   720             card = rschema.rproperty(subj, obj, 'cardinality')
   722             if card[0] in '1?' and len(rschema.subjects(obj)) == 1:
   721             if card[0] in '1?' and len(rschema.subjects(obj)) == 1:
   723                 relmap.setdefault((rschema, subj), []).append(str(obj))
   722                 relmap.setdefault((rschema, subj), []).append(str(obj))
   757         pass
   756         pass
   758 
   757 
   759     def post_populate(self, cursor):
   758     def post_populate(self, cursor):
   760         pass
   759         pass
   761 
   760 
       
   761 
   762     @nocoverage
   762     @nocoverage
   763     def auto_populate(self, how_many):
   763     def auto_populate(self, how_many):
   764         """this method populates the database with `how_many` entities
   764         """this method populates the database with `how_many` entities
   765         of each possible type. It also inserts random relations between them
   765         of each possible type. It also inserts random relations between them
   766         """
   766         """
   777         edict = {}
   777         edict = {}
   778         for etype in unprotected_entities(self.schema, strict=True):
   778         for etype in unprotected_entities(self.schema, strict=True):
   779             rset = cu.execute('%s X' % etype)
   779             rset = cu.execute('%s X' % etype)
   780             edict[str(etype)] = set(row[0] for row in rset.rows)
   780             edict[str(etype)] = set(row[0] for row in rset.rows)
   781         existingrels = {}
   781         existingrels = {}
   782         ignored_relations = SYSTEM_RELATIONS | set(self.ignored_relations)
   782         ignored_relations = SYSTEM_RELATIONS + self.ignored_relations
   783         for rschema in self.schema.relations():
   783         for rschema in self.schema.relations():
   784             if rschema.is_final() or rschema in ignored_relations:
   784             if rschema.final or rschema in ignored_relations:
   785                 continue
   785                 continue
   786             rset = cu.execute('DISTINCT Any X,Y WHERE X %s Y' % rschema)
   786             rset = cu.execute('DISTINCT Any X,Y WHERE X %s Y' % rschema)
   787             existingrels.setdefault(rschema.type, set()).update((x, y) for x, y in rset)
   787             existingrels.setdefault(rschema.type, set()).update((x, y) for x, y in rset)
   788         q = make_relations_queries(self.schema, edict, cu, ignored_relations,
   788         q = make_relations_queries(self.schema, edict, cu, ignored_relations,
   789                                    existingrels=existingrels)
   789                                    existingrels=existingrels)