Skip to content

Commit 2900ba8

Browse files
authored
[MNT] CI workflow to run multiple versions and os (#68)
## Change updated `.github\workflows\tests.yml` to add `concurrency` (${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}), multiple `python versions` ("3.10", "3.11", "3.12") and multiple `os` (ubuntu-latest, windows-latest) for running `pytests` ## How to Test in the CI envirionment the tests should run with multiple os and python versions.
1 parent 4b14f70 commit 2900ba8

4 files changed

Lines changed: 27 additions & 18 deletions

File tree

.github/workflows/tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ on:
1515
workflow_dispatch:
1616

1717
concurrency:
18-
group: ${{ github.ref }}
18+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1919
cancel-in-progress: true
2020

2121
jobs:
2222
test-code:
23-
runs-on: ubuntu-latest
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
matrix:
26+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
27+
os: [ubuntu-latest, windows-latest]
2428
steps:
2529
- uses: actions/checkout@v4
2630
- uses: actions/setup-python@v5
2731
with:
28-
python-version: "3.11"
32+
python-version: ${{ matrix.python-version }}
2933
cache: pip
3034
- run: python -m pip install ".[dev]"
3135
name: Install Dependencies

src/aiod/authentication/authentication.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime
1+
from datetime import datetime, timezone, timedelta
22
import time
33
import http.client
44
from http import HTTPStatus
@@ -39,9 +39,9 @@ def _on_keycloak_config_changed(_: str, __: str, ___: str) -> None:
3939
config.subscribe("client_id", on_change=_on_keycloak_config_changed)
4040

4141

42-
def _datetime_utc_in(*, seconds: int) -> datetime.datetime:
43-
span = datetime.timedelta(seconds=seconds)
44-
return datetime.datetime.now(datetime.UTC) + span
42+
def _datetime_utc_in(*, seconds: int) -> datetime:
43+
span = timedelta(seconds=seconds)
44+
return datetime.now(timezone.utc) + span
4545

4646

4747
class Token:
@@ -71,7 +71,7 @@ def __init__(
7171
@property
7272
def has_expired(self) -> bool:
7373
"""Return whether the *access token* has expired based on local data."""
74-
return datetime.datetime.now(datetime.UTC) >= self._expiration_date
74+
return datetime.now(timezone.utc) >= self._expiration_date
7575

7676
@property
7777
def headers(self) -> dict[str, str]:
@@ -142,7 +142,7 @@ def from_file(cls, file: Path | None = None) -> "Token":
142142
"client_secret": str(doc.get("client_secret", "")),
143143
}
144144
if "expiration_date" in doc:
145-
expiration_date = datetime.datetime.fromisoformat(doc["expiration_date"])
145+
expiration_date = datetime.fromisoformat(doc["expiration_date"])
146146
expires_in = expiration_date - _datetime_utc_in(seconds=0)
147147
if expires_in.total_seconds() > 0:
148148
kwargs.update(

src/aiod/bookmarks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime as dt
1+
from datetime import datetime, timezone
22
from dataclasses import dataclass
33
from http import HTTPStatus
44

@@ -18,12 +18,12 @@ class Bookmark:
1818
----------
1919
identifier: str
2020
The identifier of the asset on AI-on-Demand, e.g., 'data_xyz...'
21-
created: datetime.datetime
21+
created: datetime
2222
The datetime when the bookmark was originally created.
2323
"""
2424

2525
identifier: str
26-
created: dt.datetime
26+
created: datetime
2727

2828

2929
def _bookmarks_url() -> str:
@@ -63,8 +63,8 @@ def register(identifier: str) -> Bookmark:
6363

6464
return Bookmark(
6565
identifier=res.json()["resource_identifier"],
66-
created=dt.datetime.fromisoformat(res.json()["created_at"]).replace(
67-
tzinfo=dt.UTC
66+
created=datetime.fromisoformat(res.json()["created_at"]).replace(
67+
tzinfo=timezone.utc
6868
),
6969
)
7070

@@ -115,8 +115,8 @@ def get_list() -> list[Bookmark]:
115115
return [
116116
Bookmark(
117117
identifier=bookmark["resource_identifier"],
118-
created=dt.datetime.fromisoformat(bookmark["created_at"]).replace(
119-
tzinfo=dt.UTC
118+
created=datetime.fromisoformat(bookmark["created_at"]).replace(
119+
tzinfo=timezone.utc
120120
),
121121
)
122122
for bookmark in res.json()

tests/test_endpoints.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from http import HTTPStatus
44

5+
from aiohttp.pytest_plugin import loop
56
import pytest
67
import responses
78
from responses import matchers
@@ -232,7 +233,9 @@ def test_search(asset_with_search):
232233

233234

234235
def test_endpoint_get_asset_async(asset_name):
235-
loop = asyncio.get_event_loop()
236+
loop = asyncio.new_event_loop()
237+
asyncio.set_event_loop(loop)
238+
236239
with aioresponses() as mocked_responses:
237240
mocked_responses.get(
238241
f"{server_url()}{asset_name}/1",
@@ -256,7 +259,9 @@ def test_endpoint_get_asset_async(asset_name):
256259

257260

258261
def test_endpoint_get_list_async(asset_name):
259-
loop = asyncio.get_event_loop()
262+
loop = asyncio.new_event_loop()
263+
asyncio.set_event_loop(loop)
264+
260265
with aioresponses() as mocked_responses:
261266
mocked_responses.get(
262267
f"{server_url()}{asset_name}?offset=0&limit=2",

0 commit comments

Comments
 (0)