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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
# Copyright (c) 2021, Manfred Moitzi
# License: MIT License
import pytest
from ezdxf.tools.text import MTextEditor
def test_append_text():
m = MTextEditor()
m.append("TEXT")
assert str(m) == "TEXT"
def test_iadd_text():
m = MTextEditor()
m += "TEXT"
assert str(m) == "TEXT"
def test_stacked_text_limits_style():
m = MTextEditor().stack("1", "2")
assert str(m) == r"\S1^ 2;"
def test_stacked_text_with_horizontal_divider_line():
m = MTextEditor().stack("1", "2", "/")
assert str(m) == r"\S1/2;" # no space after "/" required
def test_stacked_text_with_slanted_divider_line():
m = MTextEditor().stack("1", "2", "#")
assert str(m) == r"\S1#2;" # no space after "#" required
def test_invalid_divider_char_raises_value_error():
m = MTextEditor()
pytest.raises(ValueError, m.stack, "1", "2", "x")
def test_change_color_name():
m = MTextEditor()
m.color("red")
assert str(m) == r"\C1;"
m.clear()
m.aci(0)
assert str(m) == r"\C0;"
def test_change_aci_color():
m = MTextEditor()
m.aci(0).aci(256)
assert str(m) == r"\C0;\C256;"
@pytest.mark.parametrize("aci", [-1, 257])
def test_aci_color_raises_value_error(aci):
with pytest.raises(ValueError):
MTextEditor().aci(aci)
def test_change_to_red_by_rgb():
m = MTextEditor().rgb((255, 0, 0))
assert str(m) == r"\c255;"
def test_change_to_green_by_rgb():
m = MTextEditor().rgb((0, 255, 0))
assert str(m) == r"\c65280;"
def test_change_to_blue_by_rgb():
m = MTextEditor().rgb((0, 0, 255))
assert str(m) == r"\c16711680;"
def test_change_font():
m = MTextEditor()
m.font("Arial", bold=False, italic=False)
assert str(m) == r"\fArial|b0|i0;"
def test_scale_height_factor():
assert str(MTextEditor().scale_height(2)) == r"\H2x;"
assert str(MTextEditor().scale_height(1.6666)) == r"\H1.667x;"
def test_absolute_text_height():
assert str(MTextEditor().height(2)) == r"\H2;"
assert str(MTextEditor().height(1.6666)) == r"\H1.667;"
def test_change_width_factor():
assert str(MTextEditor().width_factor(2)) == r"\W2;"
assert str(MTextEditor().width_factor(1.6666)) == r"\W1.667;"
def test_change_char_tracking_factor():
assert str(MTextEditor().char_tracking_factor(2)) == r"\T2;"
assert str(MTextEditor().char_tracking_factor(1.6666)) == r"\T1.667;"
def test_change_oblique_angle():
assert str(MTextEditor().oblique(0)) == r"\Q0;" # vertical
assert str(MTextEditor().oblique(15)) == r"\Q15;"
def test_fluent_interface():
m = MTextEditor("some text").color("red").stack("1", "2").append("end.")
assert str(m) == r"some text\C1;\S1^ 2;end."
def test_grouping():
m = MTextEditor("some text")
group_content = str(MTextEditor().font("Arial").append("Font=Arial"))
m.group(group_content)
assert str(m) == r"some text{\fArial|b0|i0;Font=Arial}"
def test_underline_text():
assert str(MTextEditor().underline("TEXT")) == r"\LTEXT\l"
def test_overline_text():
assert str(MTextEditor().overline("TEXT")) == r"\OTEXT\o"
def test_strike_through_text():
assert str(MTextEditor().strike_through("TEXT")) == r"\KTEXT\k"
def test_bullet_lists():
result = MTextEditor().bullet_list(
indent=4, # left indentation of the list items
bullets=["-", "+"], # bullets - mark in front of the list item
content=["first", "second"], # list items
)
assert str(result) == r"{\pxi-3,l4,t4;-^Ifirst\P+^Isecond\P}"
if __name__ == "__main__":
pytest.main([__file__])
|