hbutils.testing.generator

BaseGenerator

class hbutils.testing.generator.BaseGenerator(values, names: Optional[List[str]] = None)[source]

Base generator class.

__init__(values, names: Optional[List[str]] = None)[source]

Constructor of the hbutils.testing.BaseGenerator class.

Parameters:
  • values – Selection values, such as {'a': [2, 3], 'b': ['b', 'c']}.

  • names – Names of the given generator, default is None which means use the sorted key set of the values.

cases() → Iterator[Mapping[str, object]][source]

Virtual method for cases, will be implemented in child classes.

property names

Name of the given generator.

tuple_cases() → Iterator[Tuple[object, ]][source]

Tuple-formatted cases, can be used to iterate.

property values

Selection values.

MatrixGenerator

class hbutils.testing.generator.MatrixGenerator(values: Mapping[str, object], names: Optional[List[str]] = None, includes: Optional[List[Mapping[str, object]]] = None, excludes: Optional[List[Mapping[str, object]]] = None)[source]

Full matrix model, all the cases in this matrix will be iterated.

__init__(values: Mapping[str, object], names: Optional[List[str]] = None, includes: Optional[List[Mapping[str, object]]] = None, excludes: Optional[List[Mapping[str, object]]] = None)[source]

Constructor of the hbutils.testing.MatrixGenerator class. It is similar to GitHub Action’s matrix.

Parameters:
  • values – Matrix values, such as {'a': [2, 3], 'b': ['b', 'c']}.

  • names – Names of the given generator, default is None which means use the sorted key set of the values.

  • includes – Include items, such as [{'a': 4, 'b': 'b'}], default is None which means no extra inclusions.

  • excludes – Exclude Items, such as [{'a': 2, 'b': 'c'}], default is None which means no extra exclusions.

cases() → Iterator[Mapping[str, object]][source]

Get the cases in this matrix.

Examples::
>>> from hbutils.testing import MatrixGenerator
>>> for p in MatrixGenerator(
...         {'a': [1, 2, 3], 'b': ['a', 'b'], 'r': [3, 4, 5]},
...         includes=[{'a': 4, 'r': 7}],
...         excludes=[{'a': 1, 'r': 3}, {'a': 3, 'b': 'b'}, {'a': 4, 'b': 'a', 'r': 7}]
... ).cases():
>>>     print(p)
{'a': 1, 'b': 'a', 'r': 4}
{'a': 1, 'b': 'a', 'r': 5}
{'a': 1, 'b': 'b', 'r': 4}
{'a': 1, 'b': 'b', 'r': 5}
{'a': 2, 'b': 'a', 'r': 3}
{'a': 2, 'b': 'a', 'r': 4}
{'a': 2, 'b': 'a', 'r': 5}
{'a': 2, 'b': 'b', 'r': 3}
{'a': 2, 'b': 'b', 'r': 4}
{'a': 2, 'b': 'b', 'r': 5}
{'a': 3, 'b': 'a', 'r': 3}
{'a': 3, 'b': 'a', 'r': 4}
{'a': 3, 'b': 'a', 'r': 5}
{'a': 4, 'b': 'b', 'r': 7}
property excludes

Exclude items.

property includes

Include items.

property names

Name of the given generator.

tuple_cases() → Iterator[Tuple[object, ]]

Tuple-formatted cases, can be used to iterate.

property values

Selection values.

AETGGenerator

class hbutils.testing.generator.AETGGenerator(values, names: Optional[List[str]] = None, pairs: Optional[List[Tuple[str, ]]] = None, rnd: Optional[Union[random.Random, int]] = None)[source]

Full AETG model, test cases will be generated to make sure the required pairs will be all tested.

__init__(values, names: Optional[List[str]] = None, pairs: Optional[List[Tuple[str, ]]] = None, rnd: Optional[Union[random.Random, int]] = None)[source]

Constructor of the hbutils.testing.AETGGenerator class.

Parameters:
  • values – Selection values, such as {'a': [2, 3], 'b': ['b', 'c']}.

  • names – Names of the given generator, default is None which means use the sorted key set of the values.

  • pairs – Pairs required to be all tested, default is None which means all the binary pairs will be included.

  • rnd – Random object or int-formatted random seed, default is None which means the default random object will be used.

cases() → Iterator[Mapping[str, object]][source]

Get the cases in this AETG model.

Examples::
>>> from hbutils.testing import AETGGenerator
>>> gene = AETGGenerator({'a': (1, 2), 'b': (3, 4), 'c': (5, 6), 'd': (7, 8), 'e': (9, 10)})
>>> for p in gene.cases():
...     print(p)
{'a': 1, 'b': 3, 'c': 6, 'd': 8, 'e': 10}
{'a': 2, 'b': 4, 'c': 5, 'd': 7, 'e': 9}
{'a': 2, 'b': 3, 'c': 6, 'd': 7, 'e': 9}
{'a': 2, 'b': 4, 'c': 6, 'd': 8, 'e': 10}
{'a': 1, 'b': 3, 'c': 5, 'd': 7, 'e': 10}
{'a': 1, 'b': 4, 'c': 5, 'd': 8, 'e': 9}
>>> gene = AETGGenerator(
...     {'a': (1, 2), 'b': (3, 4), 'c': (5, 6), 'd': (7, 8), 'e': (9, 10)},
...     pairs=[('a', 'c'), ('b', 'd'), ('e',)]
... )
>>> for p in gene.cases():
...     print(p)
{'a': 2, 'b': 3, 'c': 6, 'd': 8, 'e': 9}
{'a': 1, 'b': 4, 'c': 5, 'd': 7, 'e': 10}
{'a': 2, 'b': 4, 'c': 5, 'd': 8, 'e': 9}
{'a': 1, 'b': 3, 'c': 6, 'd': 7, 'e': 10}
property names

Name of the given generator.

property pairs

Pairs required to be all tested.

tuple_cases() → Iterator[Tuple[object, ]]

Tuple-formatted cases, can be used to iterate.

property values

Selection values.