示例#1
0
def test_versioned_writing():
    from ..tags.core.complex import ComplexType

    # Create a bogus version map
    versioning._version_map['42.0.0'] = {
        'FILE_FORMAT': '42.0.0',
        'YAML_VERSION': '1.1',
        'tags': {
            'tag:stsci.edu:asdf/core/complex': '42.0.0',
            'tag:stscu.edu:asdf/core/asdf': '1.0.0'
        }
    }

    versioning.supported_versions.append(versioning.AsdfVersion('42.0.0'))

    # Currently this class cannot inherit directly from ComplexType because if
    # it does it pollutes ASDF's built-in extension and causes later tests that
    # rely on ComplexType to fail. However, if CustomType is ever implemented
    # as an abstract base class, then it will be possible to use it as a mix-in
    # and also inherit from ComplexType. This means the only method/attribute
    # that will need to be explicitly defined will be 'version'.
    class FancyComplexType(asdftypes.CustomType):
        name = ComplexType.name
        version = (42, 0, 0)
        types = ComplexType.types

        @classmethod
        def to_tree(cls, node, ctx):
            return ComplexType.to_tree(node, ctx)

        @classmethod
        def from_tree(cls, tree, ctx):
            return ComplexType.from_tree(tree, ctx)

    class FancyComplexExtension(object):
        @property
        def types(self):
            return [FancyComplexType]

        @property
        def tag_mapping(self):
            return []

        @property
        def url_mapping(self):
            return [('http://stsci.edu/schemas/asdf/core/complex-42.0.0',
                     util.filepath_to_url(TEST_DATA_PATH) +
                     '/complex-42.0.0.yaml')]

    tree = {'a': complex(0, -1)}

    buff = io.BytesIO()
    ff = asdf.AsdfFile(tree, version="42.0.0",
                       extensions=[FancyComplexExtension()])
    ff.write_to(buff)

    assert b'complex-42.0.0' in buff.getvalue()

    del versioning._version_map['42.0.0']
    versioning.supported_versions.pop()
示例#2
0
def test_versioned_writing(monkeypatch):
    from ..tags.core.complex import ComplexType

    # Create a bogus version map
    monkeypatch.setitem(
        versioning._version_map, '42.0.0', {
            'FILE_FORMAT': '42.0.0',
            'YAML_VERSION': '1.1',
            'tags': {
                'tag:stsci.edu:asdf/core/complex': '42.0.0',
                'tag:stscu.edu:asdf/core/asdf': '1.0.0'
            }
        })

    # Add bogus version to supported versions
    monkeypatch.setattr(
        versioning, 'supported_versions',
        versioning.supported_versions + [versioning.AsdfVersion('42.0.0')])

    class FancyComplexType(asdftypes.CustomType):
        name = 'core/complex'
        organization = 'stsci.edu'
        standard = 'asdf'
        version = (42, 0, 0)
        types = [complex]

        @classmethod
        def to_tree(cls, node, ctx):
            return ComplexType.to_tree(node, ctx)

        @classmethod
        def from_tree(cls, tree, ctx):
            return ComplexType.from_tree(tree, ctx)

    class FancyComplexExtension(object):
        @property
        def types(self):
            return [FancyComplexType]

        @property
        def tag_mapping(self):
            return []

        @property
        def url_mapping(self):
            return [
                ('http://stsci.edu/schemas/asdf/core/complex-42.0.0',
                 util.filepath_to_url(TEST_DATA_PATH) + '/complex-42.0.0.yaml')
            ]

    tree = {'a': complex(0, -1)}

    buff = io.BytesIO()
    ff = asdf.AsdfFile(tree,
                       version="42.0.0",
                       extensions=[FancyComplexExtension()])
    ff.write_to(buff)

    assert b'complex-42.0.0' in buff.getvalue()
示例#3
0
def test_versioned_writing():
    from ..tags.core.complex import ComplexType

    # Create a bogus version map
    versioning._version_map['42.0.0'] = {
        'FILE_FORMAT': '42.0.0',
        'YAML_VERSION': '1.1',
        'tags': {
            'tag:stsci.edu:asdf/core/complex': '42.0.0',
            'tag:stscu.edu:asdf/core/asdf': '1.0.0'
        }
    }

    versioning.supported_versions.append(versioning.AsdfVersion('42.0.0'))

    class FancyComplexType(ComplexType, asdftypes.CustomType):
        version = (42, 0, 0)

    # This is a sanity check to ensure that the custom FancyComplexType does
    # not get added to ASDF's built-in extension, since this would cause any
    # subsequent tests that rely on ComplexType to fail.
    assert not issubclass(FancyComplexType, asdftypes.AsdfTypeMeta)

    class FancyComplexExtension(object):
        @property
        def types(self):
            return [FancyComplexType]

        @property
        def tag_mapping(self):
            return []

        @property
        def url_mapping(self):
            return [
                ('http://stsci.edu/schemas/asdf/core/complex-42.0.0',
                 util.filepath_to_url(TEST_DATA_PATH) + '/complex-42.0.0.yaml')
            ]

    tree = {'a': complex(0, -1)}

    buff = io.BytesIO()
    ff = asdf.AsdfFile(tree,
                       version="42.0.0",
                       extensions=[FancyComplexExtension()])
    ff.write_to(buff)

    assert b'complex-42.0.0' in buff.getvalue()

    del versioning._version_map['42.0.0']
    versioning.supported_versions.pop()
示例#4
0
 class TestType4(asdftypes.CustomType):
     supported_versions = ['1.0.0', versioning.AsdfVersion('1.1.0')]
示例#5
0
 class TestType1(asdftypes.CustomType):
     supported_versions = versioning.AsdfVersion('1.0.0')