def listgroups(t): currentgroup = None count = 0 for test in flatten(t): count += 1 if test.group != currentgroup: if currentgroup: print currentgroup, count currentgroup = test.group count = 0 if currentgroup: print currentgroup, count print 'total:', len(list(flatten(t)))
def filter(self, conditions=None, hints=None): for left, right in joinTuples(self.left, self.right, self.joinFunc): row = left + right if conditions: for key, value in conditions.iteritems(): if flatten(row[key]) != value: #XXX #print '@@@@skipped@@@', row[key], '!=', repr(value), flatten(row[key]) break else: yield row else: yield row
def _getStatementsForResources(self, resources): stmts = [] for r in resources: currentStmts = self.model.getStatements(r) for s in currentStmts: #it's an RDF list, we need to follow all the nodes and remove them too if s.predicate == base.RDF_SCHEMA_BASE+u'next': while s: listNodeStmts = self.model.getStatements(s.object) stmts.extend(listNodeStmts) s = flatten([ls for ls in listNodeStmts if ls.predicate == base.RDF_SCHEMA_BASE+u'next']) assert not isinstance(s, list) stmts.extend(currentStmts) return stmts
def main(t, cmdargs=None): from optparse import OptionParser usage = "usage: %prog [options] [group name] [number]" parser = OptionParser(usage) for name, default in [('printmodel', 0), ('printast', 0), ('explain', 0), ('printdebug', 0), ('printrows', 0), ('quiet',0), ('listgroups',0), ('printdocs',0), ('skip', 0), ('dontabort', 0)]: parser.add_option('--'+name, dest=name, default=default, action="store_true") (options, args) = parser.parse_args(cmdargs) if options.listgroups: listgroups(t) return options.num = -1 options.group = None if args and args[0] != 'null': if len(args) > 1: options.group = args[0] options.num = int(args[1]) else: try: options.num = int(args[0]) except: options.group = args[0] count = 0 skipped = 0 failed = 0 currentgroup = None groupcount = 0 lastmodelid = None for (i, test) in enumerate(flatten(t)): if test.group != currentgroup: currentgroup = test.group groupcount = 0 else: groupcount += 1 if options.group: if options.skip: if options.group == currentgroup: if options.num == -1 or groupcount == options.num: skipped += 1 continue elif options.group != currentgroup: skipped += 1 continue if options.num > -1: if options.skip: if i == options.num: skipped += 1 continue else: if options.group: if groupcount != options.num: skipped += 1 continue elif i != options.num: skipped += 1 continue if test.skip: skipped += 1 continue count += 1 if test.name: name = test.name elif test.group: name = '%s %d' % (test.group, groupcount) else: name = "%d" % i if options.printdocs: options.quiet = True printdocs(test) continue if not options.quiet and not options.dontabort: print '*** running test:', name try: print 'query', test.query or test.ast except UnicodeEncodeError: print 'query', test.query.strip().encode('unicode_escape') if options.printmodel and id(test.model) != lastmodelid: lastmodelid = id(test.model) print 'model' pprint.pprint(list(test.model)) if test.ast: if not test.skipParse and test.query: try: (testast, errs) = jql.buildAST(test.query) except: if test.ast != 'error': raise testast = None if not options.quiet: print 'comparing ast' if test.ast == 'error': #expect an error if not options.quiet: print 'expected error in test', name assert testast is None, ( 'not expecting an ast for test %d: %s' % (i,testast)) else: if isinstance(test.ast, (str,unicode)): ast = jql.buildAST(test.ast)[0] else: ast = test.ast assert testast == ast, ( 'unexpected ast for test %d: %s \n %s' % (i, findfirstdiff(testast, ast), testast)) ast = testast else: ast = test.ast else: if isinstance(test.query, QueryOp): ast = test.query else: (ast, errs) = jql.buildAST(test.query) assert ast, "ast is None, parsing failed" if options.printast: print "ast:" pprint.pprint(ast) if options.printrows or test.rows is not None: if ast: evalAst = ast.where testrows = list(jql.evalAST(evalAst, test.model, test.bindvars)) else: testrows = None if options.printrows: print 'labels', evalAst.labels print 'rows:' pprint.pprint(testrows) if test.rows is not None: assert test.rows== testrows, ('unexpected rows for test %d' % i) if options.explain: print "explain plan:" explain = sys.stdout else: explain = None if options.printdebug or test.printdebug: debug = sys.stdout else: debug = None if ast: testresults = list(jql.evalAST(ast, test.model, test.bindvars, explain=explain, debug=debug, forUpdate = test.forUpdate, useSerializer= test.useSerializer)) else: testresults = None if not options.quiet and not options.dontabort: print "Construct Results:", (options.printdebug and '(with debug)' or '') pprint.pprint(testresults) def printDontAbortMsg(errMsg): print '*** running test:', name print 'query', test.query print "Construct Results:", (options.printdebug and '(with debug)' or '') pprint.pprint(testresults) print errMsg if test.results is not None: resultsMatch = test.results == testresults if not resultsMatch and test.unordered: unorderedMatch = sorted(test.results) == sorted(testresults) errMsg = 'unexpected (unordered) results for test %d' % i if not unorderedMatch and options.dontabort: printDontAbortMsg(errMsg) failed += 1 continue else: assert unorderedMatch, errMsg if not options.quiet: print "warning: unexpected order for (unordered) test %d" % i else: errMsg = 'unexpected results for test %d' % i if not resultsMatch and options.dontabort: printDontAbortMsg(errMsg) failed += 1 continue else: assert resultsMatch, errMsg if not options.printdocs: print '***** %d tests passed, %d failed, %d skipped' % (count-failed, failed, skipped) elif t._nextdoc: print '\n'.join(t._nextdoc)