diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 485fc08f5..7de90d9f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,6 +81,8 @@ jobs: - linux: py39-devdeps-parallel - linux: py310-devdeps-parallel - linux: py311-devdeps-parallel + - linux: py312-devdeps-parallel + python-version: '3.12-dev' oldest: needs: [core, asdf-schemas] diff --git a/asdf/_tests/tags/core/tests/test_ndarray.py b/asdf/_tests/tags/core/tests/test_ndarray.py index 45373326f..941c6a125 100644 --- a/asdf/_tests/tags/core/tests/test_ndarray.py +++ b/asdf/_tests/tags/core/tests/test_ndarray.py @@ -241,12 +241,39 @@ def test_table_inline(tmpdir): def test_array_inline_threshold_recursive(tmpdir): - models = pytest.importorskip("astropy.modeling.models") + """ + Test that setting the inline threshold works for objects + that contain (and when serialized produce a ndarray) + """ + + class NDArrayContainer: + def __init__(self, array): + self._array = array + + @property + def array(self): + return np.array(self._array) + + class NDArrayContainerConverter: + tags = ["http://somewhere.org/tags/foo-1.0.0"] + types = [NDArrayContainer] + + def to_yaml_tree(self, obj, tag, ctx): + return {"array": obj.array} + + def from_yaml_tree(self, node, tag, ctx): + return NDArrayContainer(node["array"]) + + class NDArrayContainerExtension: + tags = NDArrayContainerConverter.tags + converters = [NDArrayContainerConverter()] + extension_uri = "http://somewhere.org/extensions/foo-1.0.0" - aff = models.AffineTransformation2D(matrix=[[1, 2], [3, 4]]) - tree = {"test": aff} + container = NDArrayContainer([[1, 2], [3, 4]]) + tree = {"test": container} with asdf.config_context() as config: + config.add_extension(NDArrayContainerExtension()) config.array_inline_threshold = 100 # we can no longer use _helpers.assert_roundtrip_tree here because # the model no longer has a CustomType which results in equality testing diff --git a/asdf/_tests/test_api.py b/asdf/_tests/test_api.py index 3d394ce6f..0c5b8a575 100644 --- a/asdf/_tests/test_api.py +++ b/asdf/_tests/test_api.py @@ -7,7 +7,6 @@ import numpy as np import pytest -from astropy.modeling import models from numpy.testing import assert_array_equal import asdf @@ -117,23 +116,6 @@ def test_atomic_write(tmp_path, small_tree): ff.write_to(tmpfile) -def test_overwrite(tmp_path): - """ - This is intended to reproduce the following issue: - https://github.com/asdf-format/asdf/issues/100 - """ - tmpfile = str(tmp_path / "test.asdf") - aff = models.AffineTransformation2D(matrix=[[1, 2], [3, 4]]) - f = asdf.AsdfFile() - f.tree["model"] = aff - f.write_to(tmpfile) - model = f.tree["model"] - - ff = asdf.AsdfFile() - ff.tree["model"] = model - ff.write_to(tmpfile) - - def test_default_version(): """ See https://github.com/asdf-format/asdf/issues/364 diff --git a/asdf/_tests/test_asdf.py b/asdf/_tests/test_asdf.py index d41e2b31a..8584367d8 100644 --- a/asdf/_tests/test_asdf.py +++ b/asdf/_tests/test_asdf.py @@ -1,6 +1,5 @@ import os -import fsspec import pytest from asdf import config_context @@ -361,6 +360,8 @@ def test_fsspec(tmp_path): Issue #1146 reported errors when opening a fsspec 'file' This is a regression test for the fix in PR #1226 """ + fsspec = pytest.importorskip("fsspec") + tree = {"a": 1} af = AsdfFile(tree) fn = tmp_path / "test.asdf" @@ -378,6 +379,8 @@ def test_fsspec_http(httpserver): filesystem) This is a regression test for the fix in PR #1228 """ + fsspec = pytest.importorskip("fsspec") + tree = {"a": 1} af = AsdfFile(tree) path = os.path.join(httpserver.tmpdir, "test") diff --git a/asdf/_tests/test_file_format.py b/asdf/_tests/test_file_format.py index 6c9cc593b..6a82671a6 100644 --- a/asdf/_tests/test_file_format.py +++ b/asdf/_tests/test_file_format.py @@ -59,7 +59,6 @@ def test_no_final_newline(tmp_path): assert len(ff.tree) == 2 -@pytest.mark.filterwarnings("ignore::astropy.io.fits.verify.VerifyWarning") def test_no_asdf_header(tmp_path): content = b"What? This ain't no ASDF file" @@ -98,7 +97,6 @@ def test_empty_file(): assert len(ff._blocks.blocks) == 0 -@pytest.mark.filterwarnings("ignore::astropy.io.fits.verify.VerifyWarning") @pytest.mark.filterwarnings("ignore::asdf.exceptions.AsdfDeprecationWarning") def test_not_asdf_file(): buff = io.BytesIO(b"SIMPLE") diff --git a/asdf/_tests/test_generic_io.py b/asdf/_tests/test_generic_io.py index fbc8427cc..b92047b00 100644 --- a/asdf/_tests/test_generic_io.py +++ b/asdf/_tests/test_generic_io.py @@ -5,7 +5,6 @@ import sys import urllib.request as urllib_request -import fsspec import numpy as np import pytest @@ -786,6 +785,8 @@ def test_fsspec(tmp_path): Issue #1146 reported errors when opening a fsspec 'file' This is a regression test for the fix in PR #1226 """ + fsspec = pytest.importorskip("fsspec") + ref = b"01234567890" fn = tmp_path / "test" @@ -809,6 +810,8 @@ def test_fsspec_http(httpserver): filesystem) This is a regression test for the fix in PR #1228 """ + fsspec = pytest.importorskip("fsspec") + ref = b"01234567890" path = os.path.join(httpserver.tmpdir, "test") diff --git a/asdf/_tests/test_schema.py b/asdf/_tests/test_schema.py index 7496d5bbb..82cea9238 100644 --- a/asdf/_tests/test_schema.py +++ b/asdf/_tests/test_schema.py @@ -64,22 +64,43 @@ class TagReferenceExtension: def test_tagging_scalars(): - pytest.importorskip("astropy", "3.0.0") - from astropy import units as u + class Scalar: + def __init__(self, value): + self.value = value - yaml = """ -unit: !unit/unit-1.0.0 + scalar_tag = "http://somewhere.org/tags/scalar-1.0.0" + + class ScalarConverter: + tags = [scalar_tag] + types = [Scalar] + + def to_yaml_tree(self, obj, tag, ctx): + return obj.value + + def from_yaml_tree(self, node, tag, ctx): + return Scalar(node) + + class ScalarExtension: + tags = [scalar_tag] + converters = [ScalarConverter()] + extension_uri = "http://somewhere.org/extensions/scalar-1.0.0" + + yaml = f""" +tagged: !<{scalar_tag}> m -not_unit: +not_tagged: m """ - buff = helpers.yaml_to_asdf(yaml) - with asdf.open(buff) as ff: - assert isinstance(ff.tree["unit"], u.UnitBase) - assert not isinstance(ff.tree["not_unit"], u.UnitBase) - assert isinstance(ff.tree["not_unit"], str) + with asdf.config_context() as cfg: + cfg.add_extension(ScalarExtension()) + buff = helpers.yaml_to_asdf(yaml) + with asdf.open(buff) as ff: + assert isinstance(ff.tree["tagged"], Scalar) + assert not isinstance(ff.tree["not_tagged"], Scalar) + assert isinstance(ff.tree["not_tagged"], str) - assert ff.tree == {"unit": u.m, "not_unit": "m"} + assert ff.tree["tagged"].value == "m" + assert ff.tree["not_tagged"] == "m" def test_read_json_schema(): diff --git a/pyproject.toml b/pyproject.toml index 1834068f4..3f954c247 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,14 +43,11 @@ docs = [ 'tomli; python_version < "3.11"', ] tests = [ - "astropy>=5.0.4", "fsspec[http]>=2022.8.2", - "asdf-astropy>=0.4.0", "lz4>=0.10", "psutil", "pytest>=6", "pytest-doctestplus", - "pytest-openfiles", "pytest-remotedata", ] [project.urls] @@ -107,15 +104,13 @@ minversion = 4.6 norecursedirs = ['build', 'docs/_build', 'docs/sphinxext'] doctest_plus = 'enabled' remote_data_strict = true -# The asdf.asdftypes module emits a warning on import, -# which pytest trips over during collection: filterwarnings = [ 'error', 'ignore:numpy.ndarray size changed:RuntimeWarning', ] # Configuration for pytest-doctestplus text_file_format = 'rst' -addopts = '--color=yes --doctest-rst' +addopts = '--color=yes --doctest-rst -rsx' [tool.coverage.run] omit = [ diff --git a/requirements-dev.txt b/requirements-dev.txt index 82af43cfc..a552322cc 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,11 +1,12 @@ -git+https://github.com/astropy/asdf-astropy git+https://github.com/asdf-format/asdf-coordinates-schemas git+https://github.com/asdf-format/asdf-standard git+https://github.com/asdf-format/asdf-transform-schemas git+https://github.com/asdf-format/asdf-unit-schemas.git git+https://github.com/asdf-format/asdf-wcs-schemas -git+https://github.com/astropy/astropy -#git+https://github.com/yaml/pyyaml.git +git+https://github.com/yaml/pyyaml.git numpy>=0.0.dev0 +# although we don't use scipy, we include it here so that any dependency +# that uses it during these tests will use the development version +# which is more likely to work with the above development version of numpy scipy>=0.0.dev0 diff --git a/tox.ini b/tox.ini index 42c494872..87f88ce22 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,8 @@ env_list = compatibility coverage - py{39,310,311}{,-compatibility,-coverage,-jsonschema}{,-parallel} + devdep{,-parallel} + py{39,310,311,312}{,-compatibility,-coverage,-jsonschema}{,-parallel} asdf{-standard,-transform-schemas,-unit-schemas,-wcs-schemas,-coordinates-schemas,-astropy} gwcs jwst @@ -46,7 +47,6 @@ commands = --remote-data \ --durations=10 \ jsonschema: --jsonschema \ - coverage: --open-files \ parallel: --numprocesses auto \ # the OpenAstronomy workflow appends `--cov-report` in `{posargs}`, which `coverage` doesn't recognize !coverage: {posargs}