Example #1
0
 def test_query_with_conditional_comparators(self):
     exp_e4 = ['10002004 | 1981 | 1',
               '10046101 | 1950 | 1']
     t_e4 = man.printable(consult.raw_query(self.e4, self.personas_tb))
     for s in exp_e4:
         self.assertIn(s, t_e4, '\nRaw query failed: \n'
                       'Expected:\n{0}\n'
                       'Test:\n{1}'.format(exp_e4, t_e4))
     exp_e5 = ['10003001 | 1933 | 1',
               '10002004 | 1981 | 1',
               '10002005 | 1995 | 1']
     t_e5 = man.printable(consult.raw_query(self.e5, self.personas_tb))
     for s in exp_e5:
         self.assertIn(s, t_e5, '\nRaw query failed: \n'
                       'Expected:\n{0}\n'
                       'Test:\n{1}'.format(exp_e5, t_e5))
     exp_e6 = ['338 | EL BOSQUE', '998 | NO ESPECIFICA']
     t_e6 = man.printable(consult.raw_query(self.e6, self.comunas_tb))
     for s in exp_e6:
         self.assertIn(s, t_e6, '\nRaw query failed: \n'
                       'Expected:\n{0}\n'
                       'Test:\n{1}'.format(exp_e6, t_e6))
     exp_e7 = ['10 | CALAMA', '13 | COPIAPO']
     t_e7 = man.printable(consult.raw_query(self.e7, self.comunas_tb))
     for s in exp_e7:
         self.assertIn(s, t_e7, '\nRaw query on e5 failed: \n'
                      'Expected:\n{0}\n'
                      'Test:\n{1}'.format(exp_e7, t_e7))
Example #2
0
def proc_consult_file(consult_file, result_file):
    tbs, consults = cns.get_consults(consult_file)
    result_f = open(result_file, 'a')

    for i in range(len(consults)):
        c = consults[i]
        hpr.log(TESTING, 'At consult: {0}'.format(c))
        to_file = '------- CONSULTA {0} -------\n'.format(i + 1)
        try:
            to_file += man.printable(cns.raw_query(c, tbs))
        except ValueError as ve:
            print('Error: {0}'.format(ve))
            to_file += 'FALLIDA'
        except hpr.InvalidQueryError as iqe:
            print('Error: {0}'.format(iqe))
            to_file += 'FALLIDA'
        except hpr.TerminateQueryError as tqe:
            print('Query terminated: {0}'.format(tqe))
            # Append an empty line
            to_file += '\n'
        except Exception as e:
            print('Error: {0}'.format(e))
            to_file += 'FALLIDA'
        finally:
            print('Completed consult {0}.'.format(i + 1))

        print(to_file, end='\n', file=result_f)
        hpr.log(TESTING, '\nConsult {0}: {1}'.format(i + 1, c))
        hpr.log(TESTING, to_file)
    result_f.close()
    return tbs
Example #3
0
def proc_consult_file(consult_file, result_file):
    tbs, consults = cns.get_consults(consult_file)
    result_f = open(result_file, 'a')

    for i in range(len(consults)):
        c = consults[i]
        hpr.log(TESTING, 'At consult: {0}'.format(c))
        to_file = '------- CONSULTA {0} -------\n'.format(i + 1)
        try:
            to_file += man.printable(cns.raw_query(c, tbs))
        except ValueError as ve:
            print('Error: {0}'.format(ve))
            to_file += 'FALLIDA'
        except hpr.InvalidQueryError as iqe:
            print('Error: {0}'.format(iqe))
            to_file += 'FALLIDA'
        except hpr.TerminateQueryError as tqe:
            print('Query terminated: {0}'.format(tqe))
            # Append an empty line
            to_file += '\n'
        except Exception as e:
            print('Error: {0}'.format(e))
            to_file += 'FALLIDA'
        finally:
            print('Completed consult {0}.'.format(i + 1))

        print(to_file, end='\n', file=result_f)
        hpr.log(TESTING, '\nConsult {0}: {1}'.format(i + 1, c))
        hpr.log(TESTING, to_file)
    result_f.close()
    return tbs
Example #4
0
def loop_consult(tbs, rows):
    in_loop = True

    while in_loop:
        query = input('\nPlease enter valid query:\n')
        if query:
            try:
                selected_rows = select_rows(cns.raw_query(query, tbs), rows)
                print(man.printable(selected_rows))
            except ValueError as ve:
                print('Error: {0}'.format(ve))
            except hpr.InvalidQueryError as iqe:
                print('Error: {0}'.format(iqe))
            except hpr.TerminateQueryError as tqe:
                print('\n')
            except Exception as e:
                print('Error: {0}'.format(e))
        else:
            in_loop = False
Example #5
0
def loop_consult(tbs, rows):
    in_loop = True

    while in_loop:
        query = input('\nPlease enter valid query:\n')
        if query:
            try:
                selected_rows = select_rows(cns.raw_query(query, tbs), rows)
                print(man.printable(selected_rows))
            except ValueError as ve:
                print('Error: {0}'.format(ve))
            except hpr.InvalidQueryError as iqe:
                print('Error: {0}'.format(iqe))
            except hpr.TerminateQueryError as tqe:
                print('\n')
            except Exception as e:
                print('Error: {0}'.format(e))
        else:
            in_loop = False
Example #6
0
 def test_query_ten(self):
     test = list(consult.raw_query(tquery.query10, self.tables))
     test_rows = [row[0] for row in test]
     self.assertEqual(set(test_rows), set(tquery.query10_res))
Example #7
0
 def test_query_extra_two(self):
     query = 'EMPRESTA pokemon_id DE pokemon ONDE ' \
             '(EXISTE (EMPRESTA estadistica_nombre DE estadisticas));'
     test = list(consult.raw_query(query, self.tables))
     self.assertIsNotNone(test)
Example #8
0
 def test_query_extra(self):
     query = 'EMPRESTA estadistica_nombre DE estadisticas;'
     test = list(consult.raw_query(query, self.tables))
     self.assertIsNotNone(test)
Example #9
0
 def test_query_six(self):
     test = list(consult.raw_query(tquery.query6, self.tables))
     test_rows = [row[0] for row in test]
     self.assertEqual(test_rows, tquery.query6_res)
Example #10
0
 def test_query_five(self):
     test = list(consult.raw_query(tquery.query5, self.tables))[:15]
     test_rows = [row[0] for row in test]
     self.assertEqual(test_rows, tquery.query5_res)
Example #11
0
 def test_query_one(self):
     test = list(consult.raw_query(tquery.query1, self.tables))[:15]
     test_rows = [row[0] for row in test]
     # Check the first 15 rows
     self.assertEqual(test_rows, tquery.query1_res)