sloth.raw.tests: Standard tests classes

class sloth.raw.complex.tests.TestCallable(_callable)

This test tests a callable object; any object that callable(obj) is True.

Parameters

_callable (callable) – The callable object to speedtest

run()

Speedtest the callable and return how long it took to execute.

Returns

How long the callable took to run

Return type

float

class sloth.raw.complex.tests.TestCallableWithArgs(_callable, *args, **kwargs)

This test is similar to TestCallable, but the callable has args when using this test.

Parameters
  • _callable (callable) – The callable object to speedtest

  • args – Arguments to pass to the callable object.

  • kwargs – Keyword arguments to pass to the callable object.

>>> from sloth.raw.complex.tests import TestCallableWithArgs
>>> def my_func(a, b, c, d='foo', e='bar'):
...     print(a, b, c, d, e)
>>> my_test = TestCallableWithArgs(my_func, 1, 2, 3, 'bar', 'foo')
>>> my_test.run()
1 2 3 bar foo
0.0
>>>
run(*args, **kwargs)

Speedtest the callable and return how long it took to execute. args and kwargs can be used to override those passed in at creation.

Returns

How long the callable took to run

Return type

float

class sloth.raw.complex.tests.TestEval(statement, gbls=None, lcls=None)

Speedtest eval(statement, gbls, lcls). See the eval docs docs for more info.

Parameters

statement (str or bytes or code) – The code statement to evaluate.

run(gbls=None, lcls=None)

Evaluate the statement, and return how long it took to execute. See the eval docs docs for more info.

Returns

How long the evaluation took to run

Return type

float

class sloth.raw.complex.tests.TestExec(statement, gbls=None, lcls=None)

Speedtest exec(statement, gbls, lcls). See the exec docs for more info.

Parameters

statement (str or bytes or code) – The code statement to execute.

run(gbls=None, lcls=None)

Execute the statement, and return how long it took to execute. See the exec docs for more info.

Returns

How long the evaluation took to run

Return type

float