Skip to content

Commit

Permalink
Merge pull request #91 from beda-software/black-precommit
Browse files Browse the repository at this point in the history
Add pre-commit hook with Black formatter, remove yapf
  • Loading branch information
mkizesov authored Nov 2, 2022
2 parents addfaf7 + c4b1e25 commit 1820f4d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3.8
15 changes: 10 additions & 5 deletions fhirpy/base/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def _build_request_url(self, path, params):
class AsyncClient(AbstractClient, ABC):
aiohttp_config = None

def __init__(self, url, authorization=None, extra_headers=None, aiohttp_config=None):
def __init__(
self, url, authorization=None, extra_headers=None, aiohttp_config=None
):
self.aiohttp_config = aiohttp_config or {}

super().__init__(url, authorization, extra_headers)
Expand All @@ -125,8 +127,7 @@ async def _do_request(self, method, path, data=None, params=None):
) as r:
if 200 <= r.status < 300:
data = await r.text()
return (json.loads(data, object_hook=AttrDict)
if data else None)
return json.loads(data, object_hook=AttrDict) if data else None

if r.status == 404 or r.status == 410:
raise ResourceNotFound(await r.text())
Expand All @@ -147,7 +148,9 @@ async def _fetch_resource(self, path, params=None):
class SyncClient(AbstractClient, ABC):
requests_config = None

def __init__(self, url, authorization=None, extra_headers=None, requests_config=None):
def __init__(
self, url, authorization=None, extra_headers=None, requests_config=None
):
self.requests_config = requests_config or {}

super().__init__(url, authorization, extra_headers)
Expand All @@ -158,7 +161,9 @@ def execute(self, path, method="post", **kwargs):
def _do_request(self, method, path, data=None, params=None):
headers = self._build_request_headers()
url = self._build_request_url(path, params)
r = requests.request(method, url, json=data, headers=headers, **self.requests_config)
r = requests.request(
method, url, json=data, headers=headers, **self.requests_config
)

if 200 <= r.status_code < 300:
return (
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pytest-cov==2.12.0
aiohttp==3.7.4
pytest-asyncio==0.15.1
responses==0.13.3
yapf==0.31.0
pytz==2021.1
pytz==2021.1
black==22.10.0
pre-commit==2.20.0
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[metadata]
license_file = LICENSE.md
description-file = README.md

[yapf]
based_on_style = facebook
26 changes: 9 additions & 17 deletions tests/test_lib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,27 +597,19 @@ async def test_aiohttp_config():
client = AsyncFHIRClient(
FHIR_SERVER_URL,
authorization=FHIR_SERVER_AUTHORIZATION,
aiohttp_config={
"ssl": False,
"proxy": "http://example.com"
}
aiohttp_config={"ssl": False, "proxy": "http://example.com"},
)
resp = MockAiohttpResponse(
bytes(
json.dumps(
{
'resourceType': 'Bundle',
'type': 'searchset',
'total': 0,
'entry': []
}
), 'utf-8'
), 200
{"resourceType": "Bundle", "type": "searchset", "total": 0, "entry": []}
),
"utf-8",
),
200,
)
with patch(
"aiohttp.ClientSession.request", return_value=resp
) as patched_request:
await client.resources('Patient').first()
with patch("aiohttp.ClientSession.request", return_value=resp) as patched_request:
await client.resources("Patient").first()
patched_request.assert_called_with(
ANY, ANY, json=None, ssl=False, proxy='http://example.com'
ANY, ANY, json=None, ssl=False, proxy="http://example.com"
)
18 changes: 5 additions & 13 deletions tests/test_lib_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,22 +541,14 @@ def test_requests_config():
client = SyncFHIRClient(
FHIR_SERVER_URL,
authorization=FHIR_SERVER_AUTHORIZATION,
requests_config={
"verify": False,
"cert": "some_cert"
}
requests_config={"verify": False, "cert": "some_cert"},
)
json_resp_str = json.dumps(
{
'resourceType': 'Bundle',
'type': 'searchset',
'total': 0,
'entry': []
}
{"resourceType": "Bundle", "type": "searchset", "total": 0, "entry": []}
)
resp = MockRequestsResponse(bytes(json_resp_str, 'utf-8'), 200)
resp = MockRequestsResponse(bytes(json_resp_str, "utf-8"), 200)
with patch("requests.request", return_value=resp) as patched_request:
client.resources('Patient').first()
client.resources("Patient").first()
patched_request.assert_called_with(
ANY, ANY, json=ANY, headers=ANY, verify=False, cert='some_cert'
ANY, ANY, json=ANY, headers=ANY, verify=False, cert="some_cert"
)

0 comments on commit 1820f4d

Please sign in to comment.