Skip to content

Commit a3d10f6

Browse files
committed
add psql failure tests
1 parent 653cd50 commit a3d10f6

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
# -*- coding: utf-8 -*-
22

3-
from .utils import _test_parsing
4-
5-
from queryparser.postgresql import PostgreSQLQueryProcessor
6-
from queryparser.exceptions import QueryError, QuerySyntaxError
7-
83
import os
4+
95
import pytest
106
import yaml
117

8+
from queryparser.exceptions import QueryError, QuerySyntaxError
9+
from queryparser.postgresql import PostgreSQLQueryProcessor
10+
11+
from .utils import _test_failure_parsing, _test_parsing
1212

1313
with open(os.path.dirname(__file__) + '/tests.yaml') as f:
1414
tests = yaml.load(f, Loader=yaml.FullLoader)
1515

1616

17-
@pytest.mark.parametrize("t", tests['common_tests'])
18-
def test_postgresql_parsing_common(t):
19-
_test_parsing(PostgreSQLQueryProcessor, t)
17+
# @pytest.mark.parametrize("t", tests['common_tests'])
18+
# def test_postgresql_parsing_common(t):
19+
# _test_parsing(PostgreSQLQueryProcessor, t)
20+
2021

22+
# @pytest.mark.parametrize('t', tests['postgresql_tests'])
23+
# def test_postgresql_parsing(t):
24+
# _test_parsing(PostgreSQLQueryProcessor, t)
2125

22-
@pytest.mark.parametrize("t", tests['postgresql_tests'])
23-
def test_postgresql_parsing(t):
24-
_test_parsing(PostgreSQLQueryProcessor, t)
2526

27+
# @pytest.mark.parametrize("t", tests['common_syntax_tests'])
28+
# def test_postgresql_syntax(t):
29+
# with pytest.raises(QuerySyntaxError):
30+
# PostgreSQLQueryProcessor(t)
2631

27-
@pytest.mark.parametrize("t", tests['common_syntax_tests'])
28-
def test_postgresql_syntax(t):
29-
with pytest.raises(QuerySyntaxError):
30-
PostgreSQLQueryProcessor(t)
3132

33+
# @pytest.mark.parametrize("t", tests['common_query_tests'])
34+
# def test_postrgresql_query(t):
35+
# with pytest.raises(QueryError):
36+
# PostgreSQLQueryProcessor(t)
3237

33-
@pytest.mark.parametrize("t", tests['common_query_tests'])
34-
def test_postrgresql_query(t):
35-
with pytest.raises(QueryError):
36-
PostgreSQLQueryProcessor(t)
3738

39+
@pytest.mark.parametrize('t', tests['postgresql_failure_tests'])
40+
def test_postgresql_failure_parsing(t):
41+
_test_failure_parsing(PostgreSQLQueryProcessor, t)

src/queryparser/testing/tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,22 @@ postgresql_tests:
838838
-
839839
- ["QMOST_SPEC_IS_IN_SURVEY"]
840840

841+
postgresql_failure_tests:
842+
-
843+
- SELECT specuid, ra, dec FROM dr1.spectrum WHERE QMOST_SPEC_IS_IN_SURVEY(specuid, '04');
844+
-
845+
- []
846+
847+
-
848+
- SELECT specuid, ra, dec FROM dr1.spectrum WHERE BLA(specuid, '04');
849+
-
850+
- [QMOST_SPEC_IS_IN_SURVEY]
851+
852+
-
853+
- SELECT specuid, ra, dec FROM dr1.spectrum WHERE QMOST_SPEC_IS_IN_SURVEY[specuid, '04'];
854+
-
855+
- [QMOST_SPEC_IS_IN_SURVEY]
856+
841857

842858
adql_mysql_tests:
843859
-

src/queryparser/testing/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
import pytest
23

34
from queryparser.adql import ADQLQueryTranslator
5+
from queryparser.exceptions import QuerySyntaxError
46
from queryparser.mysql import MySQLQueryProcessor
57
from queryparser.postgresql import PostgreSQLQueryProcessor
68

@@ -76,3 +78,24 @@ def _test_parsing(query_processor, test, translate=False):
7678

7779
if tables is not None:
7880
assert set(tables) == set(qp_tables)
81+
82+
83+
def _test_failure_parsing(query_processor, test, translate=False):
84+
query, replace_schema_name, replace_function_names = test
85+
86+
if translate:
87+
adt = ADQLQueryTranslator()
88+
adt.set_query(query)
89+
if query_processor == MySQLQueryProcessor:
90+
query = adt.to_mysql()
91+
elif query_processor == PostgreSQLQueryProcessor:
92+
query = adt.to_postgresql()
93+
94+
qp = query_processor()
95+
qp.set_query(query)
96+
97+
with pytest.raises(QuerySyntaxError):
98+
qp.process_query(
99+
replace_schema_name=replace_schema_name,
100+
replace_function_names=replace_function_names,
101+
)

0 commit comments

Comments
 (0)