Variable testing procedures.
Utility procedures to evaluate variables to determine if they pass simple tests. These tests are typically to ensure that a variable is of a particular type and a particular format. These methods raise informative exceptions if they fail.
AUTHORS:
EXAMPLES:
Test that a variable is greater than 0.:
x = 2
greater_than(x, 0)
This does not raise an exception. This shows that x may be an int or x may be a float. Try a negative value.:
>>> x = -2
>>> greater_than(x, 0)
The variable tested needs to be > 0.
The variable tested is of <type 'int'> and
has a wrong value of -2.
In this case, the error reported is fairly informative, but note that it can be made more informative by telling us the name of the parameter. The next example tries a different format altogether and passes in the name of the variable so that the user understands which variable is in error.:
>>> some_var='abc'
>>> greater_than(some_var, 0, 'some_var')
some_var needs to be > 0.
some_var is of <type 'str'> and has a wrong value of abc.
Tests to see that test_var is a float and is greater than a number.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |
Tests to see that test_var is a float and is greater than zero.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |
Tests to see that test_var is a float and is greater than or equal to min and less than or equal to max.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |
Tests to see that test_var is a 1-dimensional list or numpy array.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |
Tests to see that test_var is an explicit boolean (True or False) value.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |
Tests to see that test_var is an integer.
Parameters: |
|
---|---|
Throws : | exception if the test_var does not meet the requirements and describes the problem. |