From dce6a83034821c7ad78e5734ababd8ea58ceaa83 Mon Sep 17 00:00:00 2001 From: prasad-sawantdesai Date: Mon, 10 Feb 2025 16:40:25 +0100 Subject: [PATCH 1/4] initial version --- .github/workflows/test_with_pytest.yml | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/test_with_pytest.yml diff --git a/.github/workflows/test_with_pytest.yml b/.github/workflows/test_with_pytest.yml new file mode 100644 index 00000000..d300273e --- /dev/null +++ b/.github/workflows/test_with_pytest.yml @@ -0,0 +1,53 @@ +name: Test using pytest + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + + uses: actions/setup-python@v2 + with: + # until saxonche is available in 3.13 + # https://saxonica.plan.io/issues/6561 + python-version: "<3.13" + - 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 + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: htmlcov + + - name: Upload test report + uses: actions/upload-artifact@v4 + with: + name: test-report + path: junit.xml + + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-xml-coverage-path: ./coverage.xml + junitxml-path: ./junit.xml + xml-skip-covered: true + hide-report: true \ No newline at end of file From 19513d26093142420190da74f9cc10b355462230 Mon Sep 17 00:00:00 2001 From: prasad-sawantdesai Date: Mon, 10 Feb 2025 17:28:06 +0100 Subject: [PATCH 2/4] added matrix to run within different Python environment --- .github/workflows/test_with_pytest.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test_with_pytest.yml b/.github/workflows/test_with_pytest.yml index d300273e..02a7d62f 100644 --- a/.github/workflows/test_with_pytest.yml +++ b/.github/workflows/test_with_pytest.yml @@ -5,18 +5,21 @@ 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@v2 - - name: Set up Python + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: # until saxonche is available in 3.13 # https://saxonica.plan.io/issues/6561 - python-version: "<3.13" + python-version: ${{ matrix.python-version }} - name: Display Python version run: python -c "import sys; print(sys.version)" @@ -32,22 +35,14 @@ jobs: 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 + - name: Upload coverage report ${{ matrix.python-version }} uses: actions/upload-artifact@v4 with: - name: coverage-report + name: coverage-report-${{ matrix.python-version }} path: htmlcov - - name: Upload test report + - name: Upload test report ${{ matrix.python-version }} uses: actions/upload-artifact@v4 with: - name: test-report + name: test-report-${{ matrix.python-version }} path: junit.xml - - - name: Pytest coverage comment - uses: MishaKav/pytest-coverage-comment@main - with: - pytest-xml-coverage-path: ./coverage.xml - junitxml-path: ./junit.xml - xml-skip-covered: true - hide-report: true \ No newline at end of file From ecd2d71fe690be4ba69daed073ca3d0861a910b3 Mon Sep 17 00:00:00 2001 From: prasad-sawantdesai Date: Tue, 11 Feb 2025 09:19:28 +0100 Subject: [PATCH 3/4] fixed UTC issue in Python 3.8 --- .github/workflows/test_with_pytest.yml | 4 ++-- imas/ids_convert.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_with_pytest.yml b/.github/workflows/test_with_pytest.yml index 02a7d62f..4febc7a3 100644 --- a/.github/workflows/test_with_pytest.yml +++ b/.github/workflows/test_with_pytest.yml @@ -11,11 +11,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: # until saxonche is available in 3.13 # https://saxonica.plan.io/issues/6561 diff --git a/imas/ids_convert.py b/imas/ids_convert.py index f66f519d..a52db521 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) From 6d97151c0775685db8440b7f9465635e2a40505d Mon Sep 17 00:00:00 2001 From: prasad-sawantdesai Date: Tue, 11 Feb 2025 10:27:15 +0100 Subject: [PATCH 4/4] timestamp converted to supported format for Python 3.8 --- imas/test/test_ids_convert.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imas/test/test_ids_convert.py b/imas/test/test_ids_convert.py index 20dcd8c3..750c44e4 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)