File: test_pickling.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 (36 lines) | stat: -rw-r--r-- 1,006 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
"""
Tests to ensure that mypyc compiled classes are still pickleable.

See https://mypyc.readthedocs.io/en/latest/differences_from_python.html#pickling-and-copying-objects
"""

import pickle
from pathlib import Path

from schema_salad import ref_resolver, schema
from schema_salad.avro.schema import Names, RecordSchema

from .util import get_data_uri


def test_recordschema_pickle() -> None:
    """Targeted test of pickling a RecordSchema."""
    s = RecordSchema("one", None, [], Names())
    print(s)
    d = pickle.dumps(s)
    print(pickle.loads(d))


def test_loader_pickle() -> None:
    """Pickle a Loader."""
    loader = ref_resolver.Loader({})
    print(loader)
    d = pickle.dumps(loader)
    print(pickle.loads(d))


def test_extend_and_specialize_enums(tmp_path: Path) -> None:
    cwl_file_uri = get_data_uri("tests/test_schema/CommonWorkflowLanguage.yml")
    _, avsc_names, _, _ = schema.load_schema(cwl_file_uri)
    print(avsc_names)
    print(pickle.loads(pickle.dumps(avsc_names)))