From 46cb987458db505872b2c4115042a9de39edbb92 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:15:34 -0700 Subject: [PATCH 1/7] test: add matrix env for asdf unstable v4 --- pyproject.toml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ef5869a..dbad739 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,14 +64,20 @@ test = "pytest {args}" [[tool.hatch.envs.test.matrix]] python = ["3.9", "3.10", "3.11", "3.12"] -numpy-version = ["1", "2"] +numpy = ["1", "2"] +asdf = ["3", "non_lazy_ndarray"] [tool.hatch.envs.test.overrides] -matrix.numpy-version.dependencies = [ +matrix.numpy.dependencies = [ { value = "numpy>=1,<2", if = ["1"] }, { value = "numpy>=2,<3", if = ["2"] }, ] +matrix.asdf.dependencies = [ + { value = "asdf>=3,<4", if = ["latest"] }, + { value = "asdf@git+https://github.com/braingram/asdf.git@non_lazy_ndarray", if = ["non_lazy_ndarray"] }, +] + [tool.hatch.envs.docs] dependencies = [ "sphinx", From 4de4c9b00807b53174c09db85bafc69cb04ca350 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:15:52 -0700 Subject: [PATCH 2/7] test: add ndarray type test --- tests/patterns/ndarray_type_test.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/patterns/ndarray_type_test.py diff --git a/tests/patterns/ndarray_type_test.py b/tests/patterns/ndarray_type_test.py new file mode 100644 index 0000000..9570506 --- /dev/null +++ b/tests/patterns/ndarray_type_test.py @@ -0,0 +1,32 @@ +import asdf +import numpy as np +from asdf.extension import Extension + +from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel + + +class Data(AsdfPydanticModel): + _tag = "asdf://asdf-pydantic/examples/tags/data-1.0.0" + array: np.ndarray + + +def setup_module(): + AsdfPydanticConverter.add_models(Data) + + class TestExtension(Extension): + extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0" + + converters = [AsdfPydanticConverter()] # type: ignore + tags = [*AsdfPydanticConverter().tags] # type: ignore + + asdf.get_config().add_extension(TestExtension()) + + +def test_can_write_with_subclass_model(tmp_path): + data = Data(array=np.array([1, 2, 3])) + + af = asdf.AsdfFile({"data": data}) + af.write_to(tmp_path / "test.asdf") + + with asdf.open(tmp_path / "test.asdf", lazy_load=False) as af: + assert isinstance(af["data"], Data) From 9b493bb722bfb4876118bb68727b14f8fcf4a326 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:47:37 -0700 Subject: [PATCH 3/7] fixup! test: add matrix env for asdf unstable v4 --- tests/patterns/ndarray_type_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/patterns/ndarray_type_test.py b/tests/patterns/ndarray_type_test.py index 9570506..ad94d17 100644 --- a/tests/patterns/ndarray_type_test.py +++ b/tests/patterns/ndarray_type_test.py @@ -22,7 +22,7 @@ class TestExtension(Extension): asdf.get_config().add_extension(TestExtension()) -def test_can_write_with_subclass_model(tmp_path): +def test_can_deserialize_ndarray_when_nonlazy_load(tmp_path): data = Data(array=np.array([1, 2, 3])) af = asdf.AsdfFile({"data": data}) From 501fabffb3531d83082e4b7347fdd72313400014 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:51:10 -0700 Subject: [PATCH 4/7] test: make unstable run first --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fd9a29d..2051214 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,8 +70,8 @@ numpy-version = ["1"] [[tool.hatch.envs.test.matrix]] python = ["3.10", "3.11", "3.12"] -numpy = ["1", "2"] -asdf = ["3", "non_lazy_ndarray"] +numpy = ["2", "1"] +asdf = ["non_lazy_ndarray", "3"] [tool.hatch.envs.test.overrides] matrix.numpy.dependencies = [ From a586c7f04debc7417d5df4fd9f6753afa7a4f8cb Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:53:48 -0700 Subject: [PATCH 5/7] fixup! test: add matrix env for asdf unstable v4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2051214..ddb36f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ test = "pytest {args}" [[tool.hatch.envs.test.matrix]] # Only test with numpy v1 on Python 3.9 python = ["3.9"] -numpy-version = ["1"] +numpy = ["1"] [[tool.hatch.envs.test.matrix]] python = ["3.10", "3.11", "3.12"] From a80ab43ea3e4570607d039147e848e3e94ab6c1c Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 13:56:36 -0700 Subject: [PATCH 6/7] test: turn on hatch verbose --- .github/workflows/test.v2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.v2.yaml b/.github/workflows/test.v2.yaml index a0a9118..f8034ca 100644 --- a/.github/workflows/test.v2.yaml +++ b/.github/workflows/test.v2.yaml @@ -27,4 +27,4 @@ jobs: python -m pip install --upgrade pip python -m pip install hatch - name: Pytest - run: hatch run +py=${{ matrix.python-version }} test:test + run: hatch -v run +py=${{ matrix.python-version }} test:test From fd67e817e3c87a384c55e535e920be5076540ebb Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 28 Jun 2024 14:23:05 -0700 Subject: [PATCH 7/7] WIP: better hatch matrix in GH workflow --- .github/workflows/test.v2.yaml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.v2.yaml b/.github/workflows/test.v2.yaml index f8034ca..fe02170 100644 --- a/.github/workflows/test.v2.yaml +++ b/.github/workflows/test.v2.yaml @@ -8,13 +8,31 @@ on: workflow_dispatch: jobs: + define-matirx: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set matrix + id: set-matrix + run: | + python -m pip install hatch + { + echo 'hatchenv<> "$GITHUB_OUTPUT" + test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + env: ${{fromJson(needs.define-matirx.outputs.hatchenv)}} steps: - uses: actions/checkout@v3 @@ -24,7 +42,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Python dependencies run: | - python -m pip install --upgrade pip python -m pip install hatch - name: Pytest - run: hatch -v run +py=${{ matrix.python-version }} test:test + run: hatch -v run ${{ matrix.env }}:test