Skip to content

Commit f66bd9d

Browse files
authored
Merge pull request #170 from nschloe/text-test-coverage
Text test coverage
2 parents 016ed87 + 6aee642 commit f66bd9d

File tree

6 files changed

+75
-125
lines changed

6 files changed

+75
-125
lines changed

test/helpers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#
33
import matplotlib2tikz
44

5+
import imagehash
6+
import matplotlib
7+
import matplotlib.pyplot as plt
58
import os
9+
from PIL import Image
610
import shutil
7-
import tempfile
811
import subprocess
9-
from PIL import Image
10-
import imagehash
11-
from matplotlib import pyplot as plt
12+
import tempfile
1213

1314

1415
def compute_phash(fig):
@@ -145,3 +146,16 @@ def assert_phash(fig, reference_phash):
145146
assert reference_phash == phash
146147

147148
return
149+
150+
151+
def print_tree(obj, indent=''):
152+
'''Recursively prints the tree structure of the matplotlib object.
153+
'''
154+
if isinstance(obj, matplotlib.text.Text):
155+
print(indent, type(obj).__name__, '("%s")' % obj.get_text())
156+
else:
157+
print(indent, type(obj).__name__)
158+
159+
for child in obj.get_children():
160+
print_tree(child, indent + ' ')
161+
return

test/show

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/test_fancybox.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,10 @@ def plot():
193193

194194
def test():
195195
helpers.assert_phash(plot(), '9d2327dc23cdd81a')
196+
197+
198+
if __name__ == '__main__':
199+
plot()
200+
plt.show()
201+
# phash, _, _, _, _, _, _ = helpers.compute_phash(plot2())
202+
# print(phash)
Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
# -*- coding: utf-8 -*-
22
#
3-
desc = 'Regular plot with overlay text'
4-
phash = '370da93449d3f64c'
3+
import helpers
54

5+
import matplotlib.pyplot as plt
6+
import numpy
67

7-
def plot():
8-
from matplotlib import pyplot as pp
9-
import numpy as np
108

11-
fig = pp.figure()
9+
def plot():
10+
fig = plt.figure()
1211

13-
xxx = np.linspace(0, 5)
12+
xxx = numpy.linspace(0, 5)
1413
yyy = xxx**2
15-
pp.text(1, 5, 'test1', size=50, rotation=30.,
14+
plt.text(
15+
1, 5, 'test1', size=50, rotation=30.,
1616
ha='center', va='bottom', color='r', style='italic',
1717
weight='light',
18-
bbox=dict(boxstyle='round, pad=0.2',
19-
ec=(1., 0.5, 0.5),
20-
fc=(1., 0.8, 0.8),
21-
ls='dashdot'
22-
)
18+
bbox=dict(
19+
boxstyle='round, pad=0.2',
20+
ec=(1., 0.5, 0.5),
21+
fc=(1., 0.8, 0.8),
22+
ls='dashdot'
23+
)
2324
)
24-
pp.text(3, 6, 'test2', size=50, rotation=-30.,
25+
plt.text(
26+
3, 6, 'test2', size=50, rotation=-30.,
2527
ha='center', va='center', color='b', weight='bold',
26-
bbox=dict(boxstyle='square',
27-
ec=(1., 0.5, 0.5),
28-
fc=(1., 0.8, 0.8),
29-
)
28+
bbox=dict(
29+
boxstyle='square',
30+
ec=(1., 0.5, 0.5),
31+
fc=(1., 0.8, 0.8),
32+
)
3033
)
31-
pp.text(4, 8, 'test3', size=20, rotation=90.0,
34+
plt.text(
35+
4, 8, 'test3', size=20, rotation=90.0,
3236
ha='center', va='center', color='b', weight='demi',
3337
bbox=dict(
3438
boxstyle='rarrow',
@@ -37,7 +41,8 @@ def plot():
3741
fc=(1., 0.8, 0.8),
3842
)
3943
)
40-
pp.text(4, 16, 'test4', size=20, rotation=90.0,
44+
plt.text(
45+
4, 16, 'test4', size=20, rotation=90.0,
4146
ha='center', va='center', color='b', weight='heavy',
4247
bbox=dict(
4348
boxstyle='larrow',
@@ -46,39 +51,54 @@ def plot():
4651
fc=(1., 0.8, 0.8),
4752
)
4853
)
49-
pp.text(2, 18, 'test5', size=20,
54+
plt.text(
55+
2, 18, 'test5', size=20,
5056
ha='center', va='center', color='b',
5157
bbox=dict(
5258
boxstyle='darrow',
5359
ec=(1., 0.5, 0.5),
5460
fc=(1., 0.8, 0.8),
5561
)
5662
)
57-
pp.text(1, 20, 'test6', size=20,
63+
plt.text(
64+
1, 20, 'test6', size=20,
5865
ha='center', va='center', color='b',
5966
bbox=dict(
6067
boxstyle='circle',
6168
ec=(1., 0.5, 0.5),
6269
fc=(1., 0.8, 0.8),
6370
)
6471
)
65-
pp.text(3, 23, 'test7', size=20,
72+
plt.text(
73+
3, 23, 'test7', size=20,
6674
ha='center', va='center', color='b',
6775
bbox=dict(
6876
boxstyle='roundtooth',
6977
ec=(1., 0.5, 0.5),
7078
fc=(1., 0.8, 0.8),
7179
)
7280
)
73-
pp.text(3, 20, 'test8', size=20,
81+
plt.text(
82+
3, 20, 'test8', size=20,
7483
ha='center', va='center', color='b',
7584
bbox=dict(
7685
boxstyle='sawtooth',
7786
ec=(1., 0.5, 0.5),
7887
fc=(1., 0.8, 0.8),
7988
)
8089
)
81-
pp.plot(xxx, yyy, label='a graph')
82-
pp.legend()
90+
plt.plot(xxx, yyy, label='a graph')
91+
plt.legend()
8392

8493
return fig
94+
95+
96+
def test():
97+
helpers.assert_phash(plot(), '370da93449d3f64c')
98+
99+
100+
if __name__ == '__main__':
101+
plot()
102+
plt.show()
103+
# phash, _, _, _, _, _, _ = helpers.compute_phash(plot2())
104+
# print(phash)

test/test_viridis.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ def plot():
2020

2121
def test():
2222
helpers.assert_phash(plot(), 'fd7e03fc03bc0381')
23+
24+
25+
if __name__ == '__main__':
26+
helpers.print_tree(plot())

test/tree

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)