Skip to content

Commit 536f272

Browse files
authored
Merge pull request #161 from nschloe/version-bump
Version bump
2 parents 26db3ca + 7c8da9c commit 536f272

Some content is hidden

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

46 files changed

+502
-426
lines changed

matplotlib2tikz/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
__copyright__ = 'Copyright (c) 2010-2017, %s <%s>' % (__author__, __email__)
66
__credits__ = []
77
__license__ = 'License :: OSI Approved :: MIT License'
8-
__version__ = '0.6.5'
8+
__version__ = '0.6.6'
99
__maintainer__ = u'Nico Schlömer'
1010
__status__ = 'Development Status :: 5 - Production/Stable'

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

Lines changed: 17 additions & 15 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 compute_phash(fig):
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,
@@ -68,7 +61,7 @@ def test_hash(name):
6861
except subprocess.CalledProcessError as e:
6962
print('Command output:')
7063
print('=' * 70)
71-
print(repr(e.output))
64+
print(e.output)
7265
print('=' * 70)
7366
if 'DISPLAY' not in os.environ:
7467
cmd = ['curl', '-sT', tikz_file, 'chunk.io']
@@ -89,14 +82,23 @@ def test_hash(name):
8982
png_file = tmp_base + '-1.png'
9083

9184
# compute the phash of the PNG
92-
phash = imagehash.phash(Image.open(png_file)).__str__()
85+
return (
86+
imagehash.phash(Image.open(png_file)).__str__(), png_file, pdf_file,
87+
tex_out, ptp_out, mpl_reference, tikz_file
88+
)
89+
90+
91+
def assert_phash(fig, reference_phash):
92+
phash, png_file, pdf_file, tex_out, ptp_out, mpl_reference, tikz_file =\
93+
compute_phash(fig)
9394

94-
if test.phash != phash:
95+
if reference_phash != phash:
9596
# Compute the Hamming distance between the two 64-bit numbers
96-
hamming_dist = bin(int(phash, 16) ^ int(test.phash, 16)).count('1')
97+
hamming_dist = \
98+
bin(int(phash, 16) ^ int(reference_phash, 16)).count('1')
9799
print('Output file: %s' % png_file)
98100
print('computed pHash: %s' % phash)
99-
print('reference pHash: %s' % test.phash)
101+
print('reference pHash: %s' % reference_phash)
100102
print(
101103
'Hamming distance: %s (out of %s)' %
102104
(hamming_dist, 4 * len(phash))
@@ -136,6 +138,6 @@ def test_hash(name):
136138
)
137139
print('Uploaded output PNG file to %s' % out.decode('utf-8'))
138140

139-
assert test.phash == phash
141+
assert reference_phash == phash
140142

141143
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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
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
4+
5+
from matplotlib import pyplot as plt
6+
from matplotlib import style
7+
import numpy as np
68

79

810
def plot():
9-
from matplotlib import pyplot as plt
10-
from matplotlib import style
11-
import numpy as np
1211
fig = plt.figure()
1312
with plt.style.context(('ggplot')):
1413
t = np.arange(0.0, 2.0, 0.1)
@@ -23,3 +22,7 @@ def plot():
2322
plt.title('Simple plot $\\frac{\\alpha}{2}$')
2423
plt.grid(True)
2524
return fig
25+
26+
27+
def test():
28+
assert_phash(plot(), '1f36e5c621c1e7c1')

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')

0 commit comments

Comments
 (0)