assert_dicts_equal and assert_dicts_not_equal interfaces¶
This page explains the assert_dicts_equal
and assert_dicts_not_equal
function interfaces.
What interfaces are these?¶
The assert_dicts_equal
function interface asserts specified two dictionaries (dict
or Dictionary
type value) are equal. Conversely, the assert_dicts_not_equal
function interface asserts specified two dictionaries are not equal.
See also¶
Basic usage¶
Both of the assert_dicts_equal
and assert_dicts_not_equal
interfaces require the left
and right
arguments. The msg
argument is optional.
You can specify a Python built-in dict
and Dictionary
values to these arguments.
The following example (assert_dicts_equal
and values are equal) passes:
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
dict_val: ap.Dictionary = ap.Dictionary({"a": 10, "b": 20})
ap.assert_dicts_equal(
left={"a": 10, "b": 20}, right=dict_val, msg="Values are not equal!"
)
ap.save_overall_html(dest_dir_path="assert_dicts_equal_basic_usage_1/")
[assert_dicts_equal]
Left value: {a: 10, b: 20} right value: dct_1
The following example (assert_dicts_equal
and values are not equal) fails:
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
dict_val: ap.Dictionary = ap.Dictionary({"a": 10, "b": 20})
ap.assert_dicts_equal(left={"a": 30}, right=dict_val, msg="Values are not equal!")
ap.save_overall_html(dest_dir_path="assert_dicts_equal_basic_usage_2/")
[assert_dicts_equal]
Left value: {a: 30} right value: dct_1
...
Assertion failed: Values are not equal!
The following example (assert_dicts_not_equal
and values are not equal) passes:
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
dict_val: ap.Dictionary = ap.Dictionary({"a": 10, "b": 20})
ap.assert_dicts_not_equal(left={"a": 30}, right=dict_val, msg="Values are equal!")
ap.save_overall_html(dest_dir_path="assert_dicts_not_equal_basic_usage_1/")
[assert_dicts_not_equal]
Left value: {a: 30} right value: dct_1
Notes for the assert_equal and assert_not_equal interfaces¶
If a Dictionary
value is specified to the assert_equal
or assert_not_equal
interface’s argument value, then the assert_dicts_equal
or assert_dicts_not_equal
interfaces will be called instead of the assert_equal
or assert_not_equal
interfaces automatically.
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
dict_val: ap.Dictionary = ap.Dictionary({"a": 30})
ap.assert_equal(left={"a": 30}, right=dict_val, msg="Values are not equal!")
ap.save_overall_html(dest_dir_path="assert_dicts_equal_notes_for_assert_equal/")
[assert_dicts_equal]
Left value: {a: 30} right value: dct_1
assert_dicts_equal API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] assert_dicts_equal(left: Any, right: Any, *, msg: str = '', outer_frames_index_adjustment: int = 0) -> None
[Interface summary]
JavaScript assertion interface for the Dictionary values equal condition.
[Parameters]
left
: *Left-side value to compare.
right
: *Right-side value to compare.
msg
: str, optionalMessage to display when assertion failed.
outer_frames_index_adjustment
: int, optionalThe trace’s outer frames index adjustment setting. This function uses this argument to adjust the caller’s information. Also, this function only uses this argument in internal logic.
[Notes]
This interface is used instead of assert_equal for Dictionary class comparison (JavaScript can not compare dictionary (Object) directly, like a Python, for example, {"a": 10} === {"a": 10}
becomes false).
[Examples]
>>> import apysc as ap
>>> dict_1: ap.Dictionary = ap.Dictionary({"a": 10})
>>> dict_2: ap.Dictionary = ap.Dictionary({"a": 10})
>>> ap.assert_dicts_equal(dict_1, dict_2)
assert_dicts_not_equal API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] assert_dicts_not_equal(left: Any, right: Any, *, msg: str = '', outer_frames_index_adjustment: int = 0) -> None
[Interface summary]
JavaScript assertion interface for the Dictionary values not equal condition.
[Parameters]
left
: *Left-side value to compare.
right
: *Right-side value to compare.
msg
: str, optionalMessage to display when assertion failed.
outer_frames_index_adjustment
: int, optionalThe trace’s outer frames index adjustment setting. This function uses this argument to adjust the caller’s information. Also, this function only uses this argument in internal logic.
[Notes]
This interface is used instead of assert_not_equal for Dictionary class comparison (JavaScript can not compare dictionary (Object) directly, like a Python, for example, {"a": 10} !== {"a": 10}
becomes true).
[Examples]
>>> import apysc as ap
>>> dict_1: ap.Dictionary = ap.Dictionary({"a": 10})
>>> dict_2: ap.Dictionary = ap.Dictionary({"a": 20})
>>> ap.assert_dicts_not_equal(dict_1, dict_2)