Skip to content

Commit

Permalink
style: automatic reformat
Browse files Browse the repository at this point in the history
auto reformat with ruff/docformatter/prettier after config changes
  • Loading branch information
alycejenni committed Oct 31, 2024
1 parent 2f165b2 commit cc520f0
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ckanext/gbif/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def main():
pass


if __name__ == u'__main__':
if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions ckanext/gbif/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def gbif_get_classification(gbif_record):


def gbif_get_geography(occurrence):
'''
"""
:param occurrence:
'''
"""
geography = []
for geographic_part in ['continent', 'country', 'stateprovince']:
value = occurrence.get(geographic_part, None)
Expand Down
9 changes: 4 additions & 5 deletions ckanext/gbif/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Created by the Natural History Museum in London, UK

import requests

from ckan.plugins import toolkit


Expand All @@ -16,17 +15,17 @@ def gbif_record_show(context, data_dict):
:param context: CKAN context
:param data_dict: dict of parameters, only one is required: gbif_id
"""
gbif_id = toolkit.get_or_bust(data_dict, "gbif_id")
gbif_id = toolkit.get_or_bust(data_dict, 'gbif_id')
try:
response = requests.get(
f"https://api.gbif.org/v1/occurrence/{gbif_id}", timeout=5
f'https://api.gbif.org/v1/occurrence/{gbif_id}', timeout=5
)
except requests.Timeout:
raise toolkit.ObjectNotFound("GBIF request timed out")
raise toolkit.ObjectNotFound('GBIF request timed out')
# if there was an error getting the record, raise a not found error
if 400 <= response.status_code < 600:
raise toolkit.ObjectNotFound(
f"GBIF request failed with code {response.status_code}"
f'GBIF request failed with code {response.status_code}'
)
else:
return response.json()
3 changes: 2 additions & 1 deletion ckanext/gbif/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
# Created by the Natural History Museum in London, UK

from ckan.plugins import SingletonPlugin, implements, interfaces, toolkit

from ckanext.gbif import routes
from ckanext.gbif.lib import helpers
from ckanext.gbif.logic.action import gbif_record_show


class GBIFPlugin(SingletonPlugin):
'''GBIF plugin - Data Quality Indicators'''
"""GBIF plugin - Data Quality Indicators"""

implements(interfaces.IActions, inherit=True)
implements(interfaces.IConfigurer)
Expand Down
3 changes: 1 addition & 2 deletions ckanext/gbif/routes/gbif.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# This file is part of ckanext-gbif
# Created by the Natural History Museum in London, UK

from flask import Blueprint

from ckan.plugins import toolkit
from flask import Blueprint

blueprint = Blueprint(
name='gbif',
Expand Down
1 change: 0 additions & 1 deletion docs/_scripts/gen_api_pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# !/usr/bin/env python
# encoding: utf-8

"""
Generate the code reference pages and navigation.
Expand Down
7 changes: 3 additions & 4 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from unittest.mock import patch, MagicMock, call
from unittest.mock import MagicMock, call, patch

import pytest
import requests

from ckan.plugins import toolkit

from ckanext.gbif.logic.action import gbif_record_show
Expand Down Expand Up @@ -31,15 +30,15 @@ def test_failure(self, requests_mock):
)

def test_timeout(self, requests_mock):
gbif_id = "test"
gbif_id = 'test'
# we mock the entire requests module so we need to put the Timeout class back
# before we use it
requests_mock.Timeout = requests.Timeout
requests_mock.configure_mock(get=MagicMock(side_effect=requests.Timeout()))
with pytest.raises(toolkit.ObjectNotFound):
gbif_record_show(MagicMock(), dict(gbif_id=gbif_id))
assert requests_mock.get.call_args == call(
f"https://api.gbif.org/v1/occurrence/{gbif_id}", timeout=5
f'https://api.gbif.org/v1/occurrence/{gbif_id}', timeout=5
)

def test_missing_gbif_id(self, requests_mock):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import MagicMock

from ckanext.gbif.lib.errors import GBIF_ERRORS, DQI_MAJOR_ERRORS, DQI_MINOR_ERRORS
from ckanext.gbif.lib.helpers import dqi_parse_errors, dqi_get_severity
from ckanext.gbif.lib.errors import DQI_MAJOR_ERRORS, DQI_MINOR_ERRORS, GBIF_ERRORS
from ckanext.gbif.lib.helpers import dqi_get_severity, dqi_parse_errors


class TestDQIParseErrors:
Expand Down

0 comments on commit cc520f0

Please sign in to comment.