diff --git a/asdf/_tests/tags/core/tests/test_ndarray.py b/asdf/_tests/tags/core/tests/test_ndarray.py index 5de7a0ce4..d0aac5d8a 100644 --- a/asdf/_tests/tags/core/tests/test_ndarray.py +++ b/asdf/_tests/tags/core/tests/test_ndarray.py @@ -167,12 +167,42 @@ def check_raw_yaml(content): 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 c8a49f8f9..bbf03009d 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 @@ -119,23 +118,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_file_format.py b/asdf/_tests/test_file_format.py index 0f7b249ce..59b24e1ae 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" @@ -157,7 +156,6 @@ def test_empty_file(): assert len(ff._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_schema.py b/asdf/_tests/test_schema.py index 9d0f9e5f3..f868b82d0 100644 --- a/asdf/_tests/test_schema.py +++ b/asdf/_tests/test_schema.py @@ -37,22 +37,42 @@ def from_tree(cls, tree, ctx): 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(): @@ -807,8 +827,6 @@ def test_nested_array_yaml(tmp_path): def test_type_missing_dependencies(): - pytest.importorskip("astropy", "3.0.0") - with pytest.warns(AsdfDeprecationWarning, match=".*subclasses the deprecated CustomType.*"): class MissingType(types.CustomType): diff --git a/pyproject.toml b/pyproject.toml index 64118a498..c992b2e57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,6 @@ docs = [ 'tomli; python_version < "3.11"', ] tests = [ - "astropy>=5.0.4", "fsspec[http]>=2022.8.2", "lz4>=0.10", "psutil",