Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions simple_app/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ def test_one_df_query(db):
assert db
bad_query = 'thisisabadquery'
good_query = 'twa'

# test search object
results = db.search_object(bad_query, fmt='pandas')
assert not len(results) # bad query should return empty table
results = db.search_object(good_query, fmt='pandas')
assert isinstance(results, pd.DataFrame)

# test search string
with pytest.raises(KeyError):
ref_results: Optional[dict] = db.search_string(bad_query, fmt='pandas', verbose=False)
Expand All @@ -146,21 +148,26 @@ def test_one_df_query(db):
filtered_results: Optional[pd.DataFrame] = results.merge(ref_sources, on='source', suffixes=(None, 'extra'))
assert isinstance(filtered_results, pd.DataFrame)
filtered_results.drop(columns=list(filtered_results.filter(regex='extra')), inplace=True)

# test one_df_query
stringed_results = one_df_query(filtered_results)
assert isinstance(stringed_results, str)

# test sql query
with pytest.raises(OperationalError):
_ = db.sql_query('notasqlquery', fmt='pandas')
with pytest.raises(OperationalError):
_ = db.sql_query('select * from NotaTable', fmt='pandas')
with pytest.raises(OperationalError):
_ = db.sql_query('select * from Sources where notacolumn == "asdf"', fmt='pandas')
raw_sql_query = db.sql_query('select * from Sources where source == "Luhman 16"', fmt='pandas')

# Using a source that returns a single row
raw_sql_query = db.sql_query('select * from Sources where source == "WISE J104915.57-531906.1"', fmt='pandas')
Comment on lines -159 to +165
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test failed since the source was renamed.

assert isinstance(raw_sql_query, pd.DataFrame)

# Testing conversion to a markdown string
stringed_results = one_df_query(raw_sql_query)
assert isinstance(stringed_results, str)
return


def test_multi_df_query(db):
Expand Down
16 changes: 8 additions & 8 deletions simple_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,14 +1186,14 @@ def main_utils():


REFERENCE_TABLES = [
'Publications',
'Telescopes',
'Instruments',
'Modes',
'PhotometryFilters',
'Versions',
'Parameters',
'Regimes'
"Publications",
"Telescopes",
"Instruments",
"PhotometryFilters",
"Versions",
"Parameters",
"Regimes",
"CompanionList"
]

if __name__ == '__main__':
Expand Down