Skip to content

Commit

Permalink
ci: Use "pytest -W error". Fix deprecations. Use simpler caching conf…
Browse files Browse the repository at this point in the history
…iguration.
  • Loading branch information
jpmckinney committed Apr 6, 2022
1 parent 2ebefc1 commit 15a7d44
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ jobs:
- uses: actions/setup-python@v3
with:
python-version: 3.7 # Google Colaboratory uses Python 3.7
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', 'setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
cache: pip
cache-dependency-path: setup.py
- run: pip install .[test]
# The unit tests are run with ipython, as the code requires an iPython instance, like in a notebook.
- env:
TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres
run: ipython -m pytest -- --cov ocdskingfishercolab
# The unit tests are run with ipython, as the code requires an iPython instance, like in a notebook.
run: ipython -m pytest -- -W error --cov ocdskingfishercolab
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ jobs:
- uses: actions/setup-python@v3
with:
python-version: 3.8
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', 'setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
cache: pip
cache-dependency-path: setup.py
- run: curl -s -S --retry 3 $BASEDIR/tests/install.sh | bash -
- run: curl -s -S --retry 3 $BASEDIR/tests/script.sh | bash -
- run: pip install .[test]
Expand Down
26 changes: 13 additions & 13 deletions ocdskingfishercolab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def list_source_ids(pattern=''):

pattern = f'%{pattern}%'

# This inspects locals to find pattern
return get_ipython().magic(f'sql {sql}')
# This inspects locals to find `pattern`.
return get_ipython().run_line_magic('sql', sql)


def list_collections(source_id=None):
Expand All @@ -133,8 +133,8 @@ def list_collections(source_id=None):
sql += " WHERE source_id = :source_id"
sql += " ORDER BY id DESC"

# This inspects locals to find source_id
return get_ipython().magic(f'sql {sql}')
# This inspects locals to find `source_id`.
return get_ipython().run_line_magic('sql', sql)


def set_search_path(schema_name):
Expand All @@ -145,7 +145,7 @@ def set_search_path(schema_name):
:param str schema_name: a schema name
"""
try:
get_ipython().magic(f'sql SET search_path = {schema_name}, public')
get_ipython().run_line_magic('sql', f'SET search_path = {schema_name}, public')
# https://github.com/catherinedevlin/ipython-sql/issues/191
except ResourceClosedError:
pass
Expand Down Expand Up @@ -240,18 +240,18 @@ def get_ipython_sql_resultset_from_query(sql):
:rtype: sql.run.ResultSet
"""
ipython = get_ipython()
autopandas = ipython.magic('config SqlMagic.autopandas')
autopandas = ipython.run_line_magic('config', 'SqlMagic.autopandas')
# Disable autopandas, so we know that the sql magic call will always return
# a ResultSet (rather than a pandas DataFrame). Since the DataFrame would
# be created from the ResultSet, it would be less efficient.
if autopandas:
ipython.magic('config SqlMagic.autopandas=False')
ipython.run_line_magic('config', 'SqlMagic.autopandas = False')
# Use ipython.run_line_magic instead of ipython.magic here
# to get variables from the scope of the ipython cell,
# instead of the scope in this function.
results = ipython.run_line_magic('sql', sql)
if autopandas:
ipython.magic('config SqlMagic.autopandas=True')
ipython.run_line_magic('config', 'SqlMagic.autopandas = True')
return results


Expand Down Expand Up @@ -300,16 +300,16 @@ def download_package_from_ocid(collection_id, ocid, package_type):
"""

ipython = get_ipython()
autopandas = ipython.magic('config SqlMagic.autopandas')
autopandas = ipython.run_line_magic('config', 'SqlMagic.autopandas')
# Disable autopandas, so we know that the sql magic call will always return
# a ResultSet (rather than a pandas DataFrame). Since the DataFrame would
# be created from the ResultSet, it would be less efficient.
if autopandas:
ipython.magic('config SqlMagic.autopandas=False')
# This inspects locals to find ocid and collection_id
results = ipython.magic(f'sql {sql}')
ipython.run_line_magic('config', 'SqlMagic.autopandas = False')
# This inspects locals to find `ocid` and `collection_id`.
results = ipython.run_line_magic('sql', sql)
if autopandas:
ipython.magic('config SqlMagic.autopandas=True')
ipython.run_line_magic('config', 'SqlMagic.autopandas = True')

data = [row[0] for row in results]

Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def db():

conn.commit()

get_ipython().magic('load_ext sql')
get_ipython().magic(f'sql {created_database_url}')
# Set autopandas, because we think most users will
get_ipython().magic('config SqlMagic.autopandas=True')
get_ipython().run_line_magic('load_ext', 'sql')
get_ipython().run_line_magic('sql', created_database_url)
# Set autopandas, because we think most users will want it.
get_ipython().run_line_magic('config', 'SqlMagic.autopandas = True')

yield cur
finally:
Expand Down
9 changes: 4 additions & 5 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def chdir(path):
def test_set_search_path(db):
set_search_path('test')

get_ipython().magic('sql show search_path')['search_path'][0] == 'test, public'
get_ipython().run_line_magic('sql', 'show search_path')['search_path'][0] == 'test, public'


@patch('ocdskingfishercolab.files.download')
Expand Down Expand Up @@ -229,15 +229,14 @@ def test_get_ipython_sql_resultset_from_query(db):

@patch('ocdskingfishercolab._notebook_id', _notebook_id)
def test_get_ipython_sql_resultset_from_query_error(db, capsys):
get_ipython().magic('sql invalid')
get_ipython().run_line_magic('sql', 'invalid')
captured = capsys.readouterr()

assert '(psycopg2.errors.SyntaxError) syntax error at or near "invalid"\n' \
'LINE 1: ...google.com/drive/1lpWoGnOb6KcjHDEhSBjWZgA8aBLCfDp0 */invalid\n' \
' ^\n\n' \
'[SQL: /* https://colab.research.google.com/drive/1lpWoGnOb6KcjHDEhSBjWZgA8aBLCfDp0' \
' */invalid]\n' \
'(Background on this error at: http://sqlalche.me/e/13/f405)\n' in captured.out
'[SQL: /* https://colab.research.google.com/drive/1lpWoGnOb6KcjHDEhSBjWZgA8aBLCfDp0 */invalid]\n' \
'(Background on this error at: https://sqlalche.me/e/14/f405)\n' in captured.out


@patch('ocdskingfishercolab._notebook_id', _notebook_id)
Expand Down

0 comments on commit 15a7d44

Please sign in to comment.