summaryrefslogtreecommitdiff
path: root/gerber/tests/test_excellon_statements.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-21 03:57:44 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-21 03:57:44 -0500
commit5476da8aa3f4ee424f56f4f2491e7af1c4b7b758 (patch)
tree427dafda78ee21a1846a2b9c9747dd96afe7e8a3 /gerber/tests/test_excellon_statements.py
parent7a532514631384dbfc9d7fc2002cbbfe52433c9f (diff)
downloadgerbonara-5476da8aa3f4ee424f56f4f2491e7af1c4b7b758.tar.gz
gerbonara-5476da8aa3f4ee424f56f4f2491e7af1c4b7b758.tar.bz2
gerbonara-5476da8aa3f4ee424f56f4f2491e7af1c4b7b758.zip
Fix a bunch of rendering bugs.
- 'clear' polarity primitives no longer erase background - Added aperture macro support for polygons - Added aperture macro rendring support - Renderer now creates a new surface for each layer and merges them instead of working directly on a single surface - Updated examples accordingly
Diffstat (limited to 'gerber/tests/test_excellon_statements.py')
-rw-r--r--gerber/tests/test_excellon_statements.py173
1 files changed, 113 insertions, 60 deletions
diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py
index 2f0ef10..8e6e06e 100644
--- a/gerber/tests/test_excellon_statements.py
+++ b/gerber/tests/test_excellon_statements.py
@@ -7,11 +7,13 @@ from .tests import assert_equal, assert_not_equal, assert_raises
from ..excellon_statements import *
from ..cam import FileSettings
+
def test_excellon_statement_implementation():
stmt = ExcellonStatement()
assert_raises(NotImplementedError, stmt.from_excellon, None)
assert_raises(NotImplementedError, stmt.to_excellon)
+
def test_excellontstmt():
""" Smoke test ExcellonStatement
"""
@@ -20,17 +22,18 @@ def test_excellontstmt():
stmt.to_metric()
stmt.offset()
+
def test_excellontool_factory():
""" Test ExcellonTool factory methods
"""
exc_line = 'T8F01B02S00003H04Z05C0.12500'
settings = FileSettings(format=(2, 5), zero_suppression='trailing',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
tool = ExcellonTool.from_excellon(exc_line, settings)
assert_equal(tool.number, 8)
assert_equal(tool.diameter, 0.125)
assert_equal(tool.feed_rate, 1)
- assert_equal(tool.retract_rate,2)
+ assert_equal(tool.retract_rate, 2)
assert_equal(tool.rpm, 3)
assert_equal(tool.max_hit_count, 4)
assert_equal(tool.depth_offset, 5)
@@ -41,7 +44,7 @@ def test_excellontool_factory():
assert_equal(tool.number, 8)
assert_equal(tool.diameter, 0.125)
assert_equal(tool.feed_rate, 1)
- assert_equal(tool.retract_rate,2)
+ assert_equal(tool.retract_rate, 2)
assert_equal(tool.rpm, 3)
assert_equal(tool.max_hit_count, 4)
assert_equal(tool.depth_offset, 5)
@@ -55,7 +58,7 @@ def test_excellontool_dump():
'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000',
'T08B01F02H03S00003C0.12500Z04', 'T01F0S300.999C0.01200']
settings = FileSettings(format=(2, 5), zero_suppression='trailing',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
for line in exc_lines:
tool = ExcellonTool.from_excellon(line, settings)
assert_equal(tool.to_excellon(), line)
@@ -63,7 +66,7 @@ def test_excellontool_dump():
def test_excellontool_order():
settings = FileSettings(format=(2, 5), zero_suppression='trailing',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
line = 'T8F00S00C0.12500'
tool1 = ExcellonTool.from_excellon(line, settings)
line = 'T8C0.12500F00S00'
@@ -72,36 +75,48 @@ def test_excellontool_order():
assert_equal(tool1.feed_rate, tool2.feed_rate)
assert_equal(tool1.rpm, tool2.rpm)
+
def test_excellontool_conversion():
- tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 25.4})
+ tool = ExcellonTool.from_dict(FileSettings(units='metric'),
+ {'number': 8, 'diameter': 25.4})
tool.to_inch()
assert_equal(tool.diameter, 1.)
- tool = ExcellonTool.from_dict(FileSettings(units='inch'), {'number': 8, 'diameter': 1.})
+ tool = ExcellonTool.from_dict(FileSettings(units='inch'),
+ {'number': 8, 'diameter': 1.})
tool.to_metric()
assert_equal(tool.diameter, 25.4)
# Shouldn't change units if we're already using target units
- tool = ExcellonTool.from_dict(FileSettings(units='inch'), {'number': 8, 'diameter': 25.4})
+ tool = ExcellonTool.from_dict(FileSettings(units='inch'),
+ {'number': 8, 'diameter': 25.4})
tool.to_inch()
assert_equal(tool.diameter, 25.4)
- tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 1.})
+ tool = ExcellonTool.from_dict(FileSettings(units='metric'),
+ {'number': 8, 'diameter': 1.})
tool.to_metric()
assert_equal(tool.diameter, 1.)
def test_excellontool_repr():
- tool = ExcellonTool.from_dict(FileSettings(), {'number': 8, 'diameter': 0.125})
+ tool = ExcellonTool.from_dict(FileSettings(),
+ {'number': 8, 'diameter': 0.125})
assert_equal(str(tool), '<ExcellonTool 08: 0.125in. dia.>')
- tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 0.125})
+ tool = ExcellonTool.from_dict(FileSettings(units='metric'),
+ {'number': 8, 'diameter': 0.125})
assert_equal(str(tool), '<ExcellonTool 08: 0.125mm dia.>')
+
def test_excellontool_equality():
- t = ExcellonTool.from_dict(FileSettings(), {'number': 8, 'diameter': 0.125})
- t1 = ExcellonTool.from_dict(FileSettings(), {'number': 8, 'diameter': 0.125})
+ t = ExcellonTool.from_dict(
+ FileSettings(), {'number': 8, 'diameter': 0.125})
+ t1 = ExcellonTool.from_dict(
+ FileSettings(), {'number': 8, 'diameter': 0.125})
assert_equal(t, t1)
- t1 = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 0.125})
+ t1 = ExcellonTool.from_dict(FileSettings(units='metric'),
+ {'number': 8, 'diameter': 0.125})
assert_not_equal(t, t1)
+
def test_toolselection_factory():
""" Test ToolSelectionStmt factory method
"""
@@ -115,6 +130,7 @@ def test_toolselection_factory():
assert_equal(stmt.tool, 42)
assert_equal(stmt.compensation_index, None)
+
def test_toolselection_dump():
""" Test ToolSelectionStmt to_excellon()
"""
@@ -123,6 +139,7 @@ def test_toolselection_dump():
stmt = ToolSelectionStmt.from_excellon(line)
assert_equal(stmt.to_excellon(), line)
+
def test_z_axis_infeed_rate_factory():
""" Test ZAxisInfeedRateStmt factory method
"""
@@ -133,6 +150,7 @@ def test_z_axis_infeed_rate_factory():
stmt = ZAxisInfeedRateStmt.from_excellon('F03')
assert_equal(stmt.rate, 3)
+
def test_z_axis_infeed_rate_dump():
""" Test ZAxisInfeedRateStmt to_excellon()
"""
@@ -145,11 +163,12 @@ def test_z_axis_infeed_rate_dump():
stmt = ZAxisInfeedRateStmt.from_excellon(input_rate)
assert_equal(stmt.to_excellon(), expected_output)
+
def test_coordinatestmt_factory():
""" Test CoordinateStmt factory method
"""
settings = FileSettings(format=(2, 5), zero_suppression='trailing',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
line = 'X0278207Y0065293'
stmt = CoordinateStmt.from_excellon(line, settings)
@@ -165,7 +184,7 @@ def test_coordinatestmt_factory():
# assert_equal(stmt.y, 0.575)
settings = FileSettings(format=(2, 4), zero_suppression='leading',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
line = 'X9660Y4639'
stmt = CoordinateStmt.from_excellon(line, settings)
@@ -173,12 +192,12 @@ def test_coordinatestmt_factory():
assert_equal(stmt.y, 0.4639)
assert_equal(stmt.to_excellon(settings), "X9660Y4639")
assert_equal(stmt.units, 'inch')
-
+
settings.units = 'metric'
stmt = CoordinateStmt.from_excellon(line, settings)
assert_equal(stmt.units, 'metric')
-
-
+
+
def test_coordinatestmt_dump():
""" Test CoordinateStmt to_excellon()
"""
@@ -186,102 +205,110 @@ def test_coordinatestmt_dump():
'X251295Y81528', 'X2525Y78', 'X255Y575', 'Y52',
'X2675', 'Y575', 'X2425', 'Y52', 'X23', ]
settings = FileSettings(format=(2, 4), zero_suppression='leading',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
for line in lines:
stmt = CoordinateStmt.from_excellon(line, settings)
assert_equal(stmt.to_excellon(settings), line)
+
def test_coordinatestmt_conversion():
-
+
settings = FileSettings()
settings.units = 'metric'
stmt = CoordinateStmt.from_excellon('X254Y254', settings)
-
- #No effect
+
+ # No effect
stmt.to_metric()
assert_equal(stmt.x, 25.4)
assert_equal(stmt.y, 25.4)
-
+
stmt.to_inch()
assert_equal(stmt.units, 'inch')
assert_equal(stmt.x, 1.)
assert_equal(stmt.y, 1.)
-
- #No effect
+
+ # No effect
stmt.to_inch()
assert_equal(stmt.x, 1.)
assert_equal(stmt.y, 1.)
-
+
settings.units = 'inch'
stmt = CoordinateStmt.from_excellon('X01Y01', settings)
-
- #No effect
+
+ # No effect
stmt.to_inch()
assert_equal(stmt.x, 1.)
assert_equal(stmt.y, 1.)
-
+
stmt.to_metric()
assert_equal(stmt.units, 'metric')
assert_equal(stmt.x, 25.4)
assert_equal(stmt.y, 25.4)
-
- #No effect
+
+ # No effect
stmt.to_metric()
assert_equal(stmt.x, 25.4)
assert_equal(stmt.y, 25.4)
+
def test_coordinatestmt_offset():
stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings())
stmt.offset()
assert_equal(stmt.x, 1)
assert_equal(stmt.y, 1)
- stmt.offset(1,0)
+ stmt.offset(1, 0)
assert_equal(stmt.x, 2.)
assert_equal(stmt.y, 1.)
- stmt.offset(0,1)
+ stmt.offset(0, 1)
assert_equal(stmt.x, 2.)
assert_equal(stmt.y, 2.)
def test_coordinatestmt_string():
settings = FileSettings(format=(2, 4), zero_suppression='leading',
- units='inch', notation='absolute')
+ units='inch', notation='absolute')
stmt = CoordinateStmt.from_excellon('X9660Y4639', settings)
assert_equal(str(stmt), '<Coordinate Statement: X: 0.966 Y: 0.4639 >')
def test_repeathole_stmt_factory():
- stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='inch'))
+ stmt = RepeatHoleStmt.from_excellon('R0004X015Y32',
+ FileSettings(zeros='leading',
+ units='inch'))
assert_equal(stmt.count, 4)
assert_equal(stmt.xdelta, 1.5)
assert_equal(stmt.ydelta, 32)
assert_equal(stmt.units, 'inch')
-
- stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='metric'))
+
+ stmt = RepeatHoleStmt.from_excellon('R0004X015Y32',
+ FileSettings(zeros='leading',
+ units='metric'))
assert_equal(stmt.units, 'metric')
+
def test_repeatholestmt_dump():
line = 'R4X015Y32'
stmt = RepeatHoleStmt.from_excellon(line, FileSettings())
assert_equal(stmt.to_excellon(FileSettings()), line)
+
def test_repeatholestmt_conversion():
line = 'R4X0254Y254'
settings = FileSettings()
settings.units = 'metric'
stmt = RepeatHoleStmt.from_excellon(line, settings)
-
- #No effect
+
+ # No effect
stmt.to_metric()
assert_equal(stmt.xdelta, 2.54)
assert_equal(stmt.ydelta, 25.4)
-
+
stmt.to_inch()
assert_equal(stmt.units, 'inch')
assert_equal(stmt.xdelta, 0.1)
assert_equal(stmt.ydelta, 1.)
-
- #no effect
+
+ # no effect
stmt.to_inch()
assert_equal(stmt.xdelta, 0.1)
assert_equal(stmt.ydelta, 1.)
@@ -289,26 +316,28 @@ def test_repeatholestmt_conversion():
line = 'R4X01Y1'
settings.units = 'inch'
stmt = RepeatHoleStmt.from_excellon(line, settings)
-
- #no effect
+
+ # no effect
stmt.to_inch()
assert_equal(stmt.xdelta, 1.)
assert_equal(stmt.ydelta, 10.)
-
+
stmt.to_metric()
assert_equal(stmt.units, 'metric')
assert_equal(stmt.xdelta, 25.4)
assert_equal(stmt.ydelta, 254.)
-
- #No effect
+
+ # No effect
stmt.to_metric()
assert_equal(stmt.xdelta, 25.4)
assert_equal(stmt.ydelta, 254.)
+
def test_repeathole_str():
stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings())
assert_equal(str(stmt), '<Repeat Hole: 4 times, offset X: 1.5 Y: 32>')
+
def test_commentstmt_factory():
""" Test CommentStmt factory method
"""
@@ -333,42 +362,52 @@ def test_commentstmt_dump():
stmt = CommentStmt.from_excellon(line)
assert_equal(stmt.to_excellon(), line)
+
def test_header_begin_stmt():
stmt = HeaderBeginStmt()
assert_equal(stmt.to_excellon(None), 'M48')
+
def test_header_end_stmt():
stmt = HeaderEndStmt()
assert_equal(stmt.to_excellon(None), 'M95')
+
def test_rewindstop_stmt():
stmt = RewindStopStmt()
assert_equal(stmt.to_excellon(None), '%')
+
def test_z_axis_rout_position_stmt():
stmt = ZAxisRoutPositionStmt()
assert_equal(stmt.to_excellon(None), 'M15')
+
def test_retract_with_clamping_stmt():
stmt = RetractWithClampingStmt()
assert_equal(stmt.to_excellon(None), 'M16')
+
def test_retract_without_clamping_stmt():
stmt = RetractWithoutClampingStmt()
assert_equal(stmt.to_excellon(None), 'M17')
+
def test_cutter_compensation_off_stmt():
stmt = CutterCompensationOffStmt()
assert_equal(stmt.to_excellon(None), 'G40')
+
def test_cutter_compensation_left_stmt():
stmt = CutterCompensationLeftStmt()
assert_equal(stmt.to_excellon(None), 'G41')
+
def test_cutter_compensation_right_stmt():
stmt = CutterCompensationRightStmt()
assert_equal(stmt.to_excellon(None), 'G42')
+
def test_endofprogramstmt_factory():
settings = FileSettings(units='inch')
stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings)
@@ -384,61 +423,65 @@ def test_endofprogramstmt_factory():
assert_equal(stmt.x, None)
assert_equal(stmt.y, 2.)
+
def test_endofprogramStmt_dump():
- lines = ['M30X01Y02',]
+ lines = ['M30X01Y02', ]
for line in lines:
stmt = EndOfProgramStmt.from_excellon(line, FileSettings())
assert_equal(stmt.to_excellon(FileSettings()), line)
+
def test_endofprogramstmt_conversion():
settings = FileSettings()
settings.units = 'metric'
stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings)
- #No effect
+ # No effect
stmt.to_metric()
assert_equal(stmt.x, 2.54)
assert_equal(stmt.y, 25.4)
-
+
stmt.to_inch()
assert_equal(stmt.units, 'inch')
assert_equal(stmt.x, 0.1)
assert_equal(stmt.y, 1.0)
-
- #No effect
+
+ # No effect
stmt.to_inch()
assert_equal(stmt.x, 0.1)
assert_equal(stmt.y, 1.0)
settings.units = 'inch'
stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings)
-
- #No effect
+
+ # No effect
stmt.to_inch()
assert_equal(stmt.x, 1.)
assert_equal(stmt.y, 10.0)
-
+
stmt.to_metric()
assert_equal(stmt.units, 'metric')
assert_equal(stmt.x, 25.4)
assert_equal(stmt.y, 254.)
-
- #No effect
+
+ # No effect
stmt.to_metric()
assert_equal(stmt.x, 25.4)
assert_equal(stmt.y, 254.)
+
def test_endofprogramstmt_offset():
stmt = EndOfProgramStmt(1, 1)
stmt.offset()
assert_equal(stmt.x, 1)
assert_equal(stmt.y, 1)
- stmt.offset(1,0)
+ stmt.offset(1, 0)
assert_equal(stmt.x, 2.)
assert_equal(stmt.y, 1.)
- stmt.offset(0,1)
+ stmt.offset(0, 1)
assert_equal(stmt.x, 2.)
assert_equal(stmt.y, 2.)
+
def test_unitstmt_factory():
""" Test UnitStmt factory method
"""
@@ -471,6 +514,7 @@ def test_unitstmt_dump():
stmt = UnitStmt.from_excellon(line)
assert_equal(stmt.to_excellon(), line)
+
def test_unitstmt_conversion():
stmt = UnitStmt.from_excellon('METRIC,TZ')
stmt.to_inch()
@@ -480,6 +524,7 @@ def test_unitstmt_conversion():
stmt.to_metric()
assert_equal(stmt.units, 'metric')
+
def test_incrementalmode_factory():
""" Test IncrementalModeStmt factory method
"""
@@ -527,6 +572,7 @@ def test_versionstmt_dump():
stmt = VersionStmt.from_excellon(line)
assert_equal(stmt.to_excellon(), line)
+
def test_versionstmt_validation():
""" Test VersionStmt input validation
"""
@@ -608,6 +654,7 @@ def test_measmodestmt_validation():
assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70')
assert_raises(ValueError, MeasuringModeStmt, 'millimeters')
+
def test_measmodestmt_conversion():
line = 'M72'
stmt = MeasuringModeStmt.from_excellon(line)
@@ -621,27 +668,33 @@ def test_measmodestmt_conversion():
stmt.to_inch()
assert_equal(stmt.units, 'inch')
+
def test_routemode_stmt():
stmt = RouteModeStmt()
assert_equal(stmt.to_excellon(FileSettings()), 'G00')
+
def test_linearmode_stmt():
stmt = LinearModeStmt()
assert_equal(stmt.to_excellon(FileSettings()), 'G01')
+
def test_drillmode_stmt():
stmt = DrillModeStmt()
assert_equal(stmt.to_excellon(FileSettings()), 'G05')
+
def test_absolutemode_stmt():
stmt = AbsoluteModeStmt()
assert_equal(stmt.to_excellon(FileSettings()), 'G90')
+
def test_unknownstmt():
stmt = UnknownStmt('TEST')
assert_equal(stmt.stmt, 'TEST')
assert_equal(str(stmt), '<Unknown Statement: TEST>')
+
def test_unknownstmt_dump():
stmt = UnknownStmt('TEST')
assert_equal(stmt.to_excellon(FileSettings()), 'TEST')