def validate_qc_metrics(self, qc_metrics): """ Validate the passed metrics against the JSON schema. :param qc_metrics: The quality metrics to be validated. :type qc_metrics: dict, str, or file-like object """ import jsonschema # Judging from the changelog 1.0.0 appears to be the first version # to have fully working support for references. _v = get_dependency_version("jsonschema") if _v < [1, 0, 0]: # pragma: no cover msg = ("Validating the QC metrics requires jsonschema >= 1.0.0 " "You have %s. Please update." % get_dependency_version("jsonschema", raw_string=True)) raise ValueError(msg) schema_path = os.path.join(os.path.dirname(__file__), "data", "wf_metadata_schema.json") with io.open(schema_path, "rt") as fh: schema = json.load(fh) # If passed as a dictionary, serialize and derialize to get the # mapping from Python object to JSON type. if isinstance(qc_metrics, collections_abc.Mapping): qc_metrics = json.loads(self.get_json_meta(validate=False)) elif hasattr(qc_metrics, "read"): qc_metrics = json.load(qc_metrics) else: qc_metrics = json.loads(qc_metrics) jsonschema.validate(qc_metrics, schema)
def validate_qc_metrics(self, qc_metrics): """ Validate the passed metrics against the JSON schema. :param qc_metrics: The quality metrics to be validated. :type qc_metrics: dict, str, or file-like object """ import jsonschema # Judging from the changelog 1.0.0 appears to be the first version # to have fully working support for references. _v = get_dependency_version("jsonschema") if _v < [1, 0, 0]: # pragma: no cover msg = ("Validating the QC metrics requires jsonschema >= 1.0.0 " "You have %s. Please update." % get_dependency_version("jsonschema", raw_string=True)) raise ValueError(msg) schema_path = os.path.join(os.path.dirname(__file__), "data", "wf_metadata_schema.json") with io.open(schema_path, "rt") as fh: schema = json.load(fh) # If passed as a dictionary, serialize and derialize to get the # mapping from Python object to JSON type. if isinstance(qc_metrics, collections.Mapping): qc_metrics = json.loads(self.get_json_meta(validate=False)) elif hasattr(qc_metrics, "read"): qc_metrics = json.load(qc_metrics) else: qc_metrics = json.loads(qc_metrics) jsonschema.validate(qc_metrics, schema)
def test_get_matplotlib_version(self): """ Tests for the get_matplotlib_version() function as it continues to cause problems. """ versions = (("1.2.3", [1, 2, 3]), ("0.9.11", [0, 9, 11]), ("0.9.svn", [0, 9, 0]), ("1.1.1~rc1-1", [1, 1, 1]), ("1.2.x", [1, 2, 0]), ("1.3.1rc2", [1, 3, 1])) for version_string, expected in versions: with mock.patch('pkg_resources.get_distribution') as p: class _D(object): version = version_string p.return_value = _D() got = get_dependency_version('matplotlib') self.assertEqual(expected, got)
import os import unittest import numpy as np import obspy from obspy.core.util.base import NamedTemporaryFile, get_dependency_version # A bit wild to import a utility function from another test suite ... from obspy.io.mseed.tests.test_mseed_util import _create_mseed_file from obspy.signal.quality_control import MSEEDMetadata try: import jsonschema # NOQA # 1.0.0 is the first version with full $ref support. if get_dependency_version("jsonschema") < [1, 0, 0]: HAS_JSONSCHEMA = False else: HAS_JSONSCHEMA = True except ImportError: HAS_JSONSCHEMA = False class QualityControlTestCase(unittest.TestCase): """ Test cases for Quality Control. """ def setUp(self): # Directory where the test files are located self.path = os.path.join(os.path.dirname(__file__), "data")
""" import os import unittest import numpy as np import obspy from obspy.core.util.base import NamedTemporaryFile, get_dependency_version # A bit wild to import a utility function from another test suite ... from obspy.io.mseed.tests.test_mseed_util import _create_mseed_file from obspy.signal.quality_control import MSEEDMetadata try: import jsonschema # NOQA # 1.0.0 is the first version with full $ref support. if get_dependency_version("jsonschema") < [1, 0, 0]: HAS_JSONSCHEMA = False else: HAS_JSONSCHEMA = True except ImportError: HAS_JSONSCHEMA = False class QualityControlTestCase(unittest.TestCase): """ Test cases for Quality Control. """ def setUp(self): # Directory where the test files are located self.path = os.path.join(os.path.dirname(__file__), "data")