potc.fixture.addons¶
Addons¶
-
class
potc.fixture.addons.Addons(rule=None)[source]¶ - Overview:
Addon object used in rules.
-
__init__(rule=None)[source]¶ - Overview:
Constructor of
Addons.- Arguments:
rule: Translation rule, default is
Nonewhich means no translation rule, auto translation will also be disabled whenNoneis 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 statementimport jsonwill 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 isNonewhich means do not alias.
- Returns:
proxy (
AddonProxy): Expression proxy object.
-
raw(val, *, func=None) → potc.fixture.addons.AddonProxy[source]¶ - Overview:
Generate raw proxy.
- Arguments:
val: Raw object.
func: Translation function, default is
Nonewhich means just turn it to string by builtin functionstr.
- Returns:
proxy (
AddonProxy): Raw proxy object.
-
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
objmethod, this method will not do automatic import, it will just generate the string expression with the rule translator.- Arguments:
obj: Value object.
- Returns:
proxy (
AddonProxy): Expression proxy object.
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]orbase[1, 2, 3].- Arguments:
item (
str): Item value, can be simple value, slice or tuple.
- Returns:
proxy: New generated proxy.