ds_provider_mock_py_lib

File: __init__.py Region: ds-provider-mock-py-lib

Description

Mock provider for e2e pipeline testing. Read-only, fully deterministic, deterministic change batches for gold merge via primary key and row hash.

Example

from uuid import uuid4

from ds_provider_mock_py_lib import (
    MockDataset,
    MockDatasetSettings,
    MockLinkedService,
    MockLinkedServiceSettings,
)

linked_service = MockLinkedService(
    id=uuid4(),
    name="mock-ls",
    version="1.0.0",
    settings=MockLinkedServiceSettings(),
)
dataset = MockDataset(
    id=uuid4(),
    name="mock-ds",
    version="1.0.0",
    linked_service=linked_service,
    settings=MockDatasetSettings(row_count=10),
)
linked_service.connect()
dataset.read()
print(len(dataset.output.index))

Submodules

Attributes

__version__

Classes

MockColumn

One synthetic column in a mock dataset.

MockDataset

Read-only tabular dataset that emits deterministic synthetic rows.

MockDatasetSettings

Settings that define mock read scope and injected failure behaviour.

MockLinkedService

In-memory linked service with tunable connect, health, and request failures.

MockLinkedServiceSettings

Settings required to connect to the in-memory mock backend.

Package Contents

class ds_provider_mock_py_lib.MockColumn[source]

Bases: ds_common_serde_py_lib.Serializable

One synthetic column in a mock dataset.

name: str

Column name emitted in self.output.

kind: ds_provider_mock_py_lib.enums.ColumnKind

Value generator used for this column.

value: Any = None

Payload for constant and enum.

A scalar is emitted on every row when kind is constant. A non-empty list is sampled when kind is enum.

prefix: str = ''

Prefix used when kind is text.

low: int = 0

Inclusive lower bound for random numeric kinds.

high: int = 1000

Exclusive upper bound for random numeric kinds.

null_every: int | None = None

When set, every Nth id is None (stable across batches).

class ds_provider_mock_py_lib.MockDataset[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.TabularDataset[ds_provider_mock_py_lib.linked_service.mock.MockLinkedService, ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, ds_resource_plugin_py_lib.common.serde.serialize.PandasSerializer, ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializer]

Read-only tabular dataset that emits deterministic synthetic rows.

linked_service: ds_provider_mock_py_lib.linked_service.mock.MockLinkedService
settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings
serializer: ds_resource_plugin_py_lib.common.serde.serialize.PandasSerializer | None
deserializer: ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializer | None
__post_init__() None[source]

Ensure serializer and deserializer are always available.

property supports_checkpoint: bool

Whether this dataset supports incremental loads via self.checkpoint.

Returns:

Always True for the mock provider.

Return type:

bool

property type: ds_provider_mock_py_lib.enums.ResourceType

Get the type of the dataset.

Returns:

ResourceType

read() None[source]

Read the current mock batch into self.output.

An empty checkpoint performs a full load (batch 0). A populated incremental watermark reads the next change batch. A pagination cursor resumes an in-flight batch after failure.

Raises:
  • ReadError – If the mock backend fails or settings are invalid for read.

  • ConnectionError – If dataset-level injection is configured as a connection error.

create() NoReturn[source]

Create is not supported by this dataset.

update() NoReturn[source]

Update is not supported by this dataset.

upsert() NoReturn[source]

Upsert is not supported by this dataset.

delete() NoReturn[source]

Delete is not supported by this dataset.

purge() NoReturn[source]

Purge is not supported by this dataset.

rename() NoReturn[source]

Rename is not supported by this dataset.

list() NoReturn[source]

List is not supported by this dataset.

close() None[source]

Close the dataset and underlying linked service.

_unsupported(method: str) NoReturn[source]

Raise NotSupportedError for a read-only method.

Parameters:

method – Dataset method name.

Raises:

NotSupportedError – Always.

class ds_provider_mock_py_lib.MockDatasetSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.DatasetSettings

Settings that define mock read scope and injected failure behaviour.

columns: list[MockColumn]

Synthetic columns included in every emitted row.

row_count: int = 100

Rows in the full load (batch 0, all inserts).

incremental_insert_count: int = 0

New unique primary keys delivered in each incremental batch.

incremental_update_count: int = 0

Existing primary keys re-delivered with changed column values (row hash changes).

incremental_noop_count: int = 0

Existing primary keys re-delivered with an identical row (same hash).

page_size: int | None = None

Page size. None emits the whole batch in one page.

seed: int = 42

Determinism seed for id selection and random cell values.

page_delay_ms: int = 0

Artificial delay applied after each successful page.

op_column: str | None = None

Optional label column for intended row kind.

Gold merge uses primary key plus row hash, not this column. Leave unset so the label cannot change the hash of a noop row. Counts are always in operation.metadata["ops"].

modified_at_column: str = '_modified_at'

Column that stores the deterministic modified-at timestamp.

raise_on_page: int | None = None

1-based page number within the current batch that should fail. None disables.

raise_as: ds_provider_mock_py_lib.enums.RaiseAs

Contract exception class used when raise_on_page matches.

raise_error: ds_provider_mock_py_lib.models.MockError

Error spec used when raise_on_page matches.

class ds_provider_mock_py_lib.MockLinkedService[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedService[MockLinkedServiceSettings]

In-memory linked service with tunable connect, health, and request failures.

settings: MockLinkedServiceSettings
_connection: MockBackend | None = None
_connect_attempts: int = 0
property type: ds_provider_mock_py_lib.enums.ResourceType

Get the type of the linked service.

Returns:

ResourceType

property connection: MockBackend

Return the mock backend established by connect().

Returns:

The connected backend handle.

Return type:

MockBackend

Raises:

ConnectionError – If connect() has not been called.

connect() None[source]

Establish a connection to the mock backend.

Raises:
  • ConnectionError – When connect is configured to fail or is still in the transient-failure window.

  • AuthenticationError – When connect_behaviour is authentication_error.

  • AuthorizationError – When connect_behaviour is authorization_error.

test_connection() tuple[bool, str][source]

Verify mock backend health without raising on failure.

Returns:

(True, "") on success, otherwise (False, reason).

Return type:

tuple[bool, str]

close() None[source]

Release the mock backend handle. Safe to call repeatedly.

class ds_provider_mock_py_lib.MockLinkedServiceSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedServiceSettings

Settings required to connect to the in-memory mock backend.

connect_behaviour: ds_provider_mock_py_lib.enums.ConnectBehaviour

What connect() does after optional transient failures.

connect_delay_ms: int = 0

Artificial delay applied during connect().

connect_fail_first_n: int = 0

First N connect() calls raise ConnectionError, then succeed.

connect_error: ds_provider_mock_py_lib.models.MockError

Error spec used when connect() is configured to fail.

test_connection_ok: bool = True

When False, test_connection() returns a failed health check.

test_connection_message: str = ''

Reason returned when test_connection_ok is False.

latency_ms: int = 0

Artificial delay applied to every connection.request() call.

fail_on_call: int | None = None

Raise MockBackendError on the Nth request() call. None disables.

request_error: ds_provider_mock_py_lib.models.MockError

Error spec used when fail_on_call matches.

drop_after_calls: int | None = None

Every request() after N calls raises. None disables.

drop_error: ds_provider_mock_py_lib.models.MockError

Error spec used when the connection is dropped after N calls.

ds_provider_mock_py_lib.__version__