File: test_integration.py

package info (click to toggle)
asdf-astropy 0.3.0%2Bgithub-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 556 kB
  • sloc: python: 3,703; makefile: 109
file content (78 lines) | stat: -rw-r--r-- 2,895 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
from pathlib import Path

import asdf
import yaml


def test_resources():
    resources_root = Path(__file__).parent.parent / "resources"
    resource_manager = asdf.get_config().resource_manager

    for resource_path in resources_root.glob("**/*.yaml"):
        with resource_path.open("rb") as f:
            resource_content = f.read()
        resource = yaml.safe_load(resource_content)
        resource_uri = resource["id"]
        assert resource_manager[resource_uri] == resource_content


def test_manifests():
    manifests_root = Path(__file__).parent.parent / "resources" / "manifests"
    resource_manager = asdf.get_config().resource_manager

    for manifest_path in manifests_root.glob("*.yaml"):
        with manifest_path.open("rb") as f:
            manifest_content = f.read()
        manifest = yaml.safe_load(manifest_content)

        manifest_schema = asdf.schema.load_schema("asdf://asdf-format.org/core/schemas/extension_manifest-1.0.0")

        # The manifest must be valid against its own schema:
        asdf.schema.validate(manifest, schema=manifest_schema)

        for tag_definition in manifest["tags"]:
            # The tag's schema must be available:
            assert tag_definition["schema_uri"] in resource_manager


def test_extensions():
    package_and_uri_pairs = {(e.package_name, e.extension_uri) for e in asdf.get_config().extensions}

    assert ("asdf-astropy", "asdf://astropy.org/astropy/extensions/astropy-1.0.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.0.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.1.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.2.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.3.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.4.0") in package_and_uri_pairs
    assert ("asdf-astropy", "asdf://asdf-format.org/transform/extensions/transform-1.5.0") in package_and_uri_pairs


_ASTROPY_MODULES = [
    "astropy.coordinates",
    "astropy.io",
    "astropy.modeling",
    "astropy.table",
    "astropy.time",
    "astropy.units",
]


def test_no_astropy_import():
    """
    Confirm that none of the ASDF plugins import astropy modules
    at import time.
    """

    keys = [
        k for k in sys.modules.keys() if k.startswith("asdf_astropy") or any(k.startswith(m) for m in _ASTROPY_MODULES)
    ]
    for key in keys:
        del sys.modules[key]

    from asdf_astropy import integration

    integration.get_resource_mappings()
    integration.get_extensions()

    assert not any(k for k in sys.modules.keys() if any(k.startswith(m) for m in _ASTROPY_MODULES))