Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Replace assert with np.testing assertions (#2743)

Baroudi Aymenbdf7b73ce1fa
diff --git a/tests/opengl/test_axes_shift_opengl.py b/tests/opengl/test_axes_shift_opengl.py
index 731db633f..1ae58afff 100644
--- a/tests/opengl/test_axes_shift_opengl.py
+++ b/tests/opengl/test_axes_shift_opengl.py
@@ -7,5 +7,9 @@ from manim.mobject.graphing.coordinate_systems import Axes
def test_axes_origin_shift(using_opengl_renderer):
ax = Axes(x_range=(5, 10, 1), y_range=(40, 45, 0.5))
- assert np.allclose(ax.coords_to_point(5.0, 40.0), ax.x_axis.number_to_point(5))
- assert np.allclose(ax.coords_to_point(5.0, 40.0), ax.y_axis.number_to_point(40))
+ np.testing.assert_allclose(
+ ax.coords_to_point(5.0, 40.0), ax.x_axis.number_to_point(5)
+ )
+ np.testing.assert_allclose(
+ ax.coords_to_point(5.0, 40.0), ax.y_axis.number_to_point(40)
+ )
diff --git a/tests/opengl/test_color_opengl.py b/tests/opengl/test_color_opengl.py
index e3f6940ac..32f9dfbdd 100644
--- a/tests/opengl/test_color_opengl.py
+++ b/tests/opengl/test_color_opengl.py
@@ -18,15 +18,21 @@ def test_background_color(using_opengl_renderer):
S = Scene()
S.renderer.background_color = "#ff0000"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 0, 0, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([255, 0, 0, 255])
+ )
S.renderer.background_color = "#436f80"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([67, 111, 128, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([67, 111, 128, 255])
+ )
S.renderer.background_color = "#fff"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 255, 255, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([255, 255, 255, 255])
+ )
def test_set_color(using_opengl_renderer):
diff --git a/tests/opengl/test_config_opengl.py b/tests/opengl/test_config_opengl.py
index f3013800d..378ba3355 100644
--- a/tests/opengl/test_config_opengl.py
+++ b/tests/opengl/test_config_opengl.py
@@ -26,7 +26,7 @@ def test_tempconfig(using_opengl_renderer):
# check that config is correctly restored
for k, v in original.items():
if isinstance(v, np.ndarray):
- assert np.allclose(config[k], v)
+ np.testing.assert_allclose(config[k], v)
else:
assert config[k] == v
@@ -43,7 +43,7 @@ def test_background_color(using_opengl_renderer):
scene = MyScene()
scene.render()
frame = scene.renderer.get_frame()
- assert np.allclose(frame[0, 0], [255, 255, 255, 255])
+ np.testing.assert_allclose(frame[0, 0], [255, 255, 255, 255])
def test_digest_file(using_opengl_renderer, tmp_path):
@@ -67,8 +67,10 @@ def test_digest_file(using_opengl_renderer, tmp_path):
def test_frame_size(using_opengl_renderer, tmp_path):
"""Test that the frame size can be set via config file."""
- assert np.allclose(config.aspect_ratio, config.pixel_width / config.pixel_height)
- assert np.allclose(config.frame_height, 8.0)
+ np.testing.assert_allclose(
+ config.aspect_ratio, config.pixel_width / config.pixel_height
+ )
+ np.testing.assert_allclose(config.frame_height, 8.0)
with tempconfig({}):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
@@ -83,10 +85,10 @@ def test_frame_size(using_opengl_renderer, tmp_path):
config.digest_file(tmp_cfg.name)
# aspect ratio is set using pixel measurements
- assert np.allclose(config.aspect_ratio, 1.0)
+ np.testing.assert_allclose(config.aspect_ratio, 1.0)
# if not specified in the cfg file, frame_width is set using the aspect ratio
- assert np.allclose(config.frame_height, 8.0)
- assert np.allclose(config.frame_width, 8.0)
+ np.testing.assert_allclose(config.frame_height, 8.0)
+ np.testing.assert_allclose(config.frame_width, 8.0)
with tempconfig({}):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
@@ -102,10 +104,10 @@ def test_frame_size(using_opengl_renderer, tmp_path):
tmp_cfg.close()
config.digest_file(tmp_cfg.name)
- assert np.allclose(config.aspect_ratio, 1.0)
+ np.testing.assert_allclose(config.aspect_ratio, 1.0)
# if both are specified in the cfg file, the aspect ratio is ignored
- assert np.allclose(config.frame_height, 10.0)
- assert np.allclose(config.frame_width, 10.0)
+ np.testing.assert_allclose(config.frame_height, 10.0)
+ np.testing.assert_allclose(config.frame_width, 10.0)
def test_temporary_dry_run(using_opengl_renderer):
diff --git a/tests/opengl/test_coordinate_system_opengl.py b/tests/opengl/test_coordinate_system_opengl.py
index 8e1d778e5..fb0a51748 100644
--- a/tests/opengl/test_coordinate_system_opengl.py
+++ b/tests/opengl/test_coordinate_system_opengl.py
@@ -21,8 +21,8 @@ def test_initial_config(using_opengl_renderer):
assert cs.y_range[2] == 1.0
ax = Axes()
- assert np.allclose(ax.get_center(), ORIGIN)
- assert np.allclose(ax.y_axis_config["label_direction"], LEFT)
+ np.testing.assert_allclose(ax.get_center(), ORIGIN)
+ np.testing.assert_allclose(ax.y_axis_config["label_direction"], LEFT)
with tempconfig({"frame_x_radius": 100, "frame_y_radius": 200}):
cs = CS()
@@ -102,7 +102,7 @@ def test_point_to_coords(using_opengl_renderer):
# get the coordinates of the circle with respect to the axes
coords = np.around(ax.point_to_coords(circ.get_right()), decimals=4)
- assert np.array_equal(coords, (7.0833, 2.6667))
+ np.testing.assert_array_equal(coords, (7.0833, 2.6667))
def test_coords_to_point(using_opengl_renderer):
@@ -110,7 +110,7 @@ def test_coords_to_point(using_opengl_renderer):
# a point with respect to the axes
c2p_coord = np.around(ax.coords_to_point(2, 2), decimals=4)
- assert np.array_equal(c2p_coord, (1.7143, 1.5, 0))
+ np.testing.assert_array_equal(c2p_coord, (1.7143, 1.5, 0))
def test_input_to_graph_point(using_opengl_renderer):
@@ -122,8 +122,8 @@ def test_input_to_graph_point(using_opengl_renderer):
# move a square to PI on the cosine curve.
position = np.around(ax.input_to_graph_point(x=PI, graph=curve), decimals=4)
- assert np.array_equal(position, (2.6928, -0.75, 0))
+ np.testing.assert_array_equal(position, (2.6928, -0.75, 0))
# test the line_graph implementation
position = np.around(ax.input_to_graph_point(x=PI, graph=line_graph), decimals=4)
- assert np.array_equal(position, (2.6928, 1.2876, 0))
+ np.testing.assert_array_equal(position, (2.6928, 1.2876, 0))
diff --git a/tests/opengl/test_family_opengl.py b/tests/opengl/test_family_opengl.py
index a7dd35e93..96a4814d7 100644
--- a/tests/opengl/test_family_opengl.py
+++ b/tests/opengl/test_family_opengl.py
@@ -82,4 +82,4 @@ def test_shift_family(using_opengl_renderer):
positions_after = {m: m.get_center().copy() for m in family}
for m in family:
- assert np.allclose(positions_before[m] + RIGHT, positions_after[m])
+ np.testing.assert_allclose(positions_before[m] + RIGHT, positions_after[m])
diff --git a/tests/opengl/test_opengl_vectorized_mobject.py b/tests/opengl/test_opengl_vectorized_mobject.py
index 64b53641c..8e0ba2258 100644
--- a/tests/opengl/test_opengl_vectorized_mobject.py
+++ b/tests/opengl/test_opengl_vectorized_mobject.py
@@ -22,7 +22,7 @@ def test_opengl_vmobject_point_from_propotion(using_opengl_renderer):
# Total length of 6, so halfway along the object
# would be at length 3, which lands in the first, long line.
- assert np.all(obj.point_from_proportion(0.5) == np.array([3, 0, 0]))
+ np.testing.assert_array_equal(obj.point_from_proportion(0.5), np.array([3, 0, 0]))
with pytest.raises(ValueError, match="between 0 and 1"):
obj.point_from_proportion(2)
diff --git a/tests/opengl/test_unit_geometry_opengl.py b/tests/opengl/test_unit_geometry_opengl.py
index c92b5978c..f92bc9ff3 100644
--- a/tests/opengl/test_unit_geometry_opengl.py
+++ b/tests/opengl/test_unit_geometry_opengl.py
@@ -6,4 +6,6 @@ from manim import Sector
def test_get_arc_center(using_opengl_renderer):
- assert np.all(Sector(arc_center=[1, 2, 0]).get_arc_center() == [1, 2, 0])
+ np.testing.assert_array_equal(
+ Sector(arc_center=[1, 2, 0]).get_arc_center(), [1, 2, 0]
+ )
diff --git a/tests/test_axes_shift.py b/tests/test_axes_shift.py
index 6697f5d83..b733ffe50 100644
--- a/tests/test_axes_shift.py
+++ b/tests/test_axes_shift.py
@@ -8,8 +8,8 @@ from manim.mobject.graphing.scale import LogBase
def test_axes_origin_shift():
ax = Axes(x_range=(5, 10, 1), y_range=(40, 45, 0.5))
- assert np.allclose(ax.coords_to_point(5, 40), ax.x_axis.number_to_point(5))
- assert np.allclose(ax.coords_to_point(5, 40), ax.y_axis.number_to_point(40))
+ np.testing.assert_allclose(ax.coords_to_point(5, 40), ax.x_axis.number_to_point(5))
+ np.testing.assert_allclose(ax.coords_to_point(5, 40), ax.y_axis.number_to_point(40))
def test_axes_origin_shift_logbase():
@@ -19,19 +19,25 @@ def test_axes_origin_shift_logbase():
x_axis_config={"scaling": LogBase()},
y_axis_config={"scaling": LogBase()},
)
- assert np.allclose(
+ np.testing.assert_allclose(
ax.coords_to_point(10**5, 10**3), ax.x_axis.number_to_point(10**5)
)
- assert np.allclose(
+ np.testing.assert_allclose(
ax.coords_to_point(10**5, 10**3), ax.y_axis.number_to_point(10**3)
)
def test_3daxes_origin_shift():
ax = ThreeDAxes(x_range=(3, 9, 1), y_range=(6, 12, 1), z_range=(-1, 1, 0.5))
- assert np.allclose(ax.coords_to_point(3, 6, 0), ax.x_axis.number_to_point(3))
- assert np.allclose(ax.coords_to_point(3, 6, 0), ax.y_axis.number_to_point(6))
- assert np.allclose(ax.coords_to_point(3, 6, 0), ax.z_axis.number_to_point(0))
+ np.testing.assert_allclose(
+ ax.coords_to_point(3, 6, 0), ax.x_axis.number_to_point(3)
+ )
+ np.testing.assert_allclose(
+ ax.coords_to_point(3, 6, 0), ax.y_axis.number_to_point(6)
+ )
+ np.testing.assert_allclose(
+ ax.coords_to_point(3, 6, 0), ax.z_axis.number_to_point(0)
+ )
def test_3daxes_origin_shift_logbase():
@@ -43,15 +49,15 @@ def test_3daxes_origin_shift_logbase():
y_axis_config={"scaling": LogBase()},
z_axis_config={"scaling": LogBase()},
)
- assert np.allclose(
+ np.testing.assert_allclose(
ax.coords_to_point(10**3, 10**6, 10**2),
ax.x_axis.number_to_point(10**3),
)
- assert np.allclose(
+ np.testing.assert_allclose(
ax.coords_to_point(10**3, 10**6, 10**2),
ax.y_axis.number_to_point(10**6),
)
- assert np.allclose(
+ np.testing.assert_allclose(
ax.coords_to_point(10**3, 10**6, 10**2),
ax.z_axis.number_to_point(10**2),
)
diff --git a/tests/test_boolean_ops.py b/tests/test_boolean_ops.py
index 30ea22906..844a9f2b5 100644
--- a/tests/test_boolean_ops.py
+++ b/tests/test_boolean_ops.py
@@ -55,4 +55,4 @@ def test_vmobject_to_skia_path_and_inverse(test_input):
new_vmobject = a._convert_skia_path_to_vmobject(path)
# for some reason there is an extra 4 points in new vmobject than original
- assert np.where(np.isclose(new_vmobject.points[:-4], test_input.points))
+ np.testing.assert_allclose(new_vmobject.points[:-4], test_input.points)
diff --git a/tests/test_color.py b/tests/test_color.py
index 1a84052df..fa9e22a77 100644
--- a/tests/test_color.py
+++ b/tests/test_color.py
@@ -15,20 +15,28 @@ def test_background_color():
S = Scene()
S.camera.background_color = "#ff0000"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 0, 0, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([255, 0, 0, 255])
+ )
S.camera.background_color = "#436f80"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([67, 111, 128, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([67, 111, 128, 255])
+ )
S.camera.background_color = "#fff"
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 255, 255, 255]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([255, 255, 255, 255])
+ )
S.camera.background_color = "#bbffbb"
S.camera.background_opacity = 0.5
S.renderer.update_frame(S)
- assert np.all(S.renderer.get_frame()[0, 0] == np.array([93, 127, 93, 127]))
+ np.testing.assert_array_equal(
+ S.renderer.get_frame()[0, 0], np.array([93, 127, 93, 127])
+ )
def test_set_color():
diff --git a/tests/test_config.py b/tests/test_config.py
index cab333446..c54b73877 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -28,7 +28,7 @@ def test_tempconfig():
# check that config is correctly restored
for k, v in original.items():
if isinstance(v, np.ndarray):
- assert np.allclose(config[k], v)
+ np.testing.assert_allclose(config[k], v)
else:
assert config[k] == v
@@ -50,13 +50,13 @@ def test_transparent():
scene = MyScene()
scene.render()
frame = scene.renderer.get_frame()
- assert np.allclose(frame[0, 0], [0, 0, 0, 255])
+ np.testing.assert_allclose(frame[0, 0], [0, 0, 0, 255])
with tempconfig({"transparent": True, "dry_run": True}):
scene = MyScene()
scene.render()
frame = scene.renderer.get_frame()
- assert np.allclose(frame[0, 0], [0, 0, 0, 0])
+ np.testing.assert_allclose(frame[0, 0], [0, 0, 0, 0])
config["verbosity"] = orig_verbosity
@@ -67,7 +67,7 @@ def test_background_color():
scene = MyScene()
scene.render()
frame = scene.renderer.get_frame()
- assert np.allclose(frame[0, 0], [255, 255, 255, 255])
+ np.testing.assert_allclose(frame[0, 0], [255, 255, 255, 255])
def test_digest_file(tmp_path):
@@ -136,8 +136,10 @@ def test_custom_dirs(tmp_path):
def test_frame_size(tmp_path):
"""Test that the frame size can be set via config file."""
- assert np.allclose(config.aspect_ratio, config.pixel_width / config.pixel_height)
- assert np.allclose(config.frame_height, 8.0)
+ np.testing.assert_allclose(
+ config.aspect_ratio, config.pixel_width / config.pixel_height
+ )
+ np.testing.assert_allclose(config.frame_height, 8.0)
with tempconfig({}):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
@@ -152,10 +154,10 @@ def test_frame_size(tmp_path):
config.digest_file(tmp_cfg.name)
# aspect ratio is set using pixel measurements
- assert np.allclose(config.aspect_ratio, 1.0)
+ np.testing.assert_allclose(config.aspect_ratio, 1.0)
# if not specified in the cfg file, frame_width is set using the aspect ratio
- assert np.allclose(config.frame_height, 8.0)
- assert np.allclose(config.frame_width, 8.0)
+ np.testing.assert_allclose(config.frame_height, 8.0)
+ np.testing.assert_allclose(config.frame_width, 8.0)
with tempconfig({}):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
@@ -171,10 +173,10 @@ def test_frame_size(tmp_path):
tmp_cfg.close()
config.digest_file(tmp_cfg.name)
- assert np.allclose(config.aspect_ratio, 1.0)
+ np.testing.assert_allclose(config.aspect_ratio, 1.0)
# if both are specified in the cfg file, the aspect ratio is ignored
- assert np.allclose(config.frame_height, 10.0)
- assert np.allclose(config.frame_width, 10.0)
+ np.testing.assert_allclose(config.frame_height, 10.0)
+ np.testing.assert_allclose(config.frame_width, 10.0)
def test_temporary_dry_run():
diff --git a/tests/test_coordinate_system.py b/tests/test_coordinate_system.py
index 8a359d7a1..e463ef166 100644
--- a/tests/test_coordinate_system.py
+++ b/tests/test_coordinate_system.py
@@ -21,8 +21,8 @@ def test_initial_config():
assert cs.y_range[2] == 1.0
ax = Axes()
- assert np.allclose(ax.get_center(), ORIGIN)
- assert np.allclose(ax.y_axis_config["label_direction"], LEFT)
+ np.testing.assert_allclose(ax.get_center(), ORIGIN)
+ np.testing.assert_allclose(ax.y_axis_config["label_direction"], LEFT)
with tempconfig({"frame_x_radius": 100, "frame_y_radius": 200}):
cs = CS()
@@ -99,7 +99,7 @@ def test_point_to_coords():
# get the coordinates of the circle with respect to the axes
coords = np.around(ax.point_to_coords(circ.get_right()), decimals=4)
- assert np.array_equal(coords, (7.0833, 2.6667))
+ np.testing.assert_array_equal(coords, (7.0833, 2.6667))
def test_coords_to_point():
@@ -107,7 +107,7 @@ def test_coords_to_point():
# a point with respect to the axes
c2p_coord = np.around(ax.coords_to_point(2, 2), decimals=4)
- assert np.array_equal(c2p_coord, (1.7143, 1.5, 0))
+ np.testing.assert_array_equal(c2p_coord, (1.7143, 1.5, 0))
def test_input_to_graph_point():
@@ -119,8 +119,8 @@ def test_input_to_graph_point():
# move a square to PI on the cosine curve.
position = np.around(ax.input_to_graph_point(x=PI, graph=curve), decimals=4)
- assert np.array_equal(position, (2.6928, -0.75, 0))
+ np.testing.assert_array_equal(position, (2.6928, -0.75, 0))
# test the line_graph implementation
position = np.around(ax.input_to_graph_point(x=PI, graph=line_graph), decimals=4)
- assert np.array_equal(position, (2.6928, 1.2876, 0))
+ np.testing.assert_array_equal(position, (2.6928, 1.2876, 0))
diff --git a/tests/test_family.py b/tests/test_family.py
index 0e0c1e518..90b55ebff 100644
--- a/tests/test_family.py
+++ b/tests/test_family.py
@@ -81,4 +81,4 @@ def test_shift_family():
positions_after = {m: m.get_center() for m in family}
for m in family:
- assert np.allclose(positions_before[m] + RIGHT, positions_after[m])
+ np.testing.assert_allclose(positions_before[m] + RIGHT, positions_after[m])
diff --git a/tests/test_set_attr.py b/tests/test_set_attr.py
index e04a2286f..2e483062e 100644
--- a/tests/test_set_attr.py
+++ b/tests/test_set_attr.py
@@ -11,16 +11,16 @@ def test_Data():
config.renderer = "opengl"
a = Square().move_to(RIGHT)
data_bb = a.data["bounding_box"]
- assert np.array_equal(
+ np.testing.assert_array_equal(
data_bb,
np.array([[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [2.0, 1.0, 0.0]]),
)
# test that calling the attribute equals calling it from self.data
- assert np.array_equal(a.bounding_box, data_bb)
+ np.testing.assert_array_equal(a.bounding_box, data_bb)
# test that the array can be indexed
- assert np.array_equal(
+ np.testing.assert_array_equal(
a.bounding_box[1],
np.array(
[1.0, 0.0, 0.0],
@@ -33,10 +33,10 @@ def test_Data():
# test that both the attr and self.data arrays match after adjusting a value
data_bb = a.data["bounding_box"]
- assert np.array_equal(
+ np.testing.assert_array_equal(
data_bb,
np.array([[0.0, -1.0, 0.0], [300.0, 300.0, 300.0], [2.0, 1.0, 0.0]]),
)
- assert np.array_equal(a.bounding_box, data_bb)
+ np.testing.assert_array_equal(a.bounding_box, data_bb)
config.renderer = "cairo" # needs to be here or else the following cairo tests fail
diff --git a/tests/test_space_ops.py b/tests/test_space_ops.py
index 108f586e0..8ca826d0a 100644
--- a/tests/test_space_ops.py
+++ b/tests/test_space_ops.py
@@ -12,15 +12,15 @@ def test_rotate_vector():
rotated = rotate_vector(vec, np.pi / 2)
assert np.round(rotated[0], 5) == -1.0
assert not np.round(rotated[1:], 5).any()
- assert np.all(rotate_vector(np.zeros(3), np.pi / 4) == np.zeros(3))
+ np.testing.assert_array_equal(rotate_vector(np.zeros(3), np.pi / 4), np.zeros(3))
def test_rotation_matrices():
ang = np.pi / 6
ax = np.array([1, 1, 1])
- assert np.all(
- np.round(rotation_matrix(ang, ax, True), 5)
- == np.round(
+ np.testing.assert_array_equal(
+ np.round(rotation_matrix(ang, ax, True), 5),
+ np.round(
np.array(
[
[0.91068, -0.24402, 0.33333, 0.0],
@@ -30,27 +30,27 @@ def test_rotation_matrices():
]
),
5,
- )
+ ),
)
- assert np.all(
- np.round(rotation_about_z(np.pi / 3), 5)
- == np.array(
+ np.testing.assert_array_equal(
+ np.round(rotation_about_z(np.pi / 3), 5),
+ np.array(
[
[0.5, -0.86603, 0.0],
[0.86603, 0.5, 0.0],
[0.0, 0.0, 1.0],
]
- )
+ ),
)
- assert np.all(
- np.round(z_to_vector(np.array([1, 2, 3])), 5)
- == np.array(
+ np.testing.assert_array_equal(
+ np.round(z_to_vector(np.array([1, 2, 3])), 5),
+ np.array(
[
[0.96362, 0.0, 0.26726],
[-0.14825, 0.83205, 0.53452],
[-0.22237, -0.5547, 0.80178],
]
- )
+ ),
)
@@ -64,16 +64,18 @@ def test_angle_of_vector():
def test_center_of_mass():
- assert np.all(center_of_mass([[0, 0, 0], [1, 2, 3]]) == np.array([0.5, 1.0, 1.5]))
+ np.testing.assert_array_equal(
+ center_of_mass([[0, 0, 0], [1, 2, 3]]), np.array([0.5, 1.0, 1.5])
+ )
def test_line_intersection():
- assert np.all(
+ np.testing.assert_array_equal(
line_intersection(
[[0, 0, 0], [3, 3, 0]],
[[0, 3, 0], [3, 0, 0]],
- )
- == np.array([1.5, 1.5, 0.0])
+ ),
+ np.array([1.5, 1.5, 0.0]),
)
with pytest.raises(ValueError):
line_intersection( # parallel lines
@@ -90,12 +92,12 @@ def test_line_intersection():
[[2, 2, 0], [3, 1, 0]],
[[2, 2, 0], [3, 1, 0]],
)
- assert np.all(
+ np.testing.assert_array_equal(
line_intersection( # lines with ends out of bounds
[[0, 0, 0], [1, 1, 0]],
[[0, 4, 0], [1, 3, 0]],
- )
- == np.array([2, 2, 0])
+ ),
+ np.array([2, 2, 0]),
)
@@ -106,8 +108,10 @@ def test_shoelace():
def test_polar_coords():
a = np.array([1, 1, 0])
b = (2, np.pi / 2, np.pi / 2)
- assert np.all(
- np.round(cartesian_to_spherical(a), 4)
- == np.round([2**0.5, np.pi / 4, np.pi / 2], 4),
+ np.testing.assert_array_equal(
+ np.round(cartesian_to_spherical(a), 4),
+ np.round([2**0.5, np.pi / 4, np.pi / 2], 4),
+ )
+ np.testing.assert_array_equal(
+ np.round(spherical_to_cartesian(b), 4), np.array([0, 2, 0])
)
- assert np.all(np.round(spherical_to_cartesian(b), 4) == np.array([0, 2, 0]))
diff --git a/tests/test_unit_geometry.py b/tests/test_unit_geometry.py
index 23b944ece..1729752ff 100644
--- a/tests/test_unit_geometry.py
+++ b/tests/test_unit_geometry.py
@@ -10,7 +10,9 @@ from manim import BackgroundRectangle, Circle, Sector
def test_get_arc_center():
- assert np.all(Sector(arc_center=[1, 2, 0]).get_arc_center() == [1, 2, 0])
+ np.testing.assert_array_equal(
+ Sector(arc_center=[1, 2, 0]).get_arc_center(), [1, 2, 0]
+ )
def test_BackgroundRectangle(caplog):
diff --git a/tests/test_units.py b/tests/test_units.py
index ff1ad7886..6c2cba1ac 100644
--- a/tests/test_units.py
+++ b/tests/test_units.py
@@ -10,21 +10,22 @@ from manim.utils.unit import Degrees, Munits, Percent, Pixels
def test_units():
# make sure we are using the right frame geometry
assert config.pixel_width == 1920
- assert np.isclose(config.frame_height, 8.0)
+
+ np.testing.assert_allclose(config.frame_height, 8.0)
# Munits should be equivalent to the internal logical units
- assert np.isclose(8.0 * Munits, config.frame_height)
+ np.testing.assert_allclose(8.0 * Munits, config.frame_height)
# Pixels should convert from pixels to Munits
- assert np.isclose(1920 * Pixels, config.frame_width)
+ np.testing.assert_allclose(1920 * Pixels, config.frame_width)
# Percent should give the fractional length of the frame
- assert np.isclose(50 * Percent(X_AXIS), config.frame_width / 2)
- assert np.isclose(50 * Percent(Y_AXIS), config.frame_height / 2)
+ np.testing.assert_allclose(50 * Percent(X_AXIS), config.frame_width / 2)
+ np.testing.assert_allclose(50 * Percent(Y_AXIS), config.frame_height / 2)
# The length of the Z axis is not defined
with pytest.raises(NotImplementedError):
Percent(Z_AXIS)
# Degrees should convert from degrees to radians
- assert np.isclose(180 * Degrees, PI)
+ np.testing.assert_allclose(180 * Degrees, PI)
diff --git a/tests/test_vectorized_mobject.py b/tests/test_vectorized_mobject.py
index b6013c92f..181efc044 100644
--- a/tests/test_vectorized_mobject.py
+++ b/tests/test_vectorized_mobject.py
@@ -21,7 +21,7 @@ def test_vmobject_point_from_propotion():
# Total length of 6, so halfway along the object
# would be at length 3, which lands in the first, long line.
- assert np.all(obj.point_from_proportion(0.5) == np.array([3, 0, 0]))
+ np.testing.assert_array_equal(obj.point_from_proportion(0.5), np.array([3, 0, 0]))
with pytest.raises(ValueError, match="between 0 and 1"):
obj.point_from_proportion(2)
@@ -271,7 +271,7 @@ def test_vmobject_same_points_become():
a = Square()
b = Circle()
a.become(b)
- assert np.array_equal(a.points, b.points)
+ np.testing.assert_array_equal(a.points, b.points)
assert len(a.submobjects) == len(b.submobjects)
@@ -279,7 +279,7 @@ def test_vmobject_same_num_submobjects_become():
a = Square()
b = RegularPolygon(n=6)
a.become(b)
- assert np.array_equal(a.points, b.points)
+ np.testing.assert_array_equal(a.points, b.points)
assert len(a.submobjects) == len(b.submobjects)
@@ -287,11 +287,11 @@ def test_vmobject_different_num_points_and_submobjects_become():
a = Square()
b = VGroup(Circle(), Square())
a.become(b)
- assert np.array_equal(a.points, b.points)
+ np.testing.assert_array_equal(a.points, b.points)
assert len(a.submobjects) == len(b.submobjects)
def test_vmobject_point_at_angle():
a = Circle()
p = a.point_at_angle(4 * PI)
- assert np.array_equal(a.points[0], p)
+ np.testing.assert_array_equal(a.points[0], p)