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

Deprecate asdf.testing.helpers.format_tag and asdf.versioning.AsdfSpec #1774

Merged
merged 4 commits into from
May 7, 2024
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
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

- Fix ``__asdf_traverse__`` for non-tagged objects [#1739]

- Deprecate ``asdf.testing.helpers.format_tag`` [#1774]

- Deprecate ``asdf.versioning.AsdfSpec`` [#1774]


3.2.0 (2024-04-05)
------------------

Expand Down
6 changes: 6 additions & 0 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

import asdf
import asdf.testing.helpers
from asdf.exceptions import AsdfDeprecationWarning, ValidationError


Expand Down Expand Up @@ -123,3 +124,8 @@ def test_asdffile_version_map_deprecation():
af = asdf.AsdfFile()
with pytest.warns(AsdfDeprecationWarning, match="AsdfFile.version_map is deprecated"):
af.version_map


def test_format_tag_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="format_tag is deprecated"):
asdf.testing.helpers.format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
4 changes: 2 additions & 2 deletions asdf/_tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from asdf import config_context, constants, get_config, schema, tagged, util, yamlutil
from asdf.exceptions import AsdfConversionWarning, AsdfDeprecationWarning, AsdfWarning, ValidationError
from asdf.extension import TagDefinition
from asdf.testing.helpers import format_tag, yaml_to_asdf
from asdf.testing.helpers import yaml_to_asdf


@contextlib.contextmanager
Expand Down Expand Up @@ -837,7 +837,7 @@ def test_self_reference_resolution(test_data_path):

def test_schema_resolved_via_entry_points():
"""Test that entry points mappings to core schema works"""
tag = format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
tag = "tag:stsci.edu:asdf/fits/fits-1.0.0"
extension_manager = asdf.extension.get_cached_extension_manager(get_config().extensions)
schema_uris = extension_manager.get_tag_definition(tag).schema_uris
assert len(schema_uris) > 0
Expand Down
33 changes: 23 additions & 10 deletions asdf/_tests/test_versioning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from itertools import combinations

import pytest

from asdf.exceptions import AsdfDeprecationWarning
from asdf.versioning import (
AsdfSpec,
AsdfVersion,
Expand Down Expand Up @@ -171,7 +174,8 @@ def test_version_and_tuple_inequality():


def test_spec_version_match():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

assert spec.match(AsdfVersion("1.1.0"))
assert spec.match(AsdfVersion("1.2.0"))
Expand All @@ -180,7 +184,8 @@ def test_spec_version_match():


def test_spec_version_select():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = [AsdfVersion(x) for x in ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]]
assert spec.select(versions) == "1.2.0"
Expand All @@ -189,15 +194,17 @@ def test_spec_version_select():


def test_spec_version_filter():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = [AsdfVersion(x) for x in ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
assert x == y


def test_spec_string_match():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

assert spec.match("1.1.0")
assert spec.match("1.2.0")
Expand All @@ -206,7 +213,8 @@ def test_spec_string_match():


def test_spec_string_select():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]
assert spec.select(versions) == "1.2.0"
Expand All @@ -215,15 +223,17 @@ def test_spec_string_select():


def test_spec_string_filter():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
assert x == y


def test_spec_tuple_match():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

assert spec.match((1, 1, 0))
assert spec.match((1, 2, 0))
Expand All @@ -232,7 +242,8 @@ def test_spec_tuple_match():


def test_spec_tuple_select():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = [(1, 0, 0), (1, 0, 9), (1, 1, 0), (1, 2, 0)]
assert spec.select(versions) == "1.2.0"
Expand All @@ -241,7 +252,8 @@ def test_spec_tuple_select():


def test_spec_tuple_filter():
spec = AsdfSpec(">=1.1.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")

versions = [(1, 0, 0), (1, 0, 9), (1, 1, 0), (1, 2, 0)]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
Expand All @@ -250,7 +262,8 @@ def test_spec_tuple_filter():

def test_spec_equal():
"""Make sure that equality means match"""
spec = AsdfSpec(">=1.2.0")
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.2.0")
version0 = AsdfVersion("1.1.0")
version1 = AsdfVersion("1.3.0")

Expand Down
4 changes: 4 additions & 0 deletions asdf/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
Helpers for writing unit tests of ASDF support.
"""

import warnings
from io import BytesIO

import asdf
from asdf.exceptions import AsdfDeprecationWarning
from asdf.versioning import AsdfSpec


def format_tag(organization, standard, version, tag_name):
"""
Format a YAML tag.
"""
warnings.warn("format_tag is deprecated", AsdfDeprecationWarning)

tag = f"tag:{organization}:{standard}/{tag_name}"

if version is None:
Expand Down
8 changes: 8 additions & 0 deletions asdf/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
of the ASDF spec.
"""

import warnings
from functools import total_ordering

import yaml
from semantic_version import SimpleSpec, Version

from .exceptions import AsdfDeprecationWarning

_yaml_base_loader = yaml.CSafeLoader if getattr(yaml, "__with_libyaml__", None) else yaml.SafeLoader


Expand Down Expand Up @@ -112,7 +115,12 @@ def __init__(self, version):


class AsdfSpec(SimpleSpec):
"""
Deprecated.
"""

def __init__(self, *args, **kwargs):
warnings.warn("AsdfSpec is deprecated.", AsdfDeprecationWarning)
super().__init__(*args, **kwargs)

def match(self, version):
Expand Down
Loading