def test_names(): from xotl.ql.core import get_predicate_object, normalize_query, this def f(a=100): return lambda y: global_sentinel < y < a pred = get_predicate_object(f()) assert pred.qst assert pred.get_name('a') == 100 # Test that globals may change global global_sentinel assert pred.get_name('global_sentinel') == global_sentinel global_sentinel = 90 assert pred.get_name('global_sentinel') == global_sentinel try: get_predicate_object(f) except: pass # not an expression else: assert False q = normalize_query(x for x in this) assert q.get_name('.0') is this assert '.0' in q.locals assert 'x' not in q.locals assert 'global_sentinel' in q.globals assert '1qwwee' not in q.globals
def test_expr(): query = normalize_query(generator) assert query.qst if names: for name, val in names.items(): if val is not Unset: val = query.get_name(name) else: try: query.get_name(name) except: raise else: pass
def test_queries(): queries = [ (e for e in this), ((x for x in e) for e in this), (e for e in (x for x in this)), (e for e in this if e(y for y in this)), (e for e in this if any(x for x in e)), (x for x, y in this), (x for x[1] in this), # noqa (x for x.y in this), # noqa ] for generator in queries: query = normalize_query(generator) assert query.qst
def __init__(self, query, map=None, join=None, zero=None, unit=None, use_own_monads=False): # The map, join, zero, and unit are provided for tests. self.query = query = normalize_query(query) self.map = '__x_map_%s' % id(self) if not map else map self.join = '__x_join_%s' % id(self) if not join else join self.zero = '__x_zero_%s' % id(self) if not zero else zero self.unit = '__x_unit_%s' % id(self) if not unit else unit self.use_own_monads = use_own_monads self.plan = plan = mcompile( query.qst, map=self.map, join=self.join, zero=self.zero, unit=self.unit ) self.compiled = compile(plan, '', 'eval')