diff --git a/.github/workflows/test.v2.yaml b/.github/workflows/test.v2.yaml index a0a9118..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 run +py=${{ matrix.python-version }} test:test + run: hatch -v run ${{ matrix.env }}:test diff --git a/pyproject.toml b/pyproject.toml index a8598ce..ddb36f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,20 +66,25 @@ 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"] -numpy-version = ["1", "2"] - +numpy = ["2", "1"] +asdf = ["non_lazy_ndarray", "3"] [tool.hatch.envs.test.overrides] -matrix.numpy-version.dependencies = [ +matrix.numpy.dependencies = [ { value = "numpy>=1,<2", if = ["1"] }, { value = "numpy>=2,<3", if = ["2"] }, { value = "astropy>=6.1", 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", diff --git a/tests/patterns/ndarray_type_test.py b/tests/patterns/ndarray_type_test.py new file mode 100644 index 0000000..ad94d17 --- /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_deserialize_ndarray_when_nonlazy_load(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)