File: test_schemas_directive.py

package info (click to toggle)
python-schema-salad 8.9.20250408123006-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,056 kB
  • sloc: python: 19,177; cpp: 2,631; cs: 1,869; java: 1,341; makefile: 187; xml: 184; sh: 103; javascript: 46
file content (48 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Checks for accepting $schemas directive

run individually as py.test -k tests/test_schemas_directive.py
"""

import os
from typing import Any, Optional, Union

from schema_salad.avro.schema import Names, SchemaParseException
from schema_salad.ref_resolver import Loader
from schema_salad.schema import load_and_validate, load_schema

from .util import get_data

test_dir_name = "tests/"


class TestSchemasDirective:
    """Ensure codegen-produced parsers accept $schemas directives"""

    document_loader: Loader
    avsc_names: Union[Names, SchemaParseException, None] = None
    schema_metadata: Optional[dict[str, Any]] = None
    metaschema_loader: Optional[Loader] = None

    @classmethod
    def setup_class(cls) -> None:
        path = get_data("tests/test_schema/CommonWorkflowLanguage.yml")
        (
            cls.document_loader,
            cls.avsc_names,
            schema_metadata,
            metaschema_loader,
        ) = load_schema(path)

    def load_cwl(self, src: str) -> tuple[Any, dict[str, Any]]:
        path = get_data(test_dir_name + src)
        assert isinstance(self.avsc_names, Names)
        res = load_and_validate(self.document_loader, self.avsc_names, path, True)
        return res

    def test_dollarsign_schema(self) -> None:
        """EDAM.owl as a schema"""
        res = self.load_cwl(src="formattest2.cwl")

        # EDAM.owl resides in this directory
        assert os.path.split(str(res[0]["$schemas"][0]))[1] == "EDAM.owl"