forked from xlwings/xlwings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_font.py
106 lines (81 loc) · 2.81 KB
/
test_font.py
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
from pathlib import Path
import pytest
import xlwings as xw
this_dir = Path(__file__).resolve().parent
@pytest.fixture(scope="module")
def app():
with xw.App(visible=False) as app:
app.books.open(this_dir / "test book.xlsx")
yield app
# Range
def test_range_font_bold(app):
sheet = app.books[0].sheets[0]
sheet["A1"].value = "text"
assert sheet["A1"].font.bold is False
sheet["A1"].font.bold = True
assert sheet["A1"].font.bold is True
sheet["A1"].font.bold = False
assert sheet["A1"].font.bold is False
def test_range_font_italic(app):
sheet = app.books[0].sheets[0]
sheet["A1"].value = "text"
assert sheet["A1"].font.italic is False
sheet["A1"].font.italic = True
assert sheet["A1"].font.italic is True
sheet["A1"].font.italic = False
assert sheet["A1"].font.italic is False
def test_range_font_size(app):
sheet = app.books[0].sheets[0]
sheet["A1"].value = "text"
assert sheet["A1"].font.size != 0
sheet["A1"].font.size = 33
assert sheet["A1"].font.size == 33
def test_range_font_color(app):
sheet = app.books[0].sheets[0]
sheet["A1"].value = "text"
assert sheet["A1"].font.color == (0, 0, 0)
sheet["A1"].font.color = (255, 0, 0)
assert sheet["A1"].font.color == (255, 0, 0)
def test_range_font_name(app):
sheet = app.books[0].sheets[0]
sheet["A1"].value = "text"
sheet["A1"].font.name = "Calibri"
assert sheet["A1"].font.name == "Calibri"
sheet["A1"].font.name = "Arial"
assert sheet["A1"].font.name == "Arial"
# Shape
def test_shape_font_bold(app):
shape = xw.Book("test book.xlsx").sheets["shape"].shapes[0]
shape.text = "text"
assert shape.font.bold is False
shape.font.bold = True
assert shape.font.bold is True
shape.font.bold = False
assert shape.font.bold is False
def test_shape_font_italic(app):
shape = xw.Book("test book.xlsx").sheets["shape"].shapes[0]
shape.text = "text"
assert shape.font.italic is False
shape.font.italic = True
assert shape.font.italic is True
shape.font.italic = False
assert shape.font.italic is False
def test_shape_font_size(app):
shape = xw.Book("test book.xlsx").sheets["shape"].shapes[0]
shape.text = "text"
assert shape.font.size != 33
shape.font.size = 33
assert shape.font.size == 33
def test_shape_font_color(app):
shape = xw.Book("test book.xlsx").sheets["shape"].shapes[0]
shape.text = "text"
assert shape.font.color == (255, 255, 255)
shape.font.color = (255, 0, 0)
assert shape.font.color == (255, 0, 0)
def test_shape_font_name(app):
shape = xw.Book("test book.xlsx").sheets["shape"].shapes[0]
shape.text = "text"
shape.font.name = "Calibri"
assert shape.font.name == "Calibri"
shape.font.name = "Arial"
assert shape.font.name == "Arial"