rics.translation.testing#

Test implementations.

Classes

TestFetcher([sources])

Dummy Fetcher implementation.

TestMapper([score_function, ...])

Dummy Mapper implementation.

class TestMapper(score_function: Union[str, Callable[[ValueType, Iterable[CandidateType], Optional[ContextType]], Iterable[float]]] = 'equality', score_function_kwargs: Optional[Dict[str, Any]] = None, filter_functions: Iterable[Tuple[Union[str, Callable[[ValueType, Iterable[CandidateType], Optional[ContextType]], Set[CandidateType]]], Dict[str, Any]]] = (), min_score: float = 1.0, overrides: Optional[Union[InheritedKeysDict, Dict[ValueType, CandidateType]]] = None, unmapped_values_action: Union[Literal['ignore', 'warn', 'raise', 'IGNORE', 'WARN', 'RAISE'], ActionLevel] = ActionLevel.IGNORE, unknown_user_override_action: Union[Literal['ignore', 'warn', 'raise', 'IGNORE', 'WARN', 'RAISE'], ActionLevel] = ActionLevel.RAISE, cardinality: Optional[Union[str, Cardinality]] = Cardinality.ManyToOne, enable_verbose_logging: bool = False)[source]#

Bases: Mapper[ValueType, ValueType, ContextType]

Dummy Mapper implementation.

apply(values: Iterable[ValueType], candidates: Iterable[ValueType], context: Optional[ContextType] = None, override_function: Optional[Callable[[ValueType, Set[CandidateType], Optional[ContextType]], Optional[CandidateType]]] = None, **kwargs: Any) DirectionalMapping[ValueType, ValueType][source]#

Map values to themselves, unless override_function is given.

class TestFetcher(sources: Optional[Collection[SourceType]] = 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: bool#

Flag indicating whether the fetch_all() operation is permitted.

property online: bool#

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

property sources: List[SourceType]#

Source names known to the Fetcher, such as cities or languages.

property placeholders: Dict[SourceType, List[str]]#

Placeholders for sources managed by the Fetcher.

Returns

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

Notes

Placeholders (and sources) are returned as they appear as they are known to the fetcher (without mapping).

fetch(ids_to_fetch: Iterable[IdsToFetch[SourceType, IdType]], placeholders: Iterable[str] = (), required: Iterable[str] = ()) Dict[SourceType, PlaceholderTranslations][source]#

Return generated translations for all IDs and placeholders.

fetch_all(placeholders: Iterable[str] = (), required: Iterable[str] = ()) Dict[SourceType, PlaceholderTranslations][source]#

Fetch as much data as possible.

Parameters
  • placeholders – All desired placeholders in preferred order.

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

Returns

A mapping {source: PlaceholderTranslations} for translation.

Raises