pytest_jsonschema_snapshot.tools

Submodules

Classes

JsonToSchemaConverter

A thin wrapper around genson.SchemaBuilder.

NameMaker

Lightweight helper that converts a callable into a string identifier

Package Contents

class JsonToSchemaConverter(
schema_uri: str = 'https://json-schema.org/draft/2020-12/schema',
*,
format_mode: _FormatMode = 'on',
)[source]

A thin wrapper around genson.SchemaBuilder.

add_object(obj: Any, path: str = 'root') None[source]

Modify the schema to accommodate an object.

Parameters:

obj – any object or scalar that can be serialized in JSON

to_schema() Dict[str, Any][source]

Generate a schema based on previous inputs.

Return type:

dict

class NameMaker[source]

Lightweight helper that converts a callable into a string identifier using a tiny placeholder-based template language (keeps backward compatibility with the original test-suite).

Supported placeholders

{package} – full module path (tests.test_mod)

{package_full=SEP} – same but with custom separator (default “.”)

{path} / {path=SEP} – module path without the first segment

{class} – class name or empty string

{method} – function / method name

{class_method} / {…=SEP}Class{SEP}method or just method

Unknown placeholders collapse to an empty string.

After substitution:
  • “//”, “..”, “–” are collapsed to “/”, “.”, “-” respectively;

  • double underscores are preserved so __call__ stays intact.

static format(obj: Callable[Ellipsis, object], rule: str) str[source]

Render rule using metadata extracted from obj.