def test_self_reference_resolution(): r = resolver.Resolver(CustomExtension().url_mapping, 'url') s = schema.load_schema(os.path.join(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]
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]
FITS_VALIDATORS.update({ 'fits_keyword': _fits_element_writer, 'ndim': _fits_array_writer, 'max_ndim': _fits_array_writer, 'datatype': _fits_array_writer, 'items': _fits_item_recurse, 'properties': _fits_comment_section_handler, 'type': _fits_type }) META_SCHEMA_PATH = os.path.abspath( os.path.join(os.path.dirname(__file__), 'metaschema')) FITS_SCHEMA_URL_MAPPING = resolver.Resolver( [('http://stsci.edu/schemas/fits-schema/', 'file://' + META_SCHEMA_PATH + '/{url_suffix}.yaml')] + resolver.DEFAULT_URL_MAPPING, 'url') def _save_from_schema(hdulist, tree, schema): def convert_datetimes(node, json_id): if isinstance(node, datetime.datetime): node = time.Time(node) if isinstance(node, time.Time): node = str(time.Time(node, format='iso')) return node tree = treeutil.walk_and_modify(tree, convert_datetimes) validator = asdf_schema.get_validator(schema, None, FITS_VALIDATORS, FITS_SCHEMA_URL_MAPPING)
import os from pkgutil import find_loader import asdf from asdf import resolver as res DIRNAME = os.path.dirname(__file__) if DIRNAME == os.path.abspath(os.curdir): # Override the default ASDF url mapping so that all ASDF Standard schemas # resolve to the ones that are present in this repository, rather than # those that are installed with the ASDF python package. This allows for # much more direct testing of changes to schemas in this repository. ASDF_SCHEMA_URL_MAPPING = [ (asdf.constants.STSCI_SCHEMA_URI_BASE, asdf.util.filepath_to_url( os.path.join(DIRNAME, 'schemas', 'stsci.edu')) + '/{url_suffix}.yaml') ] res.default_url_mapping = res.Resolver(ASDF_SCHEMA_URL_MAPPING, 'url') # Only add this plugin definition when not being run as part of a submodule # Account for the fact that asdf-2.4.0 and later registers the plugin as an # entry point, and this module no longer exists. But we want to retain # backwards compatibility with older versions. if find_loader('asdf.tests.schema_tester'): pytest_plugins = ['asdf.tests.schema_tester']