Dict assertions¶
Assertions for dict values: keys, values, and entries.
Dict assertions mixin.
contains_key ¶
Asserts the val is a dict and contains the given key or keys.
Alias for contains().
Checks if the dict contains the given key or keys using in operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
object
|
the key or keys expected to be contained |
()
|
Examples:
Usage:
assert_that({'a': 1, 'b': 2}).contains_key('a')
assert_that({'a': 1, 'b': 2}).contains_key('a', 'b')
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not contain the key or keys |
Source code in assertpy2/dict.py
does_not_contain_key ¶
Asserts the val is a dict and does not contain the given key or keys.
Alias for does_not_contain().
Checks if the dict excludes the given key or keys using in operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
object
|
the key or keys expected to be excluded |
()
|
Examples:
Usage:
assert_that({'a': 1, 'b': 2}).does_not_contain_key('x')
assert_that({'a': 1, 'b': 2}).does_not_contain_key('x', 'y')
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does contain the key or keys |
Source code in assertpy2/dict.py
contains_value ¶
Asserts that val is a dict and contains the given value or values.
Checks if the dict contains the given value or values in any key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*values
|
object
|
the value or values expected to be contained |
()
|
Examples:
Usage:
assert_that({'a': 1, 'b': 2}).contains_value(1)
assert_that({'a': 1, 'b': 2}).contains_value(1, 2)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not contain the value or values |
Source code in assertpy2/dict.py
does_not_contain_value ¶
Asserts that val is a dict and does not contain the given value or values.
Checks if the dict excludes the given value or values across all keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*values
|
object
|
the value or values expected to be excluded |
()
|
Examples:
Usage:
assert_that({'a': 1, 'b': 2}).does_not_contain_value(3)
assert_that({'a': 1, 'b': 2}).does_not_contain_value(3, 4)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does contain the value or values |
Source code in assertpy2/dict.py
contains_entry ¶
Asserts that val is a dict and contains the given entry or entries.
Checks if the dict contains the given key-value pair or pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
the entry or entries expected to be contained (as |
()
|
**kwargs
|
object
|
the entry or entries expected to be contained (as |
{}
|
Examples:
Usage:
# using args
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry({'a': 1})
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry({'a': 1}, {'b': 2})
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry({'a': 1}, {'b': 2}, {'c': 3})
# using kwargs
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry(a=1)
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry(a=1, b=2)
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry(a=1, b=2, c=3)
# or args and kwargs
assert_that({'a': 1, 'b': 2, 'c': 3}).contains_entry({'c': 3}, a=1, b=2)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not contain the entry or entries |
Source code in assertpy2/dict.py
does_not_contain_entry ¶
Asserts that val is a dict and does not contain the given entry or entries.
Checks if the dict excludes the given key-value pair or pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
the entry or entries expected to be excluded (as |
()
|
**kwargs
|
object
|
the entry or entries expected to be excluded (as |
{}
|
Examples:
Usage:
# using args
assert_that({'a': 1, 'b': 2, 'c': 3}).does_not_contain_entry({'a': 2})
assert_that({'a': 1, 'b': 2, 'c': 3}).does_not_contain_entry({'a': 2}, {'x': 4})
# using kwargs
assert_that({'a': 1, 'b': 2, 'c': 3}).does_not_contain_entry(a=2)
assert_that({'a': 1, 'b': 2, 'c': 3}).does_not_contain_entry(a=2, x=4)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does contain the entry or entries |