potc.fixture.chain

build_chain

potc.fixture.chain.build_chain(c: Union[List, Tuple, Callable], id_gen: Optional[Callable] = None) → List[Callable][source]
Overview:

Build chain of the rules. Bases on orders which depends by tuples and lists.

Arguments:
  • c (Union[List, Tuple, Callable]): Rule structure object, can be a list, tuple or rule, or the nested structure of them.

  • id_gen (Optional[Callable]): Id generator of the rules, default is None which means id function.

Returns:
  • chain (List[Callable]): List of the rules in order.

Example:
>>> build_chain(r1)                        # [r1]
>>> build_chain([(r1, r2), (r3, r2)])      # [r1, r3, r2] or [r3, r1, r2]
>>> build_chain((r1, [r2, (r3, r4)], r5))  # [r1, r2, r3, r4, r5] or [r1, r3, r2, r4, r5] or [r1, r3, r4, r2, r5]

Note

In build_chain function, there are 2 main structure which represents different structures:

  • list, which means the elements in it are paralleled with each other.

  • tuple, which means the element in it should be in order one by one.

Here are some examples about this problem.

In the simplest case, here is the difference between (r1, r2) and [r1, r2]. In the tuple’s case, it means t1 must be processed earlier than t2, while in list’s case, it just means they are put together here without orders’ limit.

../../_images/chain_simple.gv.svg

In another case of (r1, [(r2, r3), (r4, r5)], r6), its order graph should be like below.

../../_images/chain_another.gv.svg

Actually, r1 should be ahead of [(r2, r3), (r4, r5)], r2 should be ahead of r3, r4 should be ahead of r5, [(r2, r3), (r4, r5)] should be ahead of r6. So one of the final order should be [r1, r2, r4, r5, r3, r6] (the valid orders are not unique in this case).

rules_combine

potc.fixture.chain.rules_combine(*rules)[source]
Overview:

Combined the ordered rule list to be a executable rule-like function (but not a rule object actually).

Arguments:
  • rules: List of the rules (may be the result of function build_chain.

Returns:
  • func: Combined rule function.