summaryrefslogtreecommitdiff
path: root/gerber/tests
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-02 11:42:47 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-02 11:42:47 -0500
commit1cc20b351c10b1fa19817f29edd8c54a27aeee4b (patch)
treec79265c665c37be7d85677836f9b7761a42fa1e9 /gerber/tests
parentd98d23f8b5d61bb9d20e743a3c44bf04b6b2330a (diff)
downloadgerbonara-1cc20b351c10b1fa19817f29edd8c54a27aeee4b.tar.gz
gerbonara-1cc20b351c10b1fa19817f29edd8c54a27aeee4b.tar.bz2
gerbonara-1cc20b351c10b1fa19817f29edd8c54a27aeee4b.zip
tests
Diffstat (limited to 'gerber/tests')
-rw-r--r--gerber/tests/test_cam.py18
-rw-r--r--gerber/tests/test_gerber_statements.py92
-rw-r--r--gerber/tests/test_primitives.py119
-rw-r--r--gerber/tests/test_utils.py10
4 files changed, 201 insertions, 38 deletions
diff --git a/gerber/tests/test_cam.py b/gerber/tests/test_cam.py
index 8e0270c..185e716 100644
--- a/gerber/tests/test_cam.py
+++ b/gerber/tests/test_cam.py
@@ -77,7 +77,6 @@ def test_zeros():
assert_equal(fs.zero_suppression, 'trailing')
assert_equal(fs.zeros, 'leading')
-
fs['zero_suppression'] = 'leading'
assert_equal(fs.zero_suppression, 'leading')
assert_equal(fs.zeros, 'trailing')
@@ -90,11 +89,26 @@ def test_zeros():
assert_equal(fs.zeros, 'trailing')
assert_equal(fs.zero_suppression, 'leading')
-
fs.zeros= 'leading'
assert_equal(fs.zeros, 'leading')
assert_equal(fs.zero_suppression, 'trailing')
+ fs = FileSettings(zeros='leading')
+ assert_equal(fs.zeros, 'leading')
+ assert_equal(fs.zero_suppression, 'trailing')
+
+ fs = FileSettings(zero_suppression='leading')
+ assert_equal(fs.zeros, 'trailing')
+ assert_equal(fs.zero_suppression, 'leading')
+
+ fs = FileSettings(zeros='leading', zero_suppression='trailing')
+ assert_equal(fs.zeros, 'leading')
+ assert_equal(fs.zero_suppression, 'trailing')
+
+ fs = FileSettings(zeros='trailing', zero_suppression='leading')
+ assert_equal(fs.zeros, 'trailing')
+ assert_equal(fs.zero_suppression, 'leading')
+
def test_filesettings_validation():
""" Test FileSettings constructor argument validation
diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py
index ff967f9..e797d5a 100644
--- a/gerber/tests/test_gerber_statements.py
+++ b/gerber/tests/test_gerber_statements.py
@@ -82,6 +82,12 @@ def test_MOParamStmt_factory():
assert_equal(mo.param, 'MO')
assert_equal(mo.mode, 'metric')
+ stmt = {'param': 'MO'}
+ mo = MOParamStmt.from_dict(stmt)
+ assert_equal(mo.mode, None)
+ stmt = {'param': 'MO', 'mo': 'degrees kelvin'}
+ assert_raises(ValueError, MOParamStmt.from_dict, stmt)
+
def test_MOParamStmt():
""" Test MOParamStmt initialization
@@ -182,6 +188,13 @@ def test_OFParamStmt_dump():
assert_equal(of.to_gerber(), '%OFA0.12345B0.12345*%')
+def test_OFParamStmt_string():
+ """ Test OFParamStmt __str__
+ """
+ stmt = {'param': 'OF', 'a': '0.123456', 'b': '0.123456'}
+ of = OFParamStmt.from_dict(stmt)
+ assert_equal(str(of), '<Offset: X: 0.123456 Y: 0.123456 >')
+
def test_LPParamStmt_factory():
""" Test LPParamStmt factory
"""
@@ -377,38 +390,47 @@ def test_ADParamStmt_factory():
assert_equal(ad.d, 1)
assert_equal(ad.shape, 'R')
- stmt = {'param': 'AD', 'd': 2, 'shape': 'O'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(ad.d, 2)
- assert_equal(ad.shape, 'O')
-
-
-def test_ADParamStmt_dump():
- """ Test ADParamStmt.to_gerber()
- """
- stmt = {'param': 'AD', 'd': 0, 'shape': 'C'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(ad.to_gerber(),'%ADD0C*%')
-
- stmt = {'param': 'AD', 'd': 1, 'shape': 'R'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(ad.to_gerber(),'%ADD1R*%')
-
- stmt = {'param': 'AD', 'd': 2, 'shape': 'O'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(ad.to_gerber(),'%ADD2O*%')
-
-def test_ADParamStmt_string():
- """ Test ADParamStmt.__str__()
- """
- stmt = {'param': 'AD', 'd': 0, 'shape': 'C'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(str(ad), '<Aperture Definition: 0: circle>')
-
- stmt = {'param': 'AD', 'd': 1, 'shape': 'R'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(str(ad), '<Aperture Definition: 1: rectangle>')
-
- stmt = {'param': 'AD', 'd': 2, 'shape': 'O'}
- ad = ADParamStmt.from_dict(stmt)
- assert_equal(str(ad), '<Aperture Definition: 2: obround>')
+def test_MIParamStmt_factory():
+ stmt = {'param': 'MI', 'a': 1, 'b': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(mi.a, 1)
+ assert_equal(mi.b, 1)
+
+def test_MIParamStmt_dump():
+ stmt = {'param': 'MI', 'a': 1, 'b': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(mi.to_gerber(), '%MIA1B1*%')
+ stmt = {'param': 'MI', 'a': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(mi.to_gerber(), '%MIA1B0*%')
+ stmt = {'param': 'MI', 'b': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(mi.to_gerber(), '%MIA0B1*%')
+
+def test_MIParamStmt_string():
+ stmt = {'param': 'MI', 'a': 1, 'b': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(str(mi), '<Image Mirror: A=1 B=1>')
+
+ stmt = {'param': 'MI', 'b': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(str(mi), '<Image Mirror: A=0 B=1>')
+
+ stmt = {'param': 'MI', 'a': 1}
+ mi = MIParamStmt.from_dict(stmt)
+ assert_equal(str(mi), '<Image Mirror: A=1 B=0>')
+
+
+
+def test_coordstmt_ctor():
+ cs = CoordStmt('G04', 0.0, 0.1, 0.2, 0.3, 'D01', FileSettings())
+ assert_equal(cs.function, 'G04')
+ assert_equal(cs.x, 0.0)
+ assert_equal(cs.y, 0.1)
+ assert_equal(cs.i, 0.2)
+ assert_equal(cs.j, 0.3)
+ assert_equal(cs.op, 'D01')
+
+
+
+ \ No newline at end of file
diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py
index e5ae770..14a3d39 100644
--- a/gerber/tests/test_primitives.py
+++ b/gerber/tests/test_primitives.py
@@ -6,6 +6,11 @@ from ..primitives import *
from tests import *
+def test_primitive_implementation_warning():
+ p = Primitive()
+ assert_raises(NotImplementedError, p.bounding_box)
+
+
def test_line_angle():
""" Test Line primitive angle calculation
"""
@@ -277,4 +282,118 @@ def test_polygon_bounds():
assert_array_almost_equal(ybounds, (-2, 6))
+def test_region_ctor():
+ """ Test Region creation
+ """
+ points = ((0, 0), (1,0), (1,1), (0,1))
+ r = Region(points)
+ for i, point in enumerate(points):
+ assert_array_almost_equal(r.points[i], point)
+
+
+def test_region_bounds():
+ """ Test region bounding box calculation
+ """
+ points = ((0, 0), (1,0), (1,1), (0,1))
+ r = Region(points)
+ xbounds, ybounds = r.bounding_box
+ assert_array_almost_equal(xbounds, (0, 1))
+ assert_array_almost_equal(ybounds, (0, 1))
+
+
+def test_round_butterfly_ctor():
+ """ Test round butterfly creation
+ """
+ test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7))
+ for pos, diameter in test_cases:
+ b = RoundButterfly(pos, diameter)
+ assert_equal(b.position, pos)
+ assert_equal(b.diameter, diameter)
+ assert_equal(b.radius, diameter/2.)
+
+def test_round_butterfly_ctor_validation():
+ """ Test RoundButterfly argument validation
+ """
+ assert_raises(TypeError, RoundButterfly, 3, 5)
+ assert_raises(TypeError, RoundButterfly, (3,4,5), 5)
+
+def test_round_butterfly_bounds():
+ """ Test RoundButterfly bounding box calculation
+ """
+ b = RoundButterfly((0, 0), 2)
+ xbounds, ybounds = b.bounding_box
+ assert_array_almost_equal(xbounds, (-1, 1))
+ assert_array_almost_equal(ybounds, (-1, 1))
+
+def test_square_butterfly_ctor():
+ """ Test SquareButterfly creation
+ """
+ test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7))
+ for pos, side in test_cases:
+ b = SquareButterfly(pos, side)
+ assert_equal(b.position, pos)
+ assert_equal(b.side, side)
+
+def test_square_butterfly_ctor_validation():
+ """ Test SquareButterfly argument validation
+ """
+ assert_raises(TypeError, SquareButterfly, 3, 5)
+ assert_raises(TypeError, SquareButterfly, (3,4,5), 5)
+
+def test_square_butterfly_bounds():
+ """ Test SquareButterfly bounding box calculation
+ """
+ b = SquareButterfly((0, 0), 2)
+ xbounds, ybounds = b.bounding_box
+ assert_array_almost_equal(xbounds, (-1, 1))
+ assert_array_almost_equal(ybounds, (-1, 1))
+
+def test_donut_ctor():
+ """ Test Donut primitive creation
+ """
+ test_cases = (((0,0), 'round', 3, 5), ((0, 0), 'square', 5, 7),
+ ((1,1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11))
+ for pos, shape, in_d, out_d in test_cases:
+ d = Donut(pos, shape, in_d, out_d)
+ assert_equal(d.position, pos)
+ assert_equal(d.shape, shape)
+ assert_equal(d.inner_diameter, in_d)
+ assert_equal(d.outer_diameter, out_d)
+
+def test_donut_ctor_validation():
+ assert_raises(TypeError, Donut, 3, 'round', 5, 7)
+ assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7)
+ assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5)
+ assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3)
+
+def test_donut_bounds():
+ pass
+
+def test_drill_ctor():
+ """ Test drill primitive creation
+ """
+ test_cases = (((0, 0), 2), ((1, 1), 3), ((2, 2), 5))
+ for position, diameter in test_cases:
+ d = Drill(position, diameter)
+ assert_equal(d.position, position)
+ assert_equal(d.diameter, diameter)
+ assert_equal(d.radius, diameter/2.)
+
+def test_drill_ctor_validation():
+ """ Test drill argument validation
+ """
+ assert_raises(TypeError, Drill, 3, 5)
+ assert_raises(TypeError, Drill, (3,4,5), 5)
+
+def test_drill_bounds():
+ d = Drill((0, 0), 2)
+ xbounds, ybounds = d.bounding_box
+ assert_array_almost_equal(xbounds, (-1, 1))
+ assert_array_almost_equal(ybounds, (-1, 1))
+ d = Drill((1, 2), 2)
+ xbounds, ybounds = d.bounding_box
+ assert_array_almost_equal(xbounds, (0, 2))
+ assert_array_almost_equal(ybounds, (1, 3))
+
+ \ No newline at end of file
diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py
index 1077022..1c3f1e5 100644
--- a/gerber/tests/test_utils.py
+++ b/gerber/tests/test_utils.py
@@ -4,7 +4,7 @@
# Author: Hamilton Kibbe <ham@hamiltonkib.be>
from .tests import assert_equal, assert_raises
-from ..utils import decimal_string, parse_gerber_value, write_gerber_value, detect_file_format
+from ..utils import *
def test_zero_suppression():
@@ -107,3 +107,11 @@ def test_detect_format_with_short_file():
""" Verify file format detection works with short files
"""
assert_equal('unknown', detect_file_format('gerber/tests/__init__.py'))
+
+def test_validate_coordinates():
+ assert_raises(TypeError, validate_coordinates, 3)
+ assert_raises(TypeError, validate_coordinates, 3.1)
+ assert_raises(TypeError, validate_coordinates, '14')
+ assert_raises(TypeError, validate_coordinates, (0,))
+ assert_raises(TypeError, validate_coordinates, (0,1,2))
+ assert_raises(TypeError, validate_coordinates, (0,'string'))