-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_yaptool.py
291 lines (220 loc) · 7.99 KB
/
test_yaptool.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
"""Test suite for plottingtools.py"""
import matplotlib.figure # type: ignore
import matplotlib.pyplot as plt # type: ignore
import pytest
import yaptool as yap
######################
# General Aesthetics #
######################
def test_tex_on_off():
"""Test turning TeX mode on and off."""
yap.texon()
yap.texoff()
def test_light_and_darkmode():
"""Test switiching to lightmode and darkmode."""
yap.lightmode()
yap.darkmode()
####################
# Types of layouts #
####################
def test_singleplot():
"""Test making a new single plot figure."""
fig, _ = yap.singleplot(size=(7, 5))
assert isinstance(fig, matplotlib.figure.Figure)
plt.close()
def test_multiplot():
"""Test making a new multi plot figure."""
_, _ = yap.multiplot(nrows=3,
ncols=2,
size_xy=(20, 12),
hspace=1,
wspace=1)
plt.close()
#############################
# Adding elements to a plot #
#############################
def test_legend():
"""Test adding a legend."""
_, ax = yap.singleplot()
ax.scatter([1, 2, 3], [1, 2, 3], label="my label")
yap.legend(ax, loc="upper left", fontsize=20, frame=True)
plt.close()
def test_legend_pathological():
"""Pathological tests for adding a legend."""
with pytest.raises(ValueError):
yap.legend("not an ax object")
def test_title():
"""Test adding a title."""
_, ax = yap.singleplot()
yap.title(ax, "abcdef", fontsize=25, pad=10)
assert ax.get_title() == "abcdef"
plt.close()
def test_title_pathological():
"""Pathological test for adding a title."""
with pytest.raises(ValueError):
yap.title("not an ax object", "abcdef", fontsize=25, pad=10)
def test_labels():
"""Test adding ax labels."""
_, ax = yap.singleplot()
yap.labels(ax, xlabel="xlabel", ylabel="ylabel", fontsize=10, pad=5)
assert ax.get_xlabel() == "xlabel"
assert ax.get_ylabel() == "ylabel"
plt.close()
def test_labels_pathological():
"""Pathological test for adding ax labels."""
with pytest.raises(ValueError):
yap.labels("not an ax object",
xlabel="xlabel",
ylabel="ylabel",
fontsize=10,
pad=5)
def test_diagonal():
"""Test adding diagonal."""
_, ax = yap.singleplot()
yap.diagonal(ax)
plt.close()
def test_diagonal_pathological():
"""Pathological test for adding diagonal."""
with pytest.raises(ValueError):
yap.diagonal("not an ax object")
def test_rectangle():
"""Test adding a rectangle."""
_, ax = yap.singleplot()
yap.rectangle(ax,
x1=1,
x2=2,
y1=1,
y2=2,
linewidth=3,
linestyle=":",
fill=True)
plt.close()
def test_rectangle_pathological():
"""Pathological test for adding a rectangle."""
with pytest.raises(ValueError):
yap.rectangle("not an ax object",
x1=1,
x2=2,
y1=1,
y2=2,
linewidth=3,
linestyle=":",
fill=True)
_, ax = yap.singleplot()
with pytest.raises(ValueError):
yap.rectangle(ax,
x1="not a number",
x2=2,
y1=1,
y2=2,
linewidth=3,
linestyle=":",
fill=True)
plt.close()
#############################
# Change elements of a plot #
#############################
def test_despine():
"""Test for despining."""
_, ax = yap.singleplot()
yap.despine(ax, ['top', 'left', 'bottom', 'right'])
plt.close()
def test_despine_pathological():
"""Pathological test for despining."""
with pytest.raises(ValueError):
yap.despine("not an ax object")
def test_respine():
"""Test respining."""
_, ax = yap.singleplot()
yap.respine(ax, ['top', 'left', 'bottom', 'right'])
plt.close()
def test_respine_pathological():
"""Pathological test for respining."""
with pytest.raises(ValueError):
yap.respine("not an ax object")
def test_ticklabelsize():
"""Test setting ticklabel size."""
_, ax = yap.singleplot()
yap.ticklabelsize(ax, size=25)
plt.close()
def test_ticklabelsize_pathological():
"""Pathological test for setting ticklabel size."""
with pytest.raises(ValueError):
yap.ticklabelsize("not an ax object")
def test_limits():
"""Test setting ax limits."""
_, ax = yap.singleplot()
yap.limits(ax, xlimits=(3, 5), ylimits=None)
yap.limits(ax, xlimits=None, ylimits=(4, 6))
assert ax.get_xlim() == (3, 5)
assert ax.get_ylim() == (4, 6)
plt.close()
def test_limits_pathological():
"""Pathological test for setting ax limits."""
with pytest.raises(ValueError):
yap.limits("not an ax object", xlimits=(3, 5), ylimits=None)
def test_ticks_and_labels():
"""Test setting ax ticks and labels."""
_, ax = yap.singleplot()
yap.ticks_and_labels(ax, which="x", ticks=[-0.14, 1, 2], ticklabels=None)
yap.ticks_and_labels(ax, which="y", ticks=[-0.14, 1, 2], ticklabels=None)
yap.ticks_and_labels(ax, which="xy", ticks=[-0.14, 1, 2], ticklabels=None)
yap.ticks_and_labels(ax, which="yx", ticks=[-0.14, 1, 2], ticklabels=None)
plt.close()
def test_ticks_and_labels_pathological():
"""Pathological tests for setting ax ticks and labels."""
_, ax = yap.singleplot()
with pytest.raises(ValueError):
yap.ticks_and_labels(ax,
which="aaaaaaaaaaaaaaa",
ticks=[-0.14, 1, 2],
ticklabels=None)
plt.close()
with pytest.raises(ValueError):
yap.ticks_and_labels("not an ax object",
which="yx",
ticks=[-0.14, 1, 2],
ticklabels=None)
@pytest.mark.filterwarnings('ignore::UserWarning')
def test_rotate_ticklabels():
"""Test setting tick label rotation."""
_, ax = yap.singleplot()
yap.rotate_ticklabels(ax, which="x", rotation=10.5)
yap.rotate_ticklabels(ax, which="y", rotation=-10.5)
yap.rotate_ticklabels(ax, which="xy", rotation=10.5)
yap.rotate_ticklabels(ax, which="yx", rotation=-10.5)
yap.rotate_ticklabels(ax, which="both", rotation=-10.5)
plt.close()
@pytest.mark.filterwarnings('ignore::UserWarning')
def test_rotate_ticklabels_pathological():
"""Pathological test for setting tick label rotation."""
_, ax = yap.singleplot()
with pytest.raises(ValueError):
yap.rotate_ticklabels(ax, which="aaaaaaaaaaaaaaaa", rotation=10.5)
plt.close()
with pytest.raises(ValueError):
yap.rotate_ticklabels("not an ax obj", which="x", rotation=10.5)
@pytest.mark.filterwarnings('ignore::UserWarning')
def test_align_ticklabels():
"""Test setting tick label alignments."""
_, ax = yap.singleplot()
yap.align_ticklabels(ax, which="x", horizontal=None, vertical="center")
yap.align_ticklabels(ax, which="y", horizontal=None, vertical="top")
yap.align_ticklabels(ax, which="x", horizontal="right", vertical=None)
yap.align_ticklabels(ax, which="y", horizontal="left", vertical=None)
plt.close()
@pytest.mark.filterwarnings('ignore::UserWarning')
def test_align_ticklabels_pathological():
"""Pathological test for setting tick label alignments."""
_, ax = yap.singleplot()
with pytest.raises(ValueError):
yap.align_ticklabels(ax,
which="aaaaaaaaaaaaaaaa",
horizontal=None,
vertical="center")
plt.close()
with pytest.raises(ValueError):
yap.align_ticklabels("not an ax obj",
which="x",
horizontal=None,
vertical="center")