Skip to content

Commit 90480fb

Browse files
authored
Merge pull request #222 from nschloe/test-fixes
Test fixes
2 parents 66da89d + 3b496c5 commit 90480fb

17 files changed

+55
-29
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
- run: texhash
4949
# install
5050
- run: pip3 install -r test_requirements.txt
51+
# Install very specific versions of the dependencies; the build is too
52+
# fragile otherwise.
53+
- run: pip3 install matplotlib==2.1.0
5154
- run: pip3 install .
5255
# lint
5356
- run: pylint setup.py

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2010-2017 Nico Schlömer
3+
Copyright (c) 2010-2018 Nico Schlömer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# matplotlib2tikz
22

33
[![CircleCI](https://img.shields.io/circleci/project/github/nschloe/matplotlib2tikz/master.svg)](https://circleci.com/gh/nschloe/matplotlib2tikz/tree/master)
4-
[![codecov](https://codecov.io/gh/nschloe/matplotlib2tikz/branch/master/graph/badge.svg)](https://codecov.io/gh/nschloe/matplotlib2tikz)
4+
[![codecov](https://img.shields.io/codecov/c/github/nschloe/matplotlib2tikz.svg)](https://codecov.io/gh/nschloe/matplotlib2tikz)
55
[![Documentation Status](https://readthedocs.org/projects/matplotlib2tikz/badge/?version=latest)](https://readthedocs.org/projects/matplotlib2tikz/?badge=latest)
66
[![PyPi Version](https://img.shields.io/pypi/v/matplotlib2tikz.svg)](https://pypi.python.org/pypi/matplotlib2tikz)
7-
[![awesome](https://img.shields.io/badge/awesome-yes-brightgreen.svg)](https://img.shields.io/badge/awesome-yes-brightgreen.svg)
8-
[![GitHub stars](https://img.shields.io/github/stars/nschloe/matplotlib2tikz.svg?style=social&label=Stars&maxAge=2592000)](https://github.com/nschloe/matplotlib2tikz)
7+
[![awesome](https://img.shields.io/badge/awesome-yes-brightgreen.svg)](https://github.com/nschloe/matplotlib2tikz)
8+
[![GitHub stars](https://img.shields.io/github/stars/nschloe/matplotlib2tikz.svg?style=social&label=Stars)](https://github.com/nschloe/matplotlib2tikz)
99

1010
This is matplotlib2tikz, a Python tool for converting matplotlib figures into
1111
[PGFPlots](https://www.ctan.org/pkg/pgfplots)

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
# General information about the project.
5353
project = u'matplotlib2tikz'
54-
copyright = u'2010-2017, Nico Schlömer'
54+
copyright = u'2010-2018, Nico Schlömer'
5555

5656
# The version info for the project you're documenting, acts as replacement for
5757
# |version| and |release|, also used in various other places throughout the

matplotlib2tikz/__about__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
__author__ = u'Nico Schlömer'
44
__email__ = '[email protected]'
5-
__copyright__ = 'Copyright (c) 2010-2017, %s <%s>' % (__author__, __email__)
5+
__copyright__ = \
6+
u'Copyright (c) 2010-2018, {} <{}>'.format(__author__, __email__)
67
__credits__ = []
78
__license__ = 'License :: OSI Approved :: MIT License'
89
__version__ = '0.6.14'

test/helpers.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
#
33
from __future__ import print_function
44

5+
import math
56
import os
7+
import re
68
import shutil
79
import subprocess
810
import tempfile
911

10-
import matplotlib2tikz
11-
1212
import imagehash
1313
import matplotlib
1414
import matplotlib.image as mpimg
1515
import matplotlib.pyplot as plt
1616
from PIL import Image
1717

18+
import matplotlib2tikz
19+
1820

1921
class Phash(object):
2022
def __init__(self, fig):
@@ -75,11 +77,31 @@ def __init__(self, fig):
7577

7678
pdf_file = tmp_base + '.pdf'
7779

80+
# PIL can only read images with up to 89478485 pixels (to prevent
81+
# decompression bomb DOS attacks). Make sure the resulting image will
82+
# be smaller.
83+
pdfinfo_out = subprocess.check_output(
84+
['pdfinfo', pdf_file],
85+
stderr=subprocess.STDOUT
86+
).decode('utf-8')
87+
# Extract page size
88+
# Page size: 195.106 x 156.239 pts
89+
m = re.search(
90+
'Page size: *([0-9]+\\.[0-9]+) x ([0-9]+\\.[0-9]+) pts',
91+
pdfinfo_out
92+
)
93+
# get dims in inches
94+
dims = [float(m.group(1)) / 72, float(m.group(2)) / 72]
95+
assert dims is not None
96+
max_num_pixels = 89e6
97+
max_dpi = math.sqrt(max_num_pixels / dims[0] / dims[1])
98+
dpi = min(2400, max_dpi)
99+
78100
# Convert PDF to PNG.
79101
# Use a high resolution here to cover small changes.
80102
ptp_out = subprocess.check_output(
81103
[
82-
'pdftoppm', '-r', '2400', '-png',
104+
'pdftoppm', '-r', str(dpi), '-png',
83105
pdf_file, tmp_base
84106
],
85107
stderr=subprocess.STDOUT

test/test_annotate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from helpers import Phash
4-
53
import matplotlib.pyplot as plt
64
import numpy as np
75

6+
from helpers import Phash
7+
88

99
def plot():
1010
fig = plt.figure(1, figsize=(8, 5))

test/test_fancybox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Taken from http://matplotlib.org/examples/pylab_examples/fancybox_demo.html
4-
import helpers
5-
64
import matplotlib.pyplot as plt
75
import matplotlib.transforms as mtransforms
86
from matplotlib.patches import FancyBboxPatch
97

8+
import helpers
9+
1010

1111
# Bbox object around which the fancy box will be drawn.
1212
bb = mtransforms.Bbox([[0.3, 0.4], [0.7, 0.6]])

test/test_image_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
#
3-
import helpers
4-
53
import matplotlib.pyplot as plt
64
import pytest
75

6+
import helpers
7+
88
# the picture 'lena.png' with origin='lower' is flipped upside-down.
99
# So it has to be upside-down in the pdf-file as well.
1010

test/test_legends2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ def plot():
3232

3333
def test():
3434
phash = helpers.Phash(plot())
35-
assert phash.phash == '7f447a5266d4812f', phash.get_details()
35+
assert phash.phash == '7f467a5262d4812f', phash.get_details()
3636
return

0 commit comments

Comments
 (0)