testplan.common.serialization package

Submodules

testplan.common.serialization.fields module

Custom marshmallow fields.

class testplan.common.serialization.fields.ClassName(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Return the class name of the obj.

class Meta[source]

Bases: object

dump_only = True
class testplan.common.serialization.fields.ColumnContainComparisonField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Serialization logic for ColumnContainComparison

class testplan.common.serialization.fields.DictMatch(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

class testplan.common.serialization.fields.ExceptionField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Serialize exceptions type and message.

class testplan.common.serialization.fields.FormattedValue(value, display)[source]

Bases: testplan.common.serialization.fields.Serializable

Save a formatted value in WebUI

serialize()[source]
class testplan.common.serialization.fields.GenericNested(schema_context, type_field='type', default=<marshmallow.missing>, **kwargs)[source]

Bases: marshmallow.fields.Field

Marshmallow does not support multiple schemas for a single Nested field.

There is a project (marshmallow-oneofschema) that has similar functionality but it doesn’t support self-referencing schemas, which is needed for serializing tree structures.

This field should be used along with ClassNameField to return the type (class name) of the objects, so it can choose the correct schema during deserialization.

schemas

Return schema mapping in <CLASS_NAME>: <SCHEMA_OBJECT> format.

class testplan.common.serialization.fields.LocalDateTime(format: str | None = None, **kwargs)[source]

Bases: marshmallow.fields.DateTime

A formatted datetime string that represents machine time. Naive datetime will be thought as in local timezone. Example: 2014-12-22T11:12:58.019077+08:00

Note: Since Python 3.6 datetime.datetime.astimezone method can be called on naive instances that are presumed to represent system local time.

Bases: testplan.common.serialization.fields.Serializable

Save an HTML link in WebUI

serialize()[source]
class testplan.common.serialization.fields.NativeOrPretty(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Uses serialization compatible native values or pretty formatted str representation.

class testplan.common.serialization.fields.NativeOrPrettyDict(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Dictionary serialization with native or pretty formatted values. Keys should be JSON serializable (str type), should be used for flat dicts only.

class testplan.common.serialization.fields.RowComparisonField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Serialization logic for RowComparison

class testplan.common.serialization.fields.Serializable[source]

Bases: object

serialize()[source]
class testplan.common.serialization.fields.SliceComparisonField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Serialization logic for SliceComparison

class testplan.common.serialization.fields.UTCDateTime(format: str | None = None, **kwargs)[source]

Bases: marshmallow.fields.DateTime

A formatted datetime string that represents UTC time. Naive datetime will be thought as in UTC timezone. Example: 2014-12-22T03:12:58.019077+00:00 (always ends with ‘+00:00’)

class testplan.common.serialization.fields.Unicode(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Field that tries to convert value into a unicode

object with the given codecs. Marshmallow internally decodes to utf-8 encoding, however it fails on Python 2 for str values like @té§tþlåñ.

So we have this field with explicit codecs instead.

codecs = ['utf-8', 'latin-1']
class testplan.common.serialization.fields.XMLElementField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | (typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]]) = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)[source]

Bases: marshmallow.fields.Field

Custom field for lxml.etree.Element serialization.

testplan.common.serialization.fields.native_or_pformat(value)[source]

Generic serialization compatible value formatter.

testplan.common.serialization.fields.native_or_pformat_dict(value)[source]

Converter utility for dictionaries, converts values to JSON friendly format

testplan.common.serialization.fields.native_or_pformat_list(value)[source]

Converter utility for lists, converts values to JSON friendly format

testplan.common.serialization.schemas module

class testplan.common.serialization.schemas.SchemaRegistry[source]

Bases: testplan.common.utils.registry.Registry

Registry class to be used with Marshmallow schemas, provides serialize method that calls dump on the underlying schema mapping.

serialize(obj)[source]
class testplan.common.serialization.schemas.TreeNodeSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]

Bases: marshmallow.schema.Schema

Base class that can be used for defining tree node schemas, compatible with load_tree_data.

classmethod get_source_class()[source]

Wrapper around class level attribute to support inheritance.

opts = <marshmallow.schema.SchemaOpts object>
source_class = None
testplan.common.serialization.schemas.load_tree_data(data, node_schema, leaf_schema, nodes_field='entries', nodes_attr_name='entries', type_field='type')[source]

marshmallow does not support tree serialization with different node types, so we rely on this recursive function for traversing tree data and instantiate node objects with the given schemas.

Module contents

exception testplan.common.serialization.DeserializationError[source]

Bases: Exception

general deserialization error

class testplan.common.serialization.SelectiveSerializable[source]

Bases: abc.ABC

dumps() → bytes[source]

serialize

loads(obj: bytes) → typing_extensions.Self[source]

deserialize

serializable_attrs

Attributes to be included in serialization.

exception testplan.common.serialization.SerializationError[source]

Bases: Exception

general serialization error

testplan.common.serialization.deserialize(data: bytes) → Any[source]
testplan.common.serialization.serialize(obj: Any) → bytes[source]