Assertion module
The assertion module provides a suite of tools for performing assertions on JSON-like objects, ensuring that their structure and content conform to expected criteria. This module is particularly useful in testing scenarios where you need to validate the presence or absence of specific keys, as well as the correctness of values within nested JSON structures. At the heart of this module is the Assert class, which offers a range of assertion methods designed to work with instances of Object. These assertions enable you to verify that certain keys are either present or absent within a JSON object and that the values associated with those keys are as expected.
- class jsify.assertion.Assert[source]
Bases:
object
A class providing assertions to verify the contents of JSON-like objects.
- class IsIn[source]
Bases:
Assertion
Assertion to check that a key is in the JSON object.
- assertion(json_object, key, path)[source]
Assert that a key is in the JSON object.
- Parameters:
json_object (Object) – The JSON object to perform the assertion on.
key (str) – The key to check in the JSON object.
path (str) – The current path in the JSON object.
- Raises:
AssertionError – If the key is not found in the JSON object.
- class NotIn[source]
Bases:
Assertion
Assertion to check that a key is not in the JSON object.
- assertion(json_object, key, path)[source]
Assert that a key is not in the JSON object.
- Parameters:
json_object (Object) – The JSON object to perform the assertion on.
key (str) – The key to check in the JSON object.
path (str) – The current path in the JSON object.
- Raises:
AssertionError – If the key is found in the JSON object.
- static values_equal(json_object, values, path='')[source]
Assert that the values in a JSON object match the expected values.
- Parameters:
json_object (Object) – The JSON object to check.
values (dict or list) – The expected values to match against the JSON object.
path (str) – The current path in the JSON object (used for error messages).
- Raises:
AssertionError – If the values do not match the expected values.