summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/tests
diff options
context:
space:
mode:
Diffstat (limited to 'gerbonara/gerber/tests')
-rw-r--r--gerbonara/gerber/tests/panelize/test_dxf.py2
-rw-r--r--gerbonara/gerber/tests/panelize/test_rs274x.py23
-rw-r--r--gerbonara/gerber/tests/panelize/test_utility.py15
-rw-r--r--gerbonara/gerber/tests/test_primitives.py181
-rw-r--r--gerbonara/gerber/tests/test_rs274x.py2
5 files changed, 110 insertions, 113 deletions
diff --git a/gerbonara/gerber/tests/panelize/test_dxf.py b/gerbonara/gerber/tests/panelize/test_dxf.py
index dfd59d2..39c3842 100644
--- a/gerbonara/gerber/tests/panelize/test_dxf.py
+++ b/gerbonara/gerber/tests/panelize/test_dxf.py
@@ -8,10 +8,12 @@ import tempfile
from pathlib import Path
from contextlib import contextmanager
import unittest
+
from ... import panelize
from ...utils import inch, metric
+@unittest.skip
class TestExcellon(unittest.TestCase):
@classmethod
def setUpClass(cls):
diff --git a/gerbonara/gerber/tests/panelize/test_rs274x.py b/gerbonara/gerber/tests/panelize/test_rs274x.py
index 85748a3..067717d 100644
--- a/gerbonara/gerber/tests/panelize/test_rs274x.py
+++ b/gerbonara/gerber/tests/panelize/test_rs274x.py
@@ -8,7 +8,7 @@ import tempfile
from pathlib import Path
from contextlib import contextmanager
import unittest
-from ... import panelize
+from ...rs274x import read
class TestRs274x(unittest.TestCase):
@classmethod
@@ -26,41 +26,50 @@ class TestRs274x(unittest.TestCase):
actual = tmp_out.read()
expected = (self.EXPECTSDIR / reference_fn).read_bytes()
+
+ print('==== ACTUAL ===')
+ print(actual.decode())
+ print()
+ print()
+ print('==== EXPECTED ===')
+ print(expected.decode())
+ print()
+ print()
self.assertEqual(actual, expected)
def test_save(self):
with self._check_result('RS2724x_save.gtl') as outfile:
- gerber = panelize.read(self.METRIC_FILE)
+ gerber = read(self.METRIC_FILE)
gerber.write(outfile)
def test_to_inch(self):
with self._check_result('RS2724x_to_inch.gtl') as outfile:
- gerber = panelize.read(self.METRIC_FILE)
+ gerber = read(self.METRIC_FILE)
gerber.to_inch()
gerber.format = (2,5)
gerber.write(outfile)
def test_to_metric(self):
with self._check_result('RS2724x_to_metric.gtl') as outfile:
- gerber = panelize.read(self.INCH_FILE)
+ gerber = read(self.INCH_FILE)
gerber.to_metric()
gerber.format = (3, 4)
gerber.write(outfile)
def test_offset(self):
with self._check_result('RS2724x_offset.gtl') as outfile:
- gerber = panelize.read(self.METRIC_FILE)
+ gerber = read(self.METRIC_FILE)
gerber.offset(11, 5)
gerber.write(outfile)
def test_rotate(self):
with self._check_result('RS2724x_rotate.gtl') as outfile:
- gerber = panelize.read(self.METRIC_FILE)
+ gerber = read(self.METRIC_FILE)
gerber.rotate(20, (10,10))
gerber.write(outfile)
def test_single_quadrant(self):
with self._check_result('RS2724x_single_quadrant.gtl') as outfile:
- gerber = panelize.read(self.SQ_FILE)
+ gerber = read(self.SQ_FILE)
gerber.write(outfile)
diff --git a/gerbonara/gerber/tests/panelize/test_utility.py b/gerbonara/gerber/tests/panelize/test_utility.py
index b32af8b..f632d90 100644
--- a/gerbonara/gerber/tests/panelize/test_utility.py
+++ b/gerbonara/gerber/tests/panelize/test_utility.py
@@ -9,21 +9,6 @@ from ...panelize.utility import *
from math import sqrt
class TestUtility(unittest.TestCase):
- def test_rotate(self):
- x0, y0 = (10, 0)
-
- x1, y1 = rotate(x0, y0, 60, (0, 0))
- self.assertAlmostEqual(x1, 5)
- self.assertAlmostEqual(y1, 10 * sqrt(3) / 2)
-
- x1, y1 = rotate(x0, y0, 180, (5, 0))
- self.assertAlmostEqual(x1, 0)
- self.assertAlmostEqual(y1, 0)
-
- x1, y1 = rotate(x0, y0, -90, (10, 5))
- self.assertAlmostEqual(x1, 5)
- self.assertAlmostEqual(y1, 5)
-
def test_is_equal_value(self):
a = 10.0001
b = 10.01
diff --git a/gerbonara/gerber/tests/test_primitives.py b/gerbonara/gerber/tests/test_primitives.py
index ad5b34f..d4ee653 100644
--- a/gerbonara/gerber/tests/test_primitives.py
+++ b/gerbonara/gerber/tests/test_primitives.py
@@ -49,10 +49,10 @@ def test_line_bounds():
""" Test Line primitive bounding box calculation
"""
cases = [
- ((0, 0), (1, 1), ((-1, 2), (-1, 2))),
- ((-1, -1), (1, 1), ((-2, 2), (-2, 2))),
- ((1, 1), (-1, -1), ((-2, 2), (-2, 2))),
- ((-1, 1), (1, -1), ((-2, 2), (-2, 2))),
+ ((0, 0), (1, 1), ((-1, -1), (2, 2))),
+ ((-1, -1), (1, 1), ((-2, -2), (2, 2))),
+ ((1, 1), (-1, -1), ((-2, -2), (2, 2))),
+ ((-1, 1), (1, -1), ((-2, -2), (2, 2))),
]
c = Circle((0, 0), 2)
@@ -64,10 +64,10 @@ def test_line_bounds():
# Test a non-square rectangle
r = Rectangle((0, 0), 3, 2)
cases = [
- ((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))),
- ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))),
- ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))),
- ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))),
+ ((0, 0), (1, 1), ((-1.5, -1), (2.5, 2))),
+ ((-1, -1), (1, 1), ((-2.5, -2), (2.5, 2))),
+ ((1, 1), (-1, -1), ((-2.5, -2), (2.5, 2))),
+ ((-1, 1), (1, -1), ((-2.5, -2), (2.5, 2))),
]
for start, end, expected in cases:
l = Line(start, end, r)
@@ -197,17 +197,17 @@ def test_arc_bounds():
""" Test Arc primitive bounding box calculation
"""
cases = [
- ((1, 0), (0, 1), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))),
- ((1, 0), (0, 1), (0, 0), "counterclockwise", ((-0.5, 1.5), (-0.5, 1.5))),
- ((0, 1), (-1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))),
- ((0, 1), (-1, 0), (0, 0), "counterclockwise", ((-1.5, 0.5), (-0.5, 1.5))),
- ((-1, 0), (0, -1), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))),
- ((-1, 0), (0, -1), (0, 0), "counterclockwise", ((-1.5, 0.5), (-1.5, 0.5))),
- ((0, -1), (1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))),
- ((0, -1), (1, 0), (0, 0), "counterclockwise", ((-0.5, 1.5), (-1.5, 0.5))),
+ (( 1, 0), ( 0, 1), (0, 0), "clockwise", ((-1.5, -1.5), (1.5, 1.5))),
+ (( 1, 0), ( 0, 1), (0, 0), "counterclockwise", ((-0.5, -0.5), (1.5, 1.5))),
+ (( 0, 1), (-1, 0), (0, 0), "clockwise", ((-1.5, -1.5), (1.5, 1.5))),
+ (( 0, 1), (-1, 0), (0, 0), "counterclockwise", ((-1.5, -0.5), (0.5, 1.5))),
+ ((-1, 0), ( 0, -1), (0, 0), "clockwise", ((-1.5, -1.5), (1.5, 1.5))),
+ ((-1, 0), ( 0, -1), (0, 0), "counterclockwise", ((-1.5, -1.5), (0.5, 0.5))),
+ (( 0, -1), ( 1, 0), (0, 0), "clockwise", ((-1.5, -1.5), (1.5, 1.5))),
+ (( 0, -1), ( 1, 0), (0, 0), "counterclockwise", ((-0.5, -1.5), (1.5, 0.5))),
# Arcs with the same start and end point render a full circle
- ((1, 0), (1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))),
- ((1, 0), (1, 0), (0, 0), "counterclockwise", ((-1.5, 1.5), (-1.5, 1.5))),
+ (( 1, 0), ( 1, 0), (0, 0), "clockwise", ((-1.5, -1.5), (1.5, 1.5))),
+ (( 1, 0), ( 1, 0), (0, 0), "counterclockwise", ((-1.5, -1.5), (1.5, 1.5))),
]
for start, end, center, direction, bounds in cases:
c = Circle((0, 0), 1)
@@ -219,17 +219,17 @@ def test_arc_bounds_no_aperture():
""" Test Arc primitive bounding box calculation ignoring aperture
"""
cases = [
- ((1, 0), (0, 1), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))),
- ((1, 0), (0, 1), (0, 0), "counterclockwise", ((0.0, 1.0), (0.0, 1.0))),
- ((0, 1), (-1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))),
+ ((1, 0), (0, 1), (0, 0), "clockwise", ((-1.0, -1.0), (1.0, 1.0))),
+ ((1, 0), (0, 1), (0, 0), "counterclockwise", ((0.0, 0.0), (1.0, 1.0))),
+ ((0, 1), (-1, 0), (0, 0), "clockwise", ((-1.0, -1.0), (1.0, 1.0))),
((0, 1), (-1, 0), (0, 0), "counterclockwise", ((-1.0, 0.0), (0.0, 1.0))),
- ((-1, 0), (0, -1), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))),
- ((-1, 0), (0, -1), (0, 0), "counterclockwise", ((-1.0, 0.0), (-1.0, 0.0))),
- ((0, -1), (1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))),
- ((0, -1), (1, 0), (0, 0), "counterclockwise", ((-0.0, 1.0), (-1.0, 0.0))),
+ ((-1, 0), (0, -1), (0, 0), "clockwise", ((-1.0, -1.0), (1.0, 1.0))),
+ ((-1, 0), (0, -1), (0, 0), "counterclockwise", ((-1.0, -1.0), (0.0, 0.0))),
+ ((0, -1), (1, 0), (0, 0), "clockwise", ((-1.0, -1.0), (1.0, 1.0))),
+ ((0, -1), (1, 0), (0, 0), "counterclockwise", ((-0.0, -1.0), (1.0, 0.0))),
# Arcs with the same start and end point render a full circle
- ((1, 0), (1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))),
- ((1, 0), (1, 0), (0, 0), "counterclockwise", ((-1.0, 1.0), (-1.0, 1.0))),
+ ((1, 0), (1, 0), (0, 0), "clockwise", ((-1.0, -1.0), (1.0, 1.0))),
+ ((1, 0), (1, 0), (0, 0), "counterclockwise", ((-1.0, -1.0), (1.0, 1.0))),
]
for start, end, center, direction, bounds in cases:
c = Circle((0, 0), 1)
@@ -317,7 +317,7 @@ def test_circle_bounds():
""" Test Circle bounding box calculation
"""
c = Circle((1, 1), 2)
- assert c.bounding_box == ((0, 2), (0, 2))
+ assert c.bounding_box == ((0, 0), (2, 2))
def test_circle_conversion():
@@ -419,13 +419,13 @@ def test_ellipse_bounds():
""" Test ellipse bounding box calculation
"""
e = Ellipse((2, 2), 4, 2)
- assert e.bounding_box == ((0, 4), (1, 3))
+ assert e.bounding_box == ((0, 1), (4, 3))
e = Ellipse((2, 2), 4, 2, rotation=90)
- assert e.bounding_box == ((1, 3), (0, 4))
+ assert e.bounding_box == ((1, 0), (3, 4))
e = Ellipse((2, 2), 4, 2, rotation=180)
- assert e.bounding_box == ((0, 4), (1, 3))
+ assert e.bounding_box == ((0, 1), (4, 3))
e = Ellipse((2, 2), 4, 2, rotation=270)
- assert e.bounding_box == ((1, 3), (0, 4))
+ assert e.bounding_box == ((1, 0), (3, 4))
def test_ellipse_conversion():
@@ -501,13 +501,13 @@ def test_rectangle_bounds():
""" Test rectangle bounding box calculation
"""
r = Rectangle((0, 0), 2, 2)
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
r = Rectangle((0, 0), 2, 2, rotation=45)
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2)))
- pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2)))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2)))
+ pytest.approx(bounds[1], (math.sqrt(2), math.sqrt(2)))
def test_rectangle_vertices():
@@ -650,13 +650,13 @@ def test_diamond_bounds():
""" Test diamond bounding box calculation
"""
d = Diamond((0, 0), 2, 2)
- xbounds, ybounds = d.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = d.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
d = Diamond((0, 0), math.sqrt(2), math.sqrt(2), rotation=45)
- xbounds, ybounds = d.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = d.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
def test_diamond_conversion():
@@ -724,13 +724,13 @@ def test_chamfer_rectangle_bounds():
""" Test chamfer rectangle bounding box calculation
"""
r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False))
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45)
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2)))
- pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2)))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2)))
+ pytest.approx(bounds[1], (math.sqrt(2), math.sqrt(2)))
def test_chamfer_rectangle_conversion():
@@ -849,13 +849,13 @@ def test_round_rectangle_bounds():
""" Test round rectangle bounding box calculation
"""
r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False))
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45)
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2)))
- pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2)))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2)))
+ pytest.approx(bounds[1], (math.sqrt(2), math.sqrt(2)))
def test_round_rectangle_conversion():
@@ -927,13 +927,13 @@ def test_obround_bounds():
""" Test obround bounding box calculation
"""
o = Obround((2, 2), 2, 4)
- xbounds, ybounds = o.bounding_box
- pytest.approx(xbounds, (1, 3))
- pytest.approx(ybounds, (0, 4))
+ bounds = o.bounding_box
+ pytest.approx(bounds[0], (1, 0))
+ pytest.approx(bounds[1], (3, 4))
o = Obround((2, 2), 4, 2)
- xbounds, ybounds = o.bounding_box
- pytest.approx(xbounds, (0, 4))
- pytest.approx(ybounds, (1, 3))
+ bounds = o.bounding_box
+ pytest.approx(bounds[0], (0, 1))
+ pytest.approx(bounds[1], (4, 3))
def test_obround_orientation():
@@ -1020,13 +1020,13 @@ def test_polygon_bounds():
""" Test polygon bounding box calculation
"""
p = Polygon((2, 2), 3, 2, 0)
- xbounds, ybounds = p.bounding_box
- pytest.approx(xbounds, (0, 4))
- pytest.approx(ybounds, (0, 4))
+ bounds = p.bounding_box
+ pytest.approx(bounds[0], (0, 0))
+ pytest.approx(bounds[0], (4, 4))
p = Polygon((2, 2), 3, 4, 0)
- xbounds, ybounds = p.bounding_box
- pytest.approx(xbounds, (-2, 6))
- pytest.approx(ybounds, (-2, 6))
+ bounds = p.bounding_box
+ pytest.approx(bounds[0], (-2, -2))
+ pytest.approx(bounds[1], (6, 6))
def test_polygon_conversion():
@@ -1098,9 +1098,9 @@ def test_region_bounds():
Line((0, 1), (0, 0), apt),
)
r = Region(lines)
- xbounds, ybounds = r.bounding_box
- pytest.approx(xbounds, (0, 1))
- pytest.approx(ybounds, (0, 1))
+ bounds = r.bounding_box
+ pytest.approx(bounds[0], (0, 0))
+ pytest.approx(bounds[1], (1, 1))
def test_region_offset():
@@ -1183,9 +1183,9 @@ def test_round_butterfly_bounds():
""" Test RoundButterfly bounding box calculation
"""
b = RoundButterfly((0, 0), 2)
- xbounds, ybounds = b.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = b.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
def test_square_butterfly_ctor():
@@ -1209,9 +1209,9 @@ def test_square_butterfly_bounds():
""" Test SquareButterfly bounding box calculation
"""
b = SquareButterfly((0, 0), 2)
- xbounds, ybounds = b.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = b.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
def test_squarebutterfly_conversion():
@@ -1282,9 +1282,9 @@ def test_donut_ctor_validation():
def test_donut_bounds():
d = Donut((0, 0), "round", 0.0, 2.0)
- xbounds, ybounds = d.bounding_box
- assert xbounds == (-1.0, 1.0)
- assert ybounds == (-1.0, 1.0)
+ bounds = d.bounding_box
+ assert bounds[0] == (-1.0, -1.0)
+ assert bounds[1] == (1.0, 1.0)
def test_donut_conversion():
@@ -1355,13 +1355,13 @@ def test_drill_ctor_validation():
def test_drill_bounds():
d = Drill((0, 0), 2)
- xbounds, ybounds = d.bounding_box
- pytest.approx(xbounds, (-1, 1))
- pytest.approx(ybounds, (-1, 1))
+ bounds = d.bounding_box
+ pytest.approx(bounds[0], (-1, -1))
+ pytest.approx(bounds[1], (1, 1))
d = Drill((1, 2), 2)
- xbounds, ybounds = d.bounding_box
- pytest.approx(xbounds, (0, 2))
- pytest.approx(ybounds, (1, 3))
+ bounds = d.bounding_box
+ pytest.approx(bounds[0], (0, 1))
+ pytest.approx(bounds[1], (2, 3))
def test_drill_conversion():
@@ -1418,12 +1418,13 @@ def test_slot_bounds():
""" Test Slot primitive bounding box calculation
"""
cases = [
- ((0, 0), (1, 1), ((-1, 2), (-1, 2))),
- ((-1, -1), (1, 1), ((-2, 2), (-2, 2))),
- ((1, 1), (-1, -1), ((-2, 2), (-2, 2))),
- ((-1, 1), (1, -1), ((-2, 2), (-2, 2))),
+ (( 0, 0), ( 1, 1), ((-1, -1), (2, 2))),
+ ((-1, -1), ( 1, 1), ((-2, -2), (2, 2))),
+ (( 1, 1), (-1, -1), ((-2, -2), (2, 2))),
+ ((-1, 1), ( 1, -1), ((-2, -2), (2, 2))),
]
for start, end, expected in cases:
s = Slot(start, end, 2.0)
assert s.bounding_box == expected
+
diff --git a/gerbonara/gerber/tests/test_rs274x.py b/gerbonara/gerber/tests/test_rs274x.py
index e7baf11..e430f36 100644
--- a/gerbonara/gerber/tests/test_rs274x.py
+++ b/gerbonara/gerber/tests/test_rs274x.py
@@ -23,7 +23,7 @@ def test_read():
def test_multiline_read():
multiline = read(MULTILINE_READ_FILE)
assert isinstance(multiline, GerberFile)
- assert 10 == len(multiline.statements)
+ assert 11 == len(multiline.statements)
def test_comments_parameter():