arjuna.tpi.engine.asserter module¶
-
class
arjuna.tpi.engine.asserter.
Asserter
¶ Bases:
object
Arjuna’s asserter class.
It can be used directly. It is already included as an attribute for request fixture in test functions and all Guis and Gui Templates.
-
assert_approx_equal
(obj1, obj2, msg, places=None, delta=None)¶ Assert round(obj1-obj2, places) == 0 if places is supplied
Assert round(obj1-obj2, places) == delta if delta is supplied
Wrapper on unittest’s assertAlmostEqual
Parameters: - obj1 – Object of any type which supports == operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
- places – Number of decimal places used for rounding
- delta – The difference between objects after rounding (diff <= delta for passing assertion)
Note
You can specify either places or delta not both.
Note
This method rounds the values to the given number of decimal places (i.e. like the Python’s round() function) and not significant digits.
-
assert_approx_not_equal
(obj1, obj2, msg, places=7, delta=None)¶ Assert round(obj1-obj2, places) != 0 if places is supplied
Assert round(obj1-obj2, places) > delta if delta is supplied
Wrapper on unittest’s assertNotAlmostEqual
Parameters: - obj1 – Object of any type which supports == operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
- places – Number of decimal places used for rounding
- delta – The allowed difference between objects after rounding (diff >= delta for passing assertion)
Note
You can specify either places or delta not both.
Note
This method rounds the values to the given number of decimal places (i.e. like the Python’s round() function) and not significant digits.
-
assert_equal
(obj1, obj2, msg)¶ Assert obj1 == obj2
Wrapper on unittest’s assertEqual
Parameters: - obj1 – Object of any type which supports == operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_exceptions
(exceptions, callable=None, *cargs, regex=None, **ckwargs)¶ Asserts that one of the provided exceptions is raised when the provided callable (or ) is called with provided arguments.
Parameters: - exceptions – One or more Exception classes provided as tuple. A single Exception can be directly provided.
- callable – The callable to be called.
- cargs – Positional arguments to be passed to callable
Keyword Arguments: - regex – Regular expression to match the string representation of the Exception. Can be a string or a regular expression object that can be used with Python’s re.search() call.
- ckwargs – Keyword arguments to be passed to callable
Note
You can use this method to create a context manager by not providing the callable.
This means you can write the code to be asserted for directly inline:
with asserter.assert_exceptions(SomeException): do_something()
If you want to futher put assertions on the the actual exception raised, you can use context manager’s exception attribute:
with asserter.assert_exceptions(SomeException) as cm: do_something() asserter.assert_equal(cm.exception.error_code, 3)
-
assert_false
(obj, msg)¶ Assert obj is False.
Wrapper on unittest’s assertFalse
Parameters: - obj – Object of any type
- msg – A context string explaining why this assertion was done.
-
assert_greater
(obj1, obj2, msg)¶ Assert obj1 > obj2
Wrapper on unittest’s assertLess
Parameters: - obj1 – Object of any type which supports > operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_lesser
(obj1, obj2, msg)¶ Assert obj1 < obj2
Wrapper on unittest’s assertLess
Parameters: - obj1 – Object of any type which supports < operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_max
(obj, max_value, msg)¶ Asserts a maximum value for an object i.e. obj <= max_value
Wrapper on unittest’s assertLessEqual
Parameters: - obj – Object of any type which supports <= operator for min_value
- max_value – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_min
(obj, min_value, msg)¶ Asserts a minimum value for an object i.e. obj >= min_value
Wrapper on unittest’s assertGreaterEqual
Parameters: - obj – Object of any type which supports >= operator for min_value
- min_value – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_not_equal
(obj1, obj2, msg)¶ Assert obj1 != obj2
Wrapper on unittest’s assertNotEqual
Parameters: - obj1 – Object of any type which supports != operator for obj2 type
- obj2 – Object meeting the above constraint
- msg – A context string explaining why this assertion was done.
-
assert_true
(obj, msg)¶ Assert obj is True.
Wrapper on unittest’s assertTrue
Parameters: - obj – Object of any type
- msg – A context string explaining why this assertion was done.
-
fail
(msg)¶ Raises AssertionError with the provided message.
Parameters: msg – A context string explaining the failure.
-
-
class
arjuna.tpi.engine.asserter.
AsserterMixIn
¶ Bases:
object
Base class to add asserter property to any class which inherits from it.
-
asserter
¶ Arjuna’s Asserter object for executing assertions.
-
-
class
arjuna.tpi.engine.asserter.
IterableAsserterMixin
¶ Bases:
object
Base class for adding assertions to iterables.
Note
Use it in combination with AsserterMixIn. The child class should have _container as its attribute or property.
-
assert_empty
(*, msg)¶ Assert that there should not be any object in this iterable.
Keyword Arguments: msg – Purpose of this assertion.
-
assert_max_size
(size, *, msg)¶ Assert that the number of objects in this iterable <= provided size.
Parameters: size – Expected maximum number of objects. Keyword Arguments: msg – Purpose of this assertion.
-
assert_min_size
(size, *, msg)¶ Assert that the number of objects in this iterable >= provided size.
Parameters: size – Expected minimum number of objects. Keyword Arguments: msg – Purpose of this assertion.
-
assert_not_empty
(*, msg)¶ Assert that there should be atleast one object in this iterable.
Keyword Arguments: msg – Purpose of this assertion.
-
assert_size
(size, *, msg)¶ Assert that the number of objects in this iterable should match provided size.
Parameters: size – Expected number of objects. Keyword Arguments: msg – Purpose of this assertion.
-
assert_size_range
(min_size, max_size, *, msg)¶ Assert that the number of objects in this iterable should be in the provided size range.
Parameters: - min_size – Expected minimum number of objects.
- max_size – Expected maximum number of objects.
Keyword Arguments: msg – Purpose of this assertion.
-
is_empty
()¶ Returns True if this iterable has no objects.
-