Skip to content

Commit

Permalink
test: add tests for _adql_parameter and _adql_name
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Oct 19, 2023
1 parent 7937a85 commit bdabefa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion astroquery/simbad/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _adql_name(name: str):
name : str
The column name.
"""
return f'''lowercase("{'.'.join([f'"{element}"' for element in name.split(".")])}")'''
return f'''lowercase({'.'.join([f'"{element}"' for element in name.split(".")])})'''


error_regex = re.compile(r'(?ms)\[(?P<line>\d+)\]\s?(?P<msg>.+?)(\[|\Z)')
Expand Down
15 changes: 15 additions & 0 deletions astroquery/simbad/tests/test_simbad.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def test_simbad_create_tap_service():
assert 'simbad/sim-tap' in simbadtap.baseurl


def test_adql_parameter():
# escape single quotes
assert simbad.core._adql_parameter("Barnard's galaxy") == "Barnard''s galaxy"


def test_adql_name():
assert simbad.core._adql_name("biblio.year") == 'lowercase("biblio"."year")'


@pytest.mark.parametrize(('radius', 'expected_radius'),
[('5d0m0s', '5.0d'),
('5d', '5.0d'),
Expand Down Expand Up @@ -473,12 +482,18 @@ def test_simbad_tables():


def test_simbad_columns():
# with three table names
columns_adql = ("SELECT table_name, column_name, datatype, description, unit, ucd"
" FROM TAP_SCHEMA.columns "
"WHERE table_name NOT LIKE 'TAP_SCHEMA.%'"
" AND table_name IN ('mesPM', 'otypedef', 'journals')"
" ORDER BY table_name, principal DESC, column_name")
assert simbad.Simbad.columns("mesPM", "otypedef", "journals", get_adql=True) == columns_adql
# with only one
columns_adql = ("SELECT table_name, column_name, datatype, description, unit, ucd "
"FROM TAP_SCHEMA.columns WHERE table_name NOT LIKE 'TAP_SCHEMA.%' "
"AND table_name = 'basic' ORDER BY table_name, principal DESC, column_name")
assert simbad.Simbad.columns("basic", get_adql=True) == columns_adql


def test_find_columns_by_keyword():
Expand Down

0 comments on commit bdabefa

Please sign in to comment.