summaryrefslogtreecommitdiff
path: root/gerber/tests/test_cairo_backend.py
diff options
context:
space:
mode:
authorJan Margeta <jmargeta@gmail.com>2017-04-15 14:53:08 +0200
committerJan Margeta <jmargeta@gmail.com>2017-04-15 15:29:58 +0200
commit787399992662f1963cfbd2dd9e9b9002b6b131e4 (patch)
tree71529524b19cc0edc5b31222fa74a799f977b56d /gerber/tests/test_cairo_backend.py
parentdd0abbf3072b59c8e5ec437a85ccaf01272d8043 (diff)
downloadgerbonara-787399992662f1963cfbd2dd9e9b9002b6b131e4.tar.gz
gerbonara-787399992662f1963cfbd2dd9e9b9002b6b131e4.tar.bz2
gerbonara-787399992662f1963cfbd2dd9e9b9002b6b131e4.zip
Fix Cairo backend for svg saving and Python 3
Diffstat (limited to 'gerber/tests/test_cairo_backend.py')
-rw-r--r--gerber/tests/test_cairo_backend.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/gerber/tests/test_cairo_backend.py b/gerber/tests/test_cairo_backend.py
index 9195b93..d5ce4ed 100644
--- a/gerber/tests/test_cairo_backend.py
+++ b/gerber/tests/test_cairo_backend.py
@@ -3,7 +3,8 @@
# Author: Garret Fick <garret@ficksworkshop.com>
import os
-
+import shutil
+import tempfile
from ..render.cairo_backend import GerberCairoContext
from ..rs274x import read
@@ -136,6 +137,11 @@ def _DISABLED_test_render_am_exposure_modifier():
_test_render('resources/example_am_exposure_modifier.gbr', 'golden/example_am_exposure_modifier.png')
+def test_render_svg_simple_contour():
+ """Example of rendering to an SVG file"""
+ _test_simple_render_svg('resources/example_simple_contour.gbr')
+
+
def _resolve_path(path):
return os.path.join(os.path.dirname(__file__),
path)
@@ -187,3 +193,35 @@ def _test_render(gerber_path, png_expected_path, create_output_path = None):
assert_true(equal)
return gerber
+
+
+def _test_simple_render_svg(gerber_path):
+ """Render the gerber file as SVG
+
+ Note: verifies only the header, not the full content.
+
+ Parameters
+ ----------
+ gerber_path : string
+ Path to Gerber file to open
+ """
+
+ gerber_path = _resolve_path(gerber_path)
+ gerber = read(gerber_path)
+
+ # Create SVG image to the memory stream
+ ctx = GerberCairoContext()
+ gerber.render(ctx)
+
+ temp_dir = tempfile.mkdtemp()
+ svg_temp_path = os.path.join(temp_dir, 'output.svg')
+
+ assert_false(os.path.exists(svg_temp_path))
+ ctx.dump(svg_temp_path)
+ assert_true(os.path.exists(svg_temp_path))
+
+ with open(svg_temp_path, 'r') as expected_file:
+ expected_bytes = expected_file.read()
+ assert_equal(expected_bytes[:38], '<?xml version="1.0" encoding="UTF-8"?>')
+
+ shutil.rmtree(temp_dir)