diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-02-15 02:20:02 -0500 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-02-15 02:20:02 -0500 |
commit | 5cf1fa74b42eb8feaab23078bef6f31f6d647c33 (patch) | |
tree | 5758024d03d41fb9c8010314bbdb4f8f597db333 /gerber/tests/test_excellon_statements.py | |
parent | 5e23d07bcb5103b4607c6ad591a2a547c97ee1f6 (diff) | |
download | gerbonara-5cf1fa74b42eb8feaab23078bef6f31f6d647c33.tar.gz gerbonara-5cf1fa74b42eb8feaab23078bef6f31f6d647c33.tar.bz2 gerbonara-5cf1fa74b42eb8feaab23078bef6f31f6d647c33.zip |
Tests and bugfixes
Diffstat (limited to 'gerber/tests/test_excellon_statements.py')
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 129 |
1 files changed, 120 insertions, 9 deletions
diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 2e508ff..35bd045 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -7,17 +7,36 @@ from .tests import assert_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_excellontool_factory(): - """ Test ExcellonTool factory method + """ Test ExcellonTool factory methods """ - exc_line = 'T8F00S00C0.12500' + exc_line = 'T8F01B02S00003H04Z05C0.12500' settings = FileSettings(format=(2, 5), zero_suppression='trailing', 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, 0) - assert_equal(tool.rpm, 0) + assert_equal(tool.feed_rate, 1) + assert_equal(tool.retract_rate,2) + assert_equal(tool.rpm, 3) + assert_equal(tool.max_hit_count, 4) + assert_equal(tool.depth_offset, 5) + + stmt = {'number': 8, 'feed_rate': 1, 'retract_rate': 2, 'rpm': 3, + 'diameter': 0.125, 'max_hit_count': 4, 'depth_offset': 5} + tool = ExcellonTool.from_dict(settings, stmt) + 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.rpm, 3) + assert_equal(tool.max_hit_count, 4) + assert_equal(tool.depth_offset, 5) def test_excellontool_dump(): @@ -25,7 +44,8 @@ def test_excellontool_dump(): """ exc_lines = ['T01F0S0C0.01200', 'T02F0S0C0.01500', 'T03F0S0C0.01968', 'T04F0S0C0.02800', 'T05F0S0C0.03300', 'T06F0S0C0.03800', - 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', ] + 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', + 'T08B01F02H03S00003C0.12500Z04', 'T01F0S300.999C0.01200'] settings = FileSettings(format=(2, 5), zero_suppression='trailing', units='inch', notation='absolute') for line in exc_lines: @@ -44,6 +64,19 @@ 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(), {'number': 8, 'diameter': 25.4}) + tool.to_inch() + assert_equal(tool.diameter, 1.) + tool = ExcellonTool.from_dict(FileSettings(), {'number': 8, 'diameter': 1}) + tool.to_metric() + assert_equal(tool.diameter, 25.4) + +def test_excellontool_repr(): + 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}) + assert_equal(str(tool), '<ExcellonTool 08: 0.125mm dia.>') def test_toolselection_factory(): """ Test ToolSelectionStmt factory method @@ -93,22 +126,49 @@ def test_coordinatestmt_factory(): assert_equal(stmt.y, 0.4639) assert_equal(stmt.to_excellon(settings), "X9660Y4639") - - def test_coordinatestmt_dump(): """ Test CoordinateStmt to_excellon() """ lines = ['X278207Y65293', 'X243795', 'Y82528', 'Y86028', 'X251295Y81528', 'X2525Y78', 'X255Y575', 'Y52', 'X2675', 'Y575', 'X2425', 'Y52', 'X23', ] - settings = FileSettings(format=(2, 4), zero_suppression='leading', 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(): + stmt = CoordinateStmt.from_excellon('X254Y254', FileSettings()) + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 1.) + stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + stmt.to_metric() + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 25.4) + +def test_coordinatestmt_string(): + settings = FileSettings(format=(2, 4), zero_suppression='leading', + 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')) + assert_equal(stmt.count, 4) + assert_equal(stmt.xdelta, 1.5) + assert_equal(stmt.ydelta, 32) + +def test_repeatholestmt_dump(): + line = 'R4X015Y32' + stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + assert_equal(stmt.to_excellon(FileSettings()), line) + +def test_repeathole_str(): + stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings()) + assert_equal(str(stmt), '<Repeat Hole: 4 times>') def test_commentstmt_factory(): """ Test CommentStmt factory method @@ -134,6 +194,35 @@ 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_endofprogramstmt_factory(): + stmt = EndOfProgramStmt.from_excellon('M30X01Y02', FileSettings()) + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 2.) + stmt = EndOfProgramStmt.from_excellon('M30X01', FileSettings()) + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, None) + stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) + assert_equal(stmt.x, None) + assert_equal(stmt.y, 2.) + +def test_endofprogramStmt_dump(): + lines = ['M30X01Y02',] + for line in lines: + stmt = EndOfProgramStmt.from_excellon(line, FileSettings()) + assert_equal(stmt.to_excellon(FileSettings()), line) + def test_unitstmt_factory(): """ Test UnitStmt factory method @@ -295,3 +384,25 @@ def test_measmodestmt_validation(): """ assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') assert_raises(ValueError, MeasuringModeStmt, 'millimeters') + + +def test_routemode_stmt(): + stmt = RouteModeStmt() + assert_equal(stmt.to_excellon(FileSettings()), 'G00') + +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') |