diff --git a/.github/workflows/test_with_pytest.yml b/.github/workflows/test_with_pytest.yml new file mode 100644 index 0000000..4febc7a --- /dev/null +++ b/.github/workflows/test_with_pytest.yml @@ -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 diff --git a/imas/ids_convert.py b/imas/ids_convert.py index f66f519..a52db52 100644 --- a/imas/ids_convert.py +++ b/imas/ids_convert.py @@ -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) diff --git a/imas/test/test_ids_convert.py b/imas/test/test_ids_convert.py index 20dcd8c..750c44e 100644 --- a/imas/test/test_ids_convert.py +++ b/imas/test/test_ids_convert.py @@ -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)