File size: 4,019 Bytes
ef9c1a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
from __future__ import annotations
from pathlib import Path
import pytest
from manim import MathTex, SingleStringMathTex, Tex
def test_MathTex(config, using_opengl_renderer):
MathTex("a^2 + b^2 = c^2")
assert Path(config.media_dir, "Tex", "e4be163a00cf424f.svg").exists()
def test_SingleStringMathTex(config, using_opengl_renderer):
SingleStringMathTex("test")
assert Path(config.media_dir, "Tex", "8ce17c7f5013209f.svg").exists()
@pytest.mark.parametrize( # : PT006
("text_input", "length_sub"),
[("{{ a }} + {{ b }} = {{ c }}", 5), (r"\frac{1}{a+b\sqrt{2}}", 1)],
)
def test_double_braces_testing(using_opengl_renderer, text_input, length_sub):
t1 = MathTex(text_input)
assert len(t1.submobjects) == length_sub
def test_tex(config, using_opengl_renderer):
Tex("The horse does not eat cucumber salad.")
assert Path(config.media_dir, "Tex", "c3945e23e546c95a.svg").exists()
def test_tex_whitespace_arg(using_opengl_renderer):
"""Check that correct number of submobjects are created per string with whitespace separator"""
separator = "\t"
str_part_1 = "Hello"
str_part_2 = "world"
str_part_3 = "It is"
str_part_4 = "me!"
tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)
assert len(tex) == 4
assert len(tex[0]) == len("".join((str_part_1 + separator).split()))
assert len(tex[1]) == len("".join((str_part_2 + separator).split()))
assert len(tex[2]) == len("".join((str_part_3 + separator).split()))
assert len(tex[3]) == len("".join(str_part_4.split()))
def test_tex_non_whitespace_arg(using_opengl_renderer):
"""Check that correct number of submobjects are created per string with non_whitespace characters"""
separator = ","
str_part_1 = "Hello"
str_part_2 = "world"
str_part_3 = "It is"
str_part_4 = "me!"
tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)
assert len(tex) == 4
assert len(tex[0]) == len("".join((str_part_1 + separator).split()))
assert len(tex[1]) == len("".join((str_part_2 + separator).split()))
assert len(tex[2]) == len("".join((str_part_3 + separator).split()))
assert len(tex[3]) == len("".join(str_part_4.split()))
def test_tex_white_space_and_non_whitespace_args(using_opengl_renderer):
"""Check that correct number of submobjects are created per string when mixing characters with whitespace"""
separator = ", \n . \t\t"
str_part_1 = "Hello"
str_part_2 = "world"
str_part_3 = "It is"
str_part_4 = "me!"
tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)
assert len(tex) == 4
assert len(tex[0]) == len("".join((str_part_1 + separator).split()))
assert len(tex[1]) == len("".join((str_part_2 + separator).split()))
assert len(tex[2]) == len("".join((str_part_3 + separator).split()))
assert len(tex[3]) == len("".join(str_part_4.split()))
def test_tex_size(using_opengl_renderer):
"""Check that the size of a :class:`Tex` string is not changed."""
text = Tex("what").center()
vertical = text.get_top() - text.get_bottom()
horizontal = text.get_right() - text.get_left()
assert round(vertical[1], 4) == 0.3512
assert round(horizontal[0], 4) == 1.0420
def test_font_size(using_opengl_renderer):
"""Test that tex_mobject classes return
the correct font_size value after being scaled.
"""
string = MathTex(0).scale(0.3)
assert round(string.font_size, 5) == 14.4
def test_font_size_vs_scale(using_opengl_renderer):
"""Test that scale produces the same results as .scale()"""
num = MathTex(0, font_size=12)
num_scale = MathTex(0).scale(1 / 4)
assert num.height == num_scale.height
def test_changing_font_size(using_opengl_renderer):
"""Test that the font_size property properly scales tex_mobject.py classes."""
num = Tex("0", font_size=12)
num.font_size = 48
assert num.height == Tex("0", font_size=48).height
|