Internal functions¶
Automatic testing of a single function.
-
paranoid.testfunctions.max_run_time(t)[source]¶ Limit the runtime of a code segment.
If a block of code runs for more than t seconds, kill it. This only works on unix platforms; on Windows, there will be no time limit.
Use within a with statement, e.g.
- with max_run_time(5):
- potentially_long_function()
-
paranoid.testfunctions.test_function(func)[source]¶ Perform a unit test of a single function.
Create a series of test cases by finding the type of each of the function arguments, and creating all possible combinations of test cases for each type using the type’s generate() function. Then, test the function with each input. This is roughly equivalent to just running the function with each input, because the exceptions should be caught at runtime.
Assuming runtime checking is enabled (as it should be), running this on a function only tests it for inputs it is likely to encounter in the future.
Returns the number of tests performed.
-
paranoid.utils.get_fun_prop(f, k)[source]¶ Get the value of property k from function f.
We define properties as annotations added to a function throughout the process of defining a function for verification, e.g. the argument types. If f does not have a property named k, this throws an error. If f has the property named k, it returns the value of it.
Users should never access this function directly.
-
paranoid.utils.get_func_kwargs_name(f)[source]¶ Returns the name of the function f’s keyword argument parameter if it exists, otherwise None
-
paranoid.utils.get_func_posargs_name(f)[source]¶ Returns the name of the function f’s keyword argument parameter if it exists, otherwise None
-
paranoid.utils.has_fun_prop(f, k)[source]¶ Test whether function f has property k.
We define properties as annotations added to a function throughout the process of defining a function for verification, e.g. the argument types. If f is an unannotated function, this returns False. If f has the property named k, it returns True. Otherwise, it returns False.
Users should never access this function directly.
-
paranoid.utils.set_fun_prop(f, k, v)[source]¶ Set the value of property k to be v in function f.
We define properties as annotations added to a function throughout the process of defining a function for verification, e.g. the argument types. This sets function f’s property named k to be value v.
Users should never access this function directly.
-
exception
paranoid.exceptions.ArgumentTypeError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA function was passed an argument of the wrong type.
-
exception
paranoid.exceptions.EntryConditionsError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA function’s entry conditions were not satisfied.
-
exception
paranoid.exceptions.ExitConditionsError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA function’s exit conditions were not satisfied.
-
exception
paranoid.exceptions.InternalError[source]¶ Bases:
paranoid.exceptions.VerifyErrorThis should not happen.
-
exception
paranoid.exceptions.InvalidTypeError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA type was not implemented correctly.
-
exception
paranoid.exceptions.NoGeneratorError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA type does not have a valid generate() function.
-
exception
paranoid.exceptions.ObjectModifiedError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA static object was modified.
-
exception
paranoid.exceptions.ReturnTypeError[source]¶ Bases:
paranoid.exceptions.VerifyErrorA function returned a value of the wrong type.
-
exception
paranoid.exceptions.TestCaseTimeoutError[source]¶ Bases:
paranoid.exceptions.VerifyErrorThrown to allow function timeouts.