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
48 changes: 48 additions & 0 deletions .github/workflows/test_with_pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test using pytest

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] # Test on multiple Python versions

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v4
with:
# until saxonche is available in 3.13
# https://saxonica.plan.io/issues/6561
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip setuptools wheel
pip install .[h5py,netcdf,test]

- name: Run tests
run: |
source venv/bin/activate
python -m pytest -n=auto --cov=imas --cov-report=term-missing --cov-report=xml:coverage.xml --cov-report=html:htmlcov --junit-xml=junit.xml

- name: Upload coverage report ${{ matrix.python-version }}
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.python-version }}
path: htmlcov

- name: Upload test report ${{ matrix.python-version }}
uses: actions/upload-artifact@v4
with:
name: test-report-${{ matrix.python-version }}
path: junit.xml
3 changes: 2 additions & 1 deletion imas/ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ def _add_provenance_entry(
# DD version after IMAS-5304
node.reference.resize(len(node.reference) + 1, keep=True)
node.reference[-1].name = source_txt
timestamp = datetime.datetime.now(datetime.UTC).isoformat(timespec="seconds")
utc = getattr(datetime, "UTC", datetime.timezone.utc)
timestamp = datetime.datetime.now(utc).isoformat(timespec="seconds")
node.reference[-1].timestamp = timestamp.replace("+00:00", "Z")
else:
# DD before IMAS-5304 (between 3.34.0 and 3.41.0)
Expand Down
3 changes: 2 additions & 1 deletion imas/test/test_ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def test_provenance_entry(factory):
timestamp = str(cp4.ids_properties.provenance.node[0].reference[0].timestamp)
# Check that timestamp adheres to the format YYYY-MM-DDTHH:MM:SSZ
assert re.match(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", timestamp)
dtime = datetime.now(UTC) - datetime.fromisoformat(timestamp)
timestamp_for_parsing = timestamp.replace("Z", "+00:00")
dtime = datetime.now(UTC) - datetime.fromisoformat(timestamp_for_parsing)
assert timedelta(seconds=0) <= dtime < timedelta(seconds=2)


Expand Down