Skip to content

Commit

Permalink
remove astropy test dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Aug 18, 2023
1 parent e2cc0dd commit 2f2115c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
36 changes: 33 additions & 3 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions asdf/_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import numpy as np
import pytest
from astropy.modeling import models
from numpy.testing import assert_array_equal

import asdf
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions asdf/_tests/test_file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
Expand Down
44 changes: 31 additions & 13 deletions asdf/_tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ docs = [
'tomli; python_version < "3.11"',
]
tests = [
"astropy>=5.0.4",
"fsspec[http]>=2022.8.2",
"lz4>=0.10",
"psutil",
Expand Down

0 comments on commit 2f2115c

Please sign in to comment.