summaryrefslogtreecommitdiff
path: root/gerber/tests/test_cairo_backend.py
diff options
context:
space:
mode:
authorGarret Fick <garret@ficksworkshop.com>2016-07-24 17:08:47 +0800
committerGarret Fick <garret@ficksworkshop.com>2016-07-24 17:08:47 +0800
commit7cd6acf12670f3773113f67ed2acb35cb21c32a0 (patch)
treece2d79376375b8c7b4ee8c0f519f23d3f3fc1db9 /gerber/tests/test_cairo_backend.py
parentcd4614f9973eb9f4ce858b3864573367614f54b6 (diff)
downloadgerbonara-7cd6acf12670f3773113f67ed2acb35cb21c32a0.tar.gz
gerbonara-7cd6acf12670f3773113f67ed2acb35cb21c32a0.tar.bz2
gerbonara-7cd6acf12670f3773113f67ed2acb35cb21c32a0.zip
Add many render tests based on the Umaco gerger specification. Fix multiple rendering bugs, especially related to holes in flashed apertures
Diffstat (limited to 'gerber/tests/test_cairo_backend.py')
-rw-r--r--gerber/tests/test_cairo_backend.py128
1 files changed, 122 insertions, 6 deletions
diff --git a/gerber/tests/test_cairo_backend.py b/gerber/tests/test_cairo_backend.py
index e298439..38cffba 100644
--- a/gerber/tests/test_cairo_backend.py
+++ b/gerber/tests/test_cairo_backend.py
@@ -8,16 +8,125 @@ import os
from ..render.cairo_backend import GerberCairoContext
from ..rs274x import read, GerberFile
from .tests import *
+from nose.tools import assert_tuple_equal
+def test_render_two_boxes():
+ """Umaco exapmle of two boxes"""
+ _test_render('resources/example_two_square_boxes.gbr', 'golden/example_two_square_boxes.png')
-TWO_BOXES_FILE = os.path.join(os.path.dirname(__file__),
- 'resources/example_two_square_boxes.gbr')
-TWO_BOXES_EXPECTED = os.path.join(os.path.dirname(__file__),
- 'golden/example_two_square_boxes.png')
-def test_render_polygon():
+def test_render_single_quadrant():
+ """Umaco exapmle of a single quadrant arc"""
+ _test_render('resources/example_single_quadrant.gbr', 'golden/example_single_quadrant.png')
+
+
+def test_render_simple_contour():
+ """Umaco exapmle of a simple arrow-shaped contour"""
+ gerber = _test_render('resources/example_simple_contour.gbr', 'golden/example_simple_contour.png')
+
+ # Check the resulting dimensions
+ assert_tuple_equal(((2.0, 11.0), (1.0, 9.0)), gerber.bounding_box)
+
+
+def test_render_single_contour_1():
+ """Umaco example of a single contour
+
+ The resulting image for this test is used by other tests because they must generate the same output."""
+ _test_render('resources/example_single_contour_1.gbr', 'golden/example_single_contour.png')
+
+
+def test_render_single_contour_2():
+ """Umaco exapmle of a single contour, alternate contour end order
+
+ The resulting image for this test is used by other tests because they must generate the same output."""
+ _test_render('resources/example_single_contour_2.gbr', 'golden/example_single_contour.png')
+
+
+def test_render_single_contour_3():
+ """Umaco exapmle of a single contour with extra line"""
+ _test_render('resources/example_single_contour_3.gbr', 'golden/example_single_contour_3.png')
+
+
+def test_render_not_overlapping_contour():
+ """Umaco example of D02 staring a second contour"""
+ _test_render('resources/example_not_overlapping_contour.gbr', 'golden/example_not_overlapping_contour.png')
+
+
+def test_render_not_overlapping_touching():
+ """Umaco example of D02 staring a second contour"""
+ _test_render('resources/example_not_overlapping_touching.gbr', 'golden/example_not_overlapping_touching.png')
+
+
+def test_render_overlapping_touching():
+ """Umaco example of D02 staring a second contour"""
+ _test_render('resources/example_overlapping_touching.gbr', 'golden/example_overlapping_touching.png')
+
+
+def test_render_overlapping_contour():
+ """Umaco example of D02 staring a second contour"""
+ _test_render('resources/example_overlapping_contour.gbr', 'golden/example_overlapping_contour.png')
+
+
+def _DISABLED_test_render_level_holes():
+ """Umaco example of using multiple levels to create multiple holes"""
+
+ # TODO This is clearly rendering wrong. I'm temporarily checking this in because there are more
+ # rendering fixes in the related repository that may resolve these.
+ _test_render('resources/example_level_holes.gbr', 'golden/example_overlapping_contour.png')
+
+
+def _DISABLED_test_render_cutin():
+ """Umaco example of using a cutin"""
+
+ # TODO This is clearly rendering wrong.
+ _test_render('resources/example_cutin.gbr', 'golden/example_cutin.png')
+
+
+def test_render_fully_coincident():
+ """Umaco example of coincident lines rendering two contours"""
+
+ _test_render('resources/example_fully_coincident.gbr', 'golden/example_fully_coincident.png')
+
+
+def test_render_coincident_hole():
+ """Umaco example of coincident lines rendering a hole in the contour"""
+
+ _test_render('resources/example_coincident_hole.gbr', 'golden/example_coincident_hole.png')
+
+
+def test_render_cutin_multiple():
+ """Umaco example of a region with multiple cutins"""
+
+ _test_render('resources/example_cutin_multiple.gbr', 'golden/example_cutin_multiple.png')
+
+
+def test_flash_circle():
+ """Umaco example a simple circular flash with and without a hole"""
+
+ _test_render('resources/example_flash_circle.gbr', 'golden/example_flash_circle.png')
+
+
+def test_flash_rectangle():
+ """Umaco example a simple rectangular flash with and without a hole"""
+
+ _test_render('resources/example_flash_rectangle.gbr', 'golden/example_flash_rectangle.png')
+
+
+def test_flash_obround():
+ """Umaco example a simple obround flash with and without a hole"""
+
+ _test_render('resources/example_flash_obround.gbr', 'golden/example_flash_obround.png')
+
+
+def test_flash_polygon():
+ """Umaco example a simple polygon flash with and without a hole"""
+
+ _test_render('resources/example_flash_polygon.gbr', 'golden/example_flash_polygon.png', 'golden/example_flash_polygon.png')
+
+def _resolve_path(path):
+ return os.path.join(os.path.dirname(__file__),
+ path)
- _test_render(TWO_BOXES_FILE, TWO_BOXES_EXPECTED)
def _test_render(gerber_path, png_expected_path, create_output_path = None):
"""Render the gerber file and compare to the expected PNG output.
@@ -33,6 +142,11 @@ def _test_render(gerber_path, png_expected_path, create_output_path = None):
This is primarily to help with
"""
+ gerber_path = _resolve_path(gerber_path)
+ png_expected_path = _resolve_path(png_expected_path)
+ if create_output_path:
+ create_output_path = _resolve_path(create_output_path)
+
gerber = read(gerber_path)
# Create PNG image to the memory stream
@@ -56,3 +170,5 @@ def _test_render(gerber_path, png_expected_path, create_output_path = None):
expected_bytes = expected_file.read()
assert_equal(expected_bytes, actual_bytes)
+
+ return gerber