Skip to content

Commit 0efe258

Browse files
committed
Remove deprecation warnings with pytest 3
1 parent aa8baad commit 0efe258

File tree

6 files changed

+44
-60
lines changed

6 files changed

+44
-60
lines changed

cairosvg/path.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def path(surface, node):
166166

167167
if last_letter in (None, 'm', 'M', 'z', 'Z'):
168168
first_path_point = None
169-
if letter not in (None, 'm', 'M', 'z', 'Z') and first_path_point is None:
169+
if letter not in (None, 'm', 'M', 'z', 'Z') and (
170+
first_path_point is None):
170171
first_path_point = current_point
171172

172173
if letter in 'aA':

cairosvg/surface.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def convert(cls, bytestring=None, **kwargs):
134134
kwargs['bytestring'] = bytestring
135135
tree = Tree(**kwargs)
136136
output = write_to or io.BytesIO()
137-
cls(tree, output, dpi, None, parent_width, parent_height, scale).finish()
137+
instance = cls(
138+
tree, output, dpi, None, parent_width, parent_height, scale)
139+
instance.finish()
138140
if write_to is None:
139141
return output.getvalue()
140142

cairosvg/test_api.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import tempfile
2929

3030
import cairocffi as cairo
31+
import pytest
3132

3233
from . import SURFACES, __version__, main, parser, surface, svg2pdf, svg2png
3334

@@ -49,19 +50,11 @@
4950
'''
5051

5152

52-
def test_formats():
53+
@pytest.mark.parametrize('format_name', MAGIC_NUMBERS)
54+
def test_formats(format_name):
5355
"""Convert to a given format and test that output looks right."""
54-
for format_name in MAGIC_NUMBERS:
55-
# Use a default parameter value to bind to the current value,
56-
# not to the variabl as a closure would do.
57-
def test(format_name=format_name):
58-
"""Test the generation of ``format_name`` images."""
59-
content = SURFACES[format_name].convert(SVG_SAMPLE)
60-
assert content.startswith(MAGIC_NUMBERS[format_name])
61-
test.description = (
62-
'Test that the output from svg2{} looks like {}'.format(
63-
format_name.lower(), format_name))
64-
yield test
56+
content = SURFACES[format_name].convert(SVG_SAMPLE)
57+
assert content.startswith(MAGIC_NUMBERS[format_name])
6558

6659

6760
def read_file(filename):

pytest.ini

-5
This file was deleted.

setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ test = pytest
33

44
[bdist_wheel]
55
python-tag = py3
6+
7+
[tool:pytest]
8+
addopts = --flake8 --isort --cov --ignore=test/cairosvg_reference
9+
norecursedirs = dist .cache .git build *.egg-info .eggs venv cairosvg_reference

test/test_non_regression.py

+30-41
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,36 @@
2525
import os
2626
import tempfile
2727

28-
from . import FILES, cairosvg, reference_cairosvg
29-
30-
31-
def generate_function(description):
32-
"""Return a testing function with the given ``description``."""
33-
def check_image(svg_filename):
34-
"""Check that the pixels match between ``svg`` and ``png``."""
35-
test_png = tempfile.NamedTemporaryFile(
36-
prefix='test-', suffix='.png', delete=False)
37-
test_surface = cairosvg.surface.PNGSurface(
38-
cairosvg.parser.Tree(url=svg_filename, unsafe=True), test_png,
39-
dpi=72)
40-
test_pixels = test_surface.cairo.get_data()[:]
41-
42-
ref_png = tempfile.NamedTemporaryFile(
43-
prefix='reference-', suffix='.png', delete=False)
44-
ref_surface = reference_cairosvg.surface.PNGSurface(
45-
reference_cairosvg.parser.Tree(url=svg_filename, unsafe=True),
46-
ref_png, dpi=72)
47-
ref_pixels = ref_surface.cairo.get_data()[:]
28+
import pytest
4829

49-
if test_pixels == ref_pixels:
50-
# Test is passing
51-
os.remove(ref_png.name)
52-
os.remove(test_png.name)
53-
else: # pragma: no cover
54-
ref_surface.finish()
55-
test_surface.finish()
56-
57-
raise AssertionError(
58-
'Images are different: {} {}'.format(
59-
ref_png.name, test_png.name))
60-
61-
check_image.description = description
62-
return check_image
30+
from . import FILES, cairosvg, reference_cairosvg
6331

6432

65-
def test_images():
66-
"""Yield the functions testing an image."""
67-
for svg_filename in FILES:
68-
yield (
69-
generate_function(
70-
'Test the {} image'.format(os.path.basename(svg_filename))),
71-
svg_filename)
33+
@pytest.mark.parametrize('svg_filename', FILES)
34+
def test_image(svg_filename):
35+
"""Check that the pixels match between ``svg`` and ``png``."""
36+
test_png = tempfile.NamedTemporaryFile(
37+
prefix='test-', suffix='.png', delete=False)
38+
test_surface = cairosvg.surface.PNGSurface(
39+
cairosvg.parser.Tree(url=svg_filename, unsafe=True), test_png,
40+
dpi=72)
41+
test_pixels = test_surface.cairo.get_data()[:]
42+
43+
ref_png = tempfile.NamedTemporaryFile(
44+
prefix='reference-', suffix='.png', delete=False)
45+
ref_surface = reference_cairosvg.surface.PNGSurface(
46+
reference_cairosvg.parser.Tree(url=svg_filename, unsafe=True),
47+
ref_png, dpi=72)
48+
ref_pixels = ref_surface.cairo.get_data()[:]
49+
50+
if test_pixels == ref_pixels:
51+
# Test is passing
52+
os.remove(ref_png.name)
53+
os.remove(test_png.name)
54+
else: # pragma: no cover
55+
ref_surface.finish()
56+
test_surface.finish()
57+
58+
raise AssertionError(
59+
'Images are different: {} {}'.format(
60+
ref_png.name, test_png.name))

0 commit comments

Comments
 (0)