potc.fixture.addons

Addons

class potc.fixture.addons.Addons(rule=None)[source]
Overview:

Addon object used in rules.

__getstate__()[source]
Overview:

Get state value of this object.

Returns:
  • state: State value.

__init__(rule=None)[source]
Overview:

Constructor of Addons.

Arguments:
  • rule: Translation rule, default is None which means no translation rule, auto translation will also be disabled when None is used.

__setstate__(state)[source]
Overview:

Set state value of this object.

Arguments:
  • state: State value.

property import_items
Overview:

Import statements.

Returns:
  • statements (Tuple[ImportStatement, ...]): Tuple of import statements.

obj(obj, alias: Optional[str] = None)potc.fixture.addons.AddonProxy[source]
Overview:

Generate an object proxy. Object proxy means a object which need to be automatically imported, such as json, an import statement import json will be generated. If the object cannot be imported, it will raise exception.

Arguments:
  • obj: Target object.

  • alias (Optional[str]): Alias name of the imported object, default is None which means do not alias.

Returns:
raw(val, *, func=None)potc.fixture.addons.AddonProxy[source]
Overview:

Generate raw proxy.

Arguments:
  • val: Raw object.

  • func: Translation function, default is None which means just turn it to string by builtin function str.

Returns:
rule(v) → str[source]
Overview:

Express the value with the rule translator.

Arguments:
  • v: Value object.

Returns:
  • str (str): String formatted expression.

transaction()[source]
Overview:

Open up an atomic transaction context. If exception is thrown in this context, all the update in this addon object will be undone.

Example:
>>> with addon.transaction():
>>>     addon.rule(1)
>>>     addon.val([1, 2])
>>>     addon.obj(json)
>>>     raise RuntimeError  # the changes above will be undone
unprocessable()[source]
Overview:

Raise an exception UnprocessableError. Announce that the current rule cannot express this value.

val(obj)potc.fixture.addons.AddonProxy[source]
Overview:

Generate a value proxy. Differs from obj method, this method will not do automatic import, it will just generate the string expression with the rule translator.

Arguments:
  • obj: Value object.

Returns:

AddonProxy

class potc.fixture.addons.AddonProxy(base, rule)[source]
Overview:

Proxy of addon expression.

__call__(*args, **kwargs)[source]
Overview:

Generate item call expression, like base(1, 2, x=1, y=2).

Arguments:
  • args: Positional arguments.

  • kwargs: Key-word arguments.

Returns:
  • proxy: New generated proxy.

__getattr__(item: str)[source]
Overview:

Generate attribute-getting expression, like base.xxx.

Arguments:
  • item (str): Attribute name.

Returns:
  • proxy: New generated proxy.

__getitem__(item)[source]
Overview:

Generate item-getting expression, like base[233], base[::-1] or base[1, 2, 3].

Arguments:
  • item (str): Item value, can be simple value, slice or tuple.

Returns:
  • proxy: New generated proxy.

__init__(base, rule)[source]
Overview:

Constructor of AddonProxy

Arguments:
  • base: Base unit of the proxy.

  • rule: Translation rule.

__str__() → str[source]
Overview:

String format of expression.

Returns:
  • return (str): String formatted expression.