File: test_misc.py

package info (click to toggle)
python-schema-salad 8.9.20250408123006-1
  • links: PTS, VCS
  • area: main
  • in suites: 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 (40 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download | duplicates (3)
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
from typing import Optional, Union

from rdflib.graph import Graph

from schema_salad.avro.schema import Names
from schema_salad.schema import load_schema

from .util import get_data, get_path


def test_misc() -> None:
    path = get_data("tests/test_schema/no_field_schema.yml")
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(path)
    assert isinstance(avsc_names, Names)


def test_load_schema_cache() -> None:
    schemaid = "http://commonwl.org/schema_salad/test/schema.yml"

    path1 = get_path("tests/test_schema/misc_schema_v1.yml")

    with path1.open() as f:
        cache1: Optional[dict[str, Union[str, Graph, bool]]] = {schemaid: f.read()}

    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        schemaid, cache=cache1
    )
    assert isinstance(avsc_names, Names)
    assert "EmptyType" not in document_loader.vocab

    path2 = get_path("tests/test_schema/misc_schema_v2.yml")

    with path2.open() as f:
        cache2: Optional[dict[str, Union[str, Graph, bool]]] = {schemaid: f.read()}

    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        schemaid, cache=cache2
    )
    assert isinstance(avsc_names, Names)
    assert "EmptyType" in document_loader.vocab