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

Clean up test dependencies, add python 3.12 testing #1633

Merged
merged 6 commits into from
Sep 29, 2023
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 30 additions & 3 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -117,23 +116,6 @@ def test_atomic_write(tmp_path, small_tree):
ff.write_to(tmpfile)


def test_overwrite(tmp_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue mentioned for this test:
#100

describes that it was added to try and replicate an issue on windows. The test did not replicate the issue: #302 (comment)
yet the test was left in place.

"""
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
5 changes: 4 additions & 1 deletion asdf/_tests/test_asdf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import fsspec
import pytest

from asdf import config_context
Expand Down Expand Up @@ -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"
Expand All @@ -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")
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 @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion asdf/_tests/test_generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import urllib.request as urllib_request

import fsspec
import numpy as np
import pytest

Expand Down Expand Up @@ -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"

Expand All @@ -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")

Expand Down
43 changes: 32 additions & 11 deletions asdf/_tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,43 @@


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

Check warning on line 78 in asdf/_tests/test_schema.py

View check run for this annotation

Codecov / codecov/patch

asdf/_tests/test_schema.py#L78

Added line #L78 was not covered by tests

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
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = [
Expand Down
7 changes: 4 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Loading