예제 #1
0
def test_custom_validation_with_definitions_bad(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema_definitions.yaml')
    asdf_file = os.path.join(str(tmpdir), 'out.asdf')

    # This tree does NOT conform to the custom schema
    tree = {
        'forb': { 'biz': 'hello', 'baz': 'world' }
    }

    # Creating file without custom schema should pass
    with asdf.AsdfFile(tree) as ff:
        ff.write_to(asdf_file)

    # Creating file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
            pass

    # Opening file without custom schema should pass
    with asdf.open(asdf_file) as ff:
        pass

    # Opening file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.open(asdf_file, custom_schema=custom_schema_path) as ff:
            pass
예제 #2
0
def test_custom_validation_with_external_ref_bad(tmpdir):
    custom_schema_path = helpers.get_test_data_path(
        'custom_schema_external_ref.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree does not conform to the custom schema
    tree = {'foo': False}

    # Creating file without custom schema should pass
    with asdf.AsdfFile(tree) as ff:
        ff.write_to(asdf_file)

    # Creating file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.AsdfFile(tree, custom_schema=custom_schema_path):
            pass

    # Opening file without custom schema should pass
    with asdf.open(asdf_file):
        pass

    # Opening file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.open(asdf_file, custom_schema=custom_schema_path):
            pass
예제 #3
0
def test_custom_validation_with_definitions_bad(tmpdir):
    custom_schema_path = helpers.get_test_data_path(
        'custom_schema_definitions.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree does NOT conform to the custom schema
    tree = {'forb': {'biz': 'hello', 'baz': 'world'}}

    # Creating file without custom schema should pass
    with asdf.AsdfFile(tree) as ff:
        ff.write_to(asdf_file)

    # Creating file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.AsdfFile(tree, custom_schema=custom_schema_path):
            pass

    # Opening file without custom schema should pass
    with asdf.open(asdf_file):
        pass

    # Opening file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.open(asdf_file, custom_schema=custom_schema_path):
            pass
예제 #4
0
def test_self_reference_resolution():
    r = resolver.Resolver(CustomExtension().url_mapping, 'url')
    s = schema.load_schema(
        helpers.get_test_data_path('self_referencing-1.0.0.yaml'),
        resolver=r,
        resolve_references=True)
    assert '$ref' not in repr(s)
    assert s['anyOf'][1] == s['anyOf'][0]
예제 #5
0
def test_self_reference_resolution():
    r = resolver.Resolver(CustomExtension().url_mapping, 'url')
    s = schema.load_schema(
        helpers.get_test_data_path('self_referencing-1.0.0.yaml'),
        resolver=r,
        resolve_references=True)
    assert '$ref' not in repr(s)
    assert s['anyOf'][1] == s['anyOf'][0]
예제 #6
0
def test_read_json_schema():
    """Pytest to make sure reading JSON schemas succeeds.

    This was known to fail on Python 3.5 See issue #314 at
    https://github.com/asdf-format/asdf/issues/314 for more details.
    """
    json_schema = helpers.get_test_data_path('example_schema.json')
    schema_tree = schema.load_schema(json_schema, resolve_references=True)
    schema.check_schema(schema_tree)
예제 #7
0
def test_read_json_schema():
    """Pytest to make sure reading JSON schemas succeeds.

    This was known to fail on Python 3.5 See issue #314 at
    https://github.com/spacetelescope/asdf/issues/314 for more details.
    """
    json_schema = helpers.get_test_data_path('example_schema.json')
    schema_tree = schema.load_schema(json_schema, resolve_references=True)
    schema.check_schema(schema_tree)
예제 #8
0
def test_custom_validation_good(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree conforms to the custom schema
    tree = {'foo': {'x': 42, 'y': 10}, 'bar': {'a': 'hello', 'b': 'banjo'}}

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path):
        pass
예제 #9
0
def test_custom_validation_with_definitions_good(tmpdir):
    custom_schema_path = helpers.get_test_data_path(
        'custom_schema_definitions.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree conforms to the custom schema
    tree = {'thing': {'biz': 'hello', 'baz': 'world'}}

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path):
        pass
예제 #10
0
def test_custom_validation_with_definitions_good(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema_definitions.yaml')
    asdf_file = os.path.join(str(tmpdir), 'out.asdf')

    # This tree conforms to the custom schema
    tree = {
        'thing': { 'biz': 'hello', 'baz': 'world' }
    }

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path) as ff:
        pass
예제 #11
0
def test_custom_validation_good(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema.yaml')
    asdf_file = os.path.join(str(tmpdir), 'out.asdf')

    # This tree conforms to the custom schema
    tree = {
        'foo': {'x': 42, 'y': 10},
        'bar': {'a': 'hello', 'b': 'banjo'}
    }

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path) as ff:
        pass
예제 #12
0
def test_custom_validation_with_external_ref_good(tmpdir):
    custom_schema_path = helpers.get_test_data_path(
        'custom_schema_external_ref.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree conforms to the custom schema
    tree = {
        'foo': asdf.tags.core.Software(name="Microsoft Windows", version="95")
    }

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path):
        pass
예제 #13
0
def test_custom_validation_pathlib(tmpdir):
    """
    Make sure custom schema paths can be pathlib.Path objects

    See https://github.com/asdf-format/asdf/issues/653 for discussion.
    """
    from pathlib import Path

    custom_schema_path = Path(helpers.get_test_data_path('custom_schema.yaml'))
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree conforms to the custom schema
    tree = {'foo': {'x': 42, 'y': 10}, 'bar': {'a': 'hello', 'b': 'banjo'}}

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path):
        pass
예제 #14
0
def test_custom_validation_pathlib(tmpdir):
    """
    Make sure custom schema paths can be pathlib.Path objects

    See https://github.com/spacetelescope/asdf/issues/653 for discussion.
    """
    from pathlib import Path

    custom_schema_path = Path(helpers.get_test_data_path('custom_schema.yaml'))
    asdf_file = os.path.join(str(tmpdir), 'out.asdf')

    # This tree conforms to the custom schema
    tree = {
        'foo': {'x': 42, 'y': 10},
        'bar': {'a': 'hello', 'b': 'banjo'}
    }

    with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
        ff.write_to(asdf_file)

    with asdf.open(asdf_file, custom_schema=custom_schema_path) as ff:
        pass
예제 #15
0
def test_custom_validation_bad(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema.yaml')
    asdf_file = str(tmpdir.join('out.asdf'))

    # This tree does not conform to the custom schema
    tree = {'stuff': 42, 'other_stuff': 'hello'}

    # Creating file without custom schema should pass
    with asdf.AsdfFile(tree) as ff:
        ff.write_to(asdf_file)

    # Creating file using custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.AsdfFile(tree, custom_schema=custom_schema_path):
            pass

    # Opening file without custom schema should pass
    with asdf.open(asdf_file):
        pass

    # Opening file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.open(asdf_file, custom_schema=custom_schema_path):
            pass
예제 #16
0
def test_custom_validation_bad(tmpdir):
    custom_schema_path = helpers.get_test_data_path('custom_schema.yaml')
    asdf_file = os.path.join(str(tmpdir), 'out.asdf')

    # This tree does not conform to the custom schema
    tree = {'stuff': 42, 'other_stuff': 'hello'}

    # Creating file without custom schema should pass
    with asdf.AsdfFile(tree) as ff:
        ff.write_to(asdf_file)

    # Creating file using custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.AsdfFile(tree, custom_schema=custom_schema_path) as ff:
            pass

    # Opening file without custom schema should pass
    with asdf.open(asdf_file) as ff:
        pass

    # Opening file with custom schema should fail
    with pytest.raises(ValidationError):
        with asdf.open(asdf_file, custom_schema=custom_schema_path) as ff:
            pass
예제 #17
0
import numpy as np
from numpy import ma
from numpy.testing import assert_array_equal

import jsonschema

import yaml

import asdf
from asdf import util
from asdf.tests import helpers, CustomTestType
from asdf.tags.core import ndarray

from . import data as test_data
TEST_DATA_PATH = helpers.get_test_data_path('', module=test_data)


# These custom types and the custom extension are here purely for the purpose
# of testing NDArray objects and making sure that they can be validated as part
# of a nested hierarchy, and not just top-level objects.
class CustomNdim(CustomTestType):
    name = 'ndim'
    organization = 'nowhere.org'
    standard = 'custom'
    version = '1.0.0'


class CustomDatatype(CustomTestType):
    name = 'datatype'
    organization = 'nowhere.org'
예제 #18
0
def test_load_custom_schema_deprecated():
    custom_schema_path = helpers.get_test_data_path('custom_schema.yaml')

    with pytest.deprecated_call():
        schema.load_custom_schema(custom_schema_path)
예제 #19
0
def test_load_schema_resolve_local_refs_deprecated():
    custom_schema_path = helpers.get_test_data_path(
        'custom_schema_definitions.yaml')

    with pytest.deprecated_call():
        schema.load_schema(custom_schema_path, resolve_local_refs=True)
예제 #20
0
파일: test_schema.py 프로젝트: eteq/asdf
 def url_mapping(self):
     return [('http://nowhere.org/schemas/custom/',
              util.filepath_to_url(helpers.get_test_data_path('')) +
              '/{url_suffix}.yaml')]
예제 #21
0
import numpy as np
from numpy import ma
from numpy.testing import assert_array_equal

import jsonschema

import yaml

import asdf
from asdf import util
from asdf.tests import helpers, CustomTestType
from asdf.tags.core import ndarray

from . import data as test_data
TEST_DATA_PATH = helpers.get_test_data_path('', module=test_data)


# These custom types and the custom extension are here purely for the purpose
# of testing NDArray objects and making sure that they can be validated as part
# of a nested hierarchy, and not just top-level objects.
class CustomNdim(CustomTestType):
    name = 'ndim'
    organization = 'nowhere.org'
    standard = 'custom'
    version = '1.0.0'


class CustomDatatype(CustomTestType):
    name = 'datatype'
    organization = 'nowhere.org'
예제 #22
0
 def url_mapping(self):
     return [('http://nowhere.org/schemas/custom/',
              util.filepath_to_url(helpers.get_test_data_path('')) +
              '/{url_suffix}.yaml')]