Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test unstable asdf v4 #25

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 20 additions & 3 deletions .github/workflows/test.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF'
echo $(hatch env show --json | jq -r 'to_entries[] | select(.key | startswith("test")) | .key')
echo 'EOF'
} >> "$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
Expand All @@ -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
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions tests/patterns/ndarray_type_test.py
Original file line number Diff line number Diff line change
@@ -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)