id_translation.testing#

Test implementations.

Classes

TestFetcher([sources])

Dummy Fetcher implementation.

TestMapper([score_function, ...])

Dummy Mapper implementation.

class TestFetcher(sources=None)[source]#

Bases: Fetcher[SourceType, IdType]

Dummy Fetcher implementation.

A “happy path” fetcher implementation for testing purposes. Returns generated names for all IDs and placeholders, so translation retrieval will never fail when using this fetcher.

property allow_fetch_all#

Flag indicating whether the fetch_all() operation is permitted.

copy()[source]#
fetch(ids_to_fetch, placeholders=(), *, required=(), task_id=None, enable_uuid_heuristics=False)[source]#

Return generated translations for all IDs and placeholders.

fetch_all(placeholders=(), *, required=(), sources=None, task_id=None, enable_uuid_heuristics=False)[source]#

Fetch as much data as possible.

Parameters:
  • placeholders – All desired placeholders in preferred order.

  • required – Placeholders that must be included in the response.

  • sources – A subset of sources to fetch. Unknown sources are ignored. Set to None to fetch all sources.

  • task_id – Used for logging.

  • enable_uuid_heuristics – Improves matching when UUID-like IDs are in use.

Returns:

A mapping {source: PlaceholderTranslations} of translation elements.

See also

🔑 This is a key event method. See Key Event Records for details.

Raises:
initialize_sources(task_id=None, *, force=False)[source]#

Perform source discovery.

Parameters:
  • task_id – Used for logging.

  • force – If True, perform full discovery even if sources are already known.

See also

🔑 This is a key event method. See Key Event Records for details.

Notes

This function is called implicitly before every translation task. Result should be cached.

property online#

Return connectivity status. If False, no new translations may be fetched.

property placeholders#

Placeholders for all known Source names, such as id or name.

These are the (possibly unmapped) placeholders that may be used for translation.

Returns:

A dict {source: [placeholders, ...]}.

class TestMapper(score_function='disabled', score_function_kwargs=None, filter_functions=(), min_score=0.9, overrides=None, on_unmapped='ignore', on_unknown_user_override='raise', cardinality=Cardinality.ManyToOne)[source]#

Bases: Mapper[ValueType, ValueType, ContextType]

Dummy Mapper implementation.

apply(values, candidates, context=None, override_function=None, *, task_id=None, **kwargs)[source]#

Map values to themselves, unless override_function is given.