teachpyx.ext_test_case

class teachpyx.ext_test_case.ExtTestCase(methodName='runTest')[source][source]
assertAlmostEqual(expected: ndarray, value: ndarray, atol: float = 0, rtol: float = 0)[source][source]

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).

If the two objects compare equal then they will automatically compare almost equal.

capture(fct: Callable)[source][source]

Runs a function and capture standard output and error.

Paramètres:

fct – function to run

Renvoie:

result of fct, output, error

classmethod tearDownClass()[source][source]

Hook method for deconstructing the class fixture after running all tests in the class.

teachpyx.ext_test_case.ignore_warnings(warns: List[Warning]) Callable[source][source]

Catches warnings.

Paramètres:

warns – warnings to ignore

teachpyx.ext_test_case.measure_time(stmt: str | Callable, context: Dict[str, Any] | None = None, repeat: int = 10, number: int = 50, warmup: int = 1, div_by_number: bool = True, max_time: float | None = None) Dict[str, Any][source][source]

Measures a statement and returns the results as a dictionary.

Paramètres:
  • stmt – string or callable

  • context – variable to know in a dictionary

  • repeat – average over repeat experiment

  • number – number of executions in one row

  • warmup – number of iteration to do before starting the real measurement

  • div_by_number – divide by the number of executions

  • max_time – execute the statement until the total goes beyond this time (approximatively), repeat is ignored, div_by_number must be set to True

Renvoie:

dictionary

<<<

from teachpyx.ext_test_case import measure_time
from math import cos

res = measure_time(lambda: cos(0.5))
print(res)

>>>

    {'average': np.float64(8.056404476519675e-08), 'deviation': np.float64(7.650988849481507e-09), 'min_exec': np.float64(7.08800507709384e-08), 'max_exec': np.float64(8.846007403917611e-08), 'repeat': 10, 'number': 50, 'ttime': np.float64(8.056404476519674e-07), 'context_size': 64, 'warmup_time': 4.411995178088546e-06}

See Timer.repeat for a better understanding of parameter repeat and number. The function returns a duration corresponding to number times the execution of the main statement.

Modifié dans la version 0.4: Parameter max_time was added.

teachpyx.ext_test_case.unit_test_going()[source][source]

Enables a flag telling the script is running while testing it. Avois unit tests to be very long.