Skip to content

Commit 0adfe57

Browse files
committed
reorganize tests
1 parent 66e2a87 commit 0adfe57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+435
-371
lines changed

test/test_hashes.py renamed to test/helpers.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
# -*- coding: utf-8 -*-
22
#
33
import matplotlib2tikz
4-
import testfunctions
54

65
import os
76
import tempfile
8-
from importlib import import_module
9-
import pytest
107
import subprocess
118
from PIL import Image
129
import imagehash
1310
from matplotlib import pyplot as plt
1411

1512

16-
@pytest.mark.parametrize('name', testfunctions.__all__)
17-
def test_hash(name):
18-
test = import_module('testfunctions.' + name)
19-
# import the test
20-
fig = test.plot()
13+
def assert_phash(fig, reference_phash):
2114
# convert to tikz file
22-
_, tmp_base = tempfile.mkstemp(prefix=name)
15+
_, tmp_base = tempfile.mkstemp()
2316
tikz_file = tmp_base + '_tikz.tex'
2417
matplotlib2tikz.save(
2518
tikz_file,
@@ -91,12 +84,13 @@ def test_hash(name):
9184
# compute the phash of the PNG
9285
phash = imagehash.phash(Image.open(png_file)).__str__()
9386

94-
if test.phash != phash:
87+
if reference_phash != phash:
9588
# Compute the Hamming distance between the two 64-bit numbers
96-
hamming_dist = bin(int(phash, 16) ^ int(test.phash, 16)).count('1')
89+
hamming_dist = \
90+
bin(int(phash, 16) ^ int(reference_phash, 16)).count('1')
9791
print('Output file: %s' % png_file)
9892
print('computed pHash: %s' % phash)
99-
print('reference pHash: %s' % test.phash)
93+
print('reference pHash: %s' % reference_phash)
10094
print(
10195
'Hamming distance: %s (out of %s)' %
10296
(hamming_dist, 4 * len(phash))
@@ -136,6 +130,6 @@ def test_hash(name):
136130
)
137131
print('Uploaded output PNG file to %s' % out.decode('utf-8'))
138132

139-
assert test.phash == phash
133+
assert reference_phash == phash
140134

141135
return
File renamed without changes.
File renamed without changes.

test/testfunctions/annotate.py renamed to test/test_annotate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# -*- coding: utf-8 -*-
22
#
3-
desc = 'Annotations'
4-
# phash = 'ab8a78a1549654fe'
5-
phash = 'ab8a79a1549654be'
3+
from helpers import assert_phash
64

5+
import matplotlib.pyplot as plt
6+
import numpy as np
77

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

12-
fig = pp.figure(1, figsize=(8, 5))
9+
def plot():
10+
fig = plt.figure(1, figsize=(8, 5))
1311
ax = fig.add_subplot(
1412
111,
1513
autoscale_on=False,
@@ -36,3 +34,7 @@ def plot():
3634
arrowprops=dict(arrowstyle='->')
3735
)
3836
return fig
37+
38+
39+
def test():
40+
assert_phash(plot(), 'ab8a79a1549654be')

test/testfunctions/barchart.py renamed to test/test_barchart.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
""" Bar Chart test
2+
'''Bar Chart test
33
44
This tests plots a simple bar chart. Bar charts are plotted as
55
rectangle patches witch are difficult to tell from other rectangle
66
patches that should not be plotted in PGFPlots (e.g. axis, legend)
7-
8-
"""
9-
desc = 'Bar Chart'
10-
phash = '5f09a9e6b172874a'
7+
'''
8+
from helpers import assert_phash
119

1210

1311
def plot():
@@ -30,3 +28,6 @@ def plot():
3028

3129
return fig
3230

31+
32+
def test():
33+
assert_phash(plot(), '5f09a9e6b172874a')

test/testfunctions/barchart_errorbars.py renamed to test/test_barchart_errorbars.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
at the correct z-order to be sucessful.
66
77
"""
8-
desc = 'Bar Chart With Errorbars'
9-
phash = '5f09a9e6b1728746'
8+
from helpers import assert_phash
109

1110

1211
def plot():
@@ -34,3 +33,6 @@ def plot():
3433

3534
return fig
3635

36+
37+
def test():
38+
assert_phash(plot(), '5f09a9e6b1728746')
File renamed without changes.

test/testfunctions/basic_sin.py renamed to test/test_basic_sin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
desc = 'Simple $\sin$ plot with some labels'
4-
# phash = '5f34e1ce21c3e5c1'
5-
phash = '1f36e5c621c1e7c1'
3+
from helpers import assert_phash
64

75

86
def plot():
@@ -23,3 +21,7 @@ def plot():
2321
plt.title('Simple plot $\\frac{\\alpha}{2}$')
2422
plt.grid(True)
2523
return fig
24+
25+
26+
def test():
27+
assert_phash(plot(), '1f36e5ce21c1e5c1')

test/test_boxplot.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
''' Box Plot test
3+
4+
This test plots a box plot with three data series. The causes an empty Line2D
5+
to be plotted. Without care, this can turn into an empty table in PGFPlot
6+
which crashes latex (due to it treating an empty table as a table with
7+
external data in the file '' or '.tex')
8+
See: https://github.com/nschloe/matplotlib2tikz/pull/134
9+
'''
10+
import helpers
11+
12+
13+
def plot():
14+
import matplotlib.pyplot as plt
15+
16+
# plot data
17+
fig = plt.figure()
18+
ax = fig.add_subplot(111)
19+
20+
data = [
21+
[
22+
0.8792419963142024, 0.8842648555256405, 0.8830545971510088,
23+
0.8831310510125482, 0.8839926059865629, 0.8795815040451961,
24+
0.8780455489941472, 0.8785436398314896, 0.8830947020953477,
25+
0.8853267660041949, 0.8888678711018956, 0.8852975957910832,
26+
0.8806832729996307, 0.8757157004574541, 0.8767001155960863,
27+
0.8840806038864472, 0.8817619814119265, 0.8888364252374024,
28+
0.8812448127688732, 0.8831027782255365
29+
], [
30+
0.8977874209274417, 0.8941751386130553, 0.8896779411432865,
31+
0.8971274869048325, 0.8974081692527065, 0.8942767272739647,
32+
0.8875248054826029, 0.8777267389916926, 0.8950411839136605,
33+
0.8927553406630346, 0.8950822278376636, 0.8987940094730611,
34+
0.8921713177345106, 0.8875512496817447, 0.8897284821652239,
35+
0.8910385725900226, 0.8879321741542129, 0.889056167587369,
36+
0.884905350828982, 0.89214934207348
37+
], [
38+
0.8841888415170959, 0.8922931655807687, 0.8896153674950393,
39+
0.8875992162118492, 0.890776178375901, 0.8889109386518265,
40+
0.8879119743598638, 0.8912870099488378, 0.8981046527087161,
41+
0.8920725720963792, 0.8841683225315845, 0.8857539590587772,
42+
0.8945156112818913, 0.8894879283167035, 0.8912651966639861,
43+
0.8929190818922158, 0.8943297597492411, 0.8888594626359189,
44+
0.8912494597675972, 0.8917524004164856
45+
]]
46+
47+
ax.boxplot(data)
48+
49+
return fig
50+
51+
52+
def test():
53+
helpers.assert_phash(plot(), '6be3e6b95e8000de')

test/testfunctions/colorbars.py renamed to test/test_colorbars.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# -*- coding: utf-8 -*-
22
#
3-
desc = 'Color bars'
4-
phash = ''
53

64

75
def plot():
86
import matplotlib as mpl
97
from matplotlib import pyplot as pp
10-
from matplotlib import style
11-
import numpy as np
128
# Make a figure and axes with dimensions as desired.
139
fig, ax = pp.subplots(3)
1410

@@ -85,3 +81,7 @@ def plot():
8581
cb3.set_label('Custom extension lengths, some other units')
8682

8783
return fig
84+
85+
86+
# def test():
87+
# helpers.assert_phash(plot(), '')

0 commit comments

Comments
 (0)