Skip to content

Commit

Permalink
Merge pull request #1076 from eslavich/eslavich-try-plugin-fix
Browse files Browse the repository at this point in the history
Remove schema version parsing from the pytest plugin
  • Loading branch information
WilliamJamieson authored Feb 7, 2022
2 parents 3f4cdbf + 7140540 commit 573b572
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 55 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

- Fix deprecation warnings stemming from the release of pytest 7.0.0. [#1075]

- Fix bug in pytest plugin when schemas are not in a directory named "schemas". [#1076]

2.9.1 (2022-02-03)
------------------

Expand Down
57 changes: 2 additions & 55 deletions pytest_asdf/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import io
import os
import warnings
from importlib.util import find_spec
from pkg_resources import parse_version
import pathlib
import warnings

import yaml
import pytest
Expand Down Expand Up @@ -151,41 +149,6 @@ def reportinfo(self):
return self.fspath, 0, ""


ASTROPY_4_0_TAGS = {
'tag:stsci.edu:asdf/transform/rotate_sequence_3d',
'tag:stsci.edu:asdf/transform/ortho_polynomial',
'tag:stsci.edu:asdf/transform/fix_inputs',
'tag:stsci.edu:asdf/transform/math_functions',
'tag:stsci.edu:asdf/time/time',
}


def should_skip(name, version):
if name == 'tag:stsci.edu:asdf/transform/multiplyscale':
return not is_min_astropy_version('3.1.dev0')
elif name in ASTROPY_4_0_TAGS:
return not is_min_astropy_version('4.0')

return False


def is_min_astropy_version(min_version):
astropy = find_spec('astropy')
if astropy is None:
return False

import astropy
return parse_version(astropy.version.version) >= parse_version(min_version)


def parse_schema_filename(filename):
from asdf import versioning
components = filename[filename.find('schemas') + 1:].split(os.path.sep)
tag = 'tag:{}:{}'.format(components[1], '/'.join(components[2:]))
name, version = versioning.split_tag_version(tag.replace('.yaml', ''))
return name, version


class AsdfSchemaExampleItem(pytest.Item):
@classmethod
def from_parent(cls, parent, schema_path, example, example_index,
Expand All @@ -202,29 +165,13 @@ def from_parent(cls, parent, schema_path, example, example_index,
result.ignore_version_mismatch = ignore_version_mismatch
return result

def _find_standard_version(self, name, version):
from asdf import versioning
for sv in reversed(versioning.supported_versions):
map_version = versioning.get_version_map(sv)['tags'].get(name)
if map_version is not None and version == map_version:
return sv

return versioning.default_version

def runtest(self):
from asdf import AsdfFile, block, util
from asdf.tests import helpers

name, version = parse_schema_filename(self.filename)
if should_skip(name, version):
return

standard_version = self._find_standard_version(name, version)

# Make sure that the examples in the schema files (and thus the
# ASDF standard document) are valid.
buff = helpers.yaml_to_asdf(
'example: ' + self.example.strip(), standard_version=standard_version)
buff = helpers.yaml_to_asdf('example: ' + self.example.strip())

ff = AsdfFile(
uri=util.filepath_to_url(os.path.abspath(self.filename)),
Expand Down

0 comments on commit 573b572

Please sign in to comment.