def test_split_exprn_single_exprn(self): one_brack = '(Hello world)' exp_atomic = ['Hello world'] exp_conn = [] test_atomic, test_conn = man.split_exprn(one_brack) self.assertEqual(exp_atomic, test_atomic) self.assertEqual(exp_conn, test_conn)
def test_split_exprn_two_sub_exprn(self): two_sub_exprn = '((Hello world) Y (Bye world))' exp_atomic = ['Hello world', 'Bye world'] exp_conn = [' Y '] test_atomic, test_conn = man.split_exprn(two_sub_exprn) self.assertEqual(exp_atomic, test_atomic) self.assertEqual(exp_conn, test_conn)
def test_split_exprn_no_brackets(self): no_bracks = 'Hello world' exp_atomic = [no_bracks] exp_conn = [] test_atomic, test_conn = man.split_exprn(no_bracks) self.assertEqual(exp_atomic, test_atomic) self.assertEqual(exp_conn, test_conn)
def eval_onde(line, tables): ''' Evaluate a ONDE query :param line: ONDE query without the 'ONDE ' keyword :param tables: a dict {tname: tb} :return: a dict {tname: filtered_tb} ''' # Get atomic conditional statement and connectives from line atomics, conn = man.split_exprn(line) # all the filtered indexes from each condition statement f_cols_lst = [eval_cond(cond, tables) for cond in atomics] # Reduce the list of dicts to one single dict by joining them together # by the connectives join = lambda ind1, ind2: man.join_filt_indexes(tables.keys(), ind1, ind2, conn.pop(0)) f_cols = fct.reduce(join, f_cols_lst) if not isinstance(f_cols, bool): # If ONDE consists of only an EXISTE(...) clause then there is no need # to filter tables return man.filter_tables(tables, f_cols) elif f_cols: # f_cols is a boolean value, i.e. a single EXISTE(...) clause, return # tables if it is True, else raise TerminateQueryError return tables elif not f_cols: raise hpr.TerminateQueryError('Existe condition is False') else: raise hpr.InvalidQueryError('Something is wrong with the query')
def test_split_exprn_inner_and(self): exprn = '((encuentro_pokemon_id = pokemon_id) Y ' \ '(encuentro_min ENTRE (30 Y 60)))' expected = ['encuentro_pokemon_id = pokemon_id', 'encuentro_min ENTRE (30 Y 60)'] exp_conn = [' Y '] test_atomic, test_conn = man.split_exprn(exprn) self.assertEqual(test_atomic, expected) self.assertEqual(test_conn, exp_conn)
def test_split_exprn_outside_exprn(self): two_atomics = "((EXISTE (EMPRESTA estadistica_nombre DE estadisticas))"\ " Y (pokemon_nombre PARECIO A 'pikachu'))" exp_atomic = ['EXISTE (EMPRESTA estadistica_nombre DE estadisticas)', "pokemon_nombre PARECIO A 'pikachu'"] exp_conn = [' Y '] test_atomic, test_conn = man.split_exprn(two_atomics) self.assertEqual(exp_atomic, test_atomic) self.assertEqual(exp_conn, test_conn)
def test_split_exprn_inner_and(self): exprn = '((encuentro_pokemon_id = pokemon_id) Y ' \ '(encuentro_min ENTRE (30 Y 60)))' expected = [ 'encuentro_pokemon_id = pokemon_id', 'encuentro_min ENTRE (30 Y 60)' ] exp_conn = [' Y '] test_atomic, test_conn = man.split_exprn(exprn) self.assertEqual(test_atomic, expected) self.assertEqual(test_conn, exp_conn)
def test_split_exprn_outside_exprn(self): two_atomics = "((EXISTE (EMPRESTA estadistica_nombre DE estadisticas))"\ " Y (pokemon_nombre PARECIO A 'pikachu'))" exp_atomic = [ 'EXISTE (EMPRESTA estadistica_nombre DE estadisticas)', "pokemon_nombre PARECIO A 'pikachu'" ] exp_conn = [' Y '] test_atomic, test_conn = man.split_exprn(two_atomics) self.assertEqual(exp_atomic, test_atomic) self.assertEqual(exp_conn, test_conn)