From 7f75e8b9e9e338f16f215b2552db9ad9a0a50781 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Mon, 6 Oct 2014 23:54:39 -0400 Subject: add tests --- gerber/tests/test_excellon_statements.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gerber/tests/test_excellon_statements.py (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py new file mode 100644 index 0000000..3a10153 --- /dev/null +++ b/gerber/tests/test_excellon_statements.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from .tests import * +from ..excellon_statements import * + + +def test_ExcellonTool_factory(): + """ Test ExcellonTool factory method + """ + exc_line = 'T8F00S00C0.12500' + settings = {'format': (2, 5), 'zero_suppression': 'trailing', + 'units': 'inch', 'notation': 'absolute'} + tool = ExcellonTool.from_excellon(exc_line, settings) + assert_equal(tool.diameter, 0.125) + assert_equal(tool.feed_rate, 0) + assert_equal(tool.rpm, 0) + + +def test_ExcellonTool_dump(): + """ Test ExcellonTool to_gerber method + """ + exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968', + 'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800', + 'T7F00S00C0.04300', 'T8F00S00C0.12500', 'T9F00S00C0.13000', ] + settings = {'format': (2, 5), 'zero_suppression': 'trailing', + 'units': 'inch', 'notation': 'absolute'} + for line in exc_lines: + tool = ExcellonTool.from_excellon(line, settings) + assert_equal(tool.to_excellon(), line) + \ No newline at end of file -- cgit From f7c19398730d95bd4f34834ebcf66d9a68273055 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 00:16:39 -0400 Subject: add tests --- gerber/tests/test_excellon_statements.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 3a10153..49207d3 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -20,7 +20,7 @@ def test_ExcellonTool_factory(): def test_ExcellonTool_dump(): - """ Test ExcellonTool to_gerber method + """ Test ExcellonTool to_excellon() """ exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968', 'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800', @@ -30,4 +30,23 @@ def test_ExcellonTool_dump(): for line in exc_lines: tool = ExcellonTool.from_excellon(line, settings) assert_equal(tool.to_excellon(), line) - \ No newline at end of file + + +def test_ToolSelectionStmt_factory(): + """ Test ToolSelectionStmt factory method + """ + stmt = ToolSelectionStmt.from_excellon('T01') + assert_equal(stmt.tool, 1) + assert_equal(stmt.compensation_index, None) + stmt = ToolSelectionStmt.from_excellon('T0223') + assert_equal(stmt.tool, 2) + assert_equal(stmt.compensation_index, 23) + + +def test_ToolSelectionStmt_dump(): + """ Test ToolSelectionStmt to_excellon() + """ + lines = ['T01', 'T0223', 'T10', 'T09', 'T0000'] + for line in lines: + stmt = ToolSelectionStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) -- cgit From 8ac771db92633fab9aa0ff9ecc7333e6a412e577 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 09:12:46 -0400 Subject: More tests --- gerber/tests/test_excellon_statements.py | 66 ++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 49207d3..c728443 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -7,7 +7,7 @@ from .tests import * from ..excellon_statements import * -def test_ExcellonTool_factory(): +def test_excellontool_factory(): """ Test ExcellonTool factory method """ exc_line = 'T8F00S00C0.12500' @@ -19,7 +19,7 @@ def test_ExcellonTool_factory(): assert_equal(tool.rpm, 0) -def test_ExcellonTool_dump(): +def test_excellontool_dump(): """ Test ExcellonTool to_excellon() """ exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968', @@ -32,7 +32,19 @@ def test_ExcellonTool_dump(): assert_equal(tool.to_excellon(), line) -def test_ToolSelectionStmt_factory(): +def test_excellontool_order(): + settings = {'format': (2, 5), 'zero_suppression': 'trailing', + 'units': 'inch', 'notation': 'absolute'} + line = 'T8F00S00C0.12500' + tool1 = ExcellonTool.from_excellon(line, settings) + line = 'T8C0.12500F00S00' + tool2 = ExcellonTool.from_excellon(line, settings) + assert_equal(tool1.diameter, tool2.diameter) + assert_equal(tool1.feed_rate, tool2.feed_rate) + assert_equal(tool1.rpm, tool2.rpm) + + +def test_toolselection_factory(): """ Test ToolSelectionStmt factory method """ stmt = ToolSelectionStmt.from_excellon('T01') @@ -43,10 +55,56 @@ def test_ToolSelectionStmt_factory(): assert_equal(stmt.compensation_index, 23) -def test_ToolSelectionStmt_dump(): +def test_toolselection_dump(): """ Test ToolSelectionStmt to_excellon() """ lines = ['T01', 'T0223', 'T10', 'T09', 'T0000'] for line in lines: stmt = ToolSelectionStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) + + +def test_coordinatestmt_factory(): + line = 'X0278207Y0065293' + stmt = CoordinateStmt.from_excellon(line) + assert_equal(stmt.x, 2.78207) + assert_equal(stmt.y, 0.65293) + + line = 'X02945' + stmt = CoordinateStmt.from_excellon(line) + assert_equal(stmt.x, 2.945) + + line = 'Y00575' + stmt = CoordinateStmt.from_excellon(line) + assert_equal(stmt.y, 0.575) + + +def test_coordinatestmt_dump(): + lines = ['X0278207Y0065293', 'X0243795', 'Y0082528', 'Y0086028', + 'X0251295Y0081528', 'X02525Y0078', 'X0255Y00575', 'Y0052', + 'X02675', 'Y00575', 'X02425', 'Y0052', 'X023', ] + for line in lines: + stmt = CoordinateStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_commentstmt_factory(): + line = ';Layer_Color=9474304' + stmt = CommentStmt.from_excellon(line) + assert_equal(stmt.comment, line[1:]) + + line = ';FILE_FORMAT=2:5' + stmt = CommentStmt.from_excellon(line) + assert_equal(stmt.comment, line[1:]) + + line = ';TYPE=PLATED' + stmt = CommentStmt.from_excellon(line) + assert_equal(stmt.comment, line[1:]) + + +def test_commentstmt_dump(): + lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ] + for line in lines: + stmt = CommentStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + -- cgit From b971dacd3f058772326a479a562ceed0a9594deb Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 18:36:03 -0400 Subject: more tests --- gerber/tests/test_excellon_statements.py | 119 +++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index c728443..4fa2b35 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -108,3 +108,122 @@ def test_commentstmt_dump(): stmt = CommentStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) + +def test_unitstmt_factory(): + line = 'INCH,LZ' + stmt = UnitStmt.from_excellon(line) + assert_equal(stmt.units, 'inch') + assert_equal(stmt.zero_suppression, 'trailing') + + line = 'METRIC,TZ' + stmt = UnitStmt.from_excellon(line) + assert_equal(stmt.units, 'metric') + assert_equal(stmt.zero_suppression, 'leading') + + +def test_unitstmt_dump(): + lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ] + for line in lines: + stmt = UnitStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_incrementalmode_factory(): + line = 'ICI,ON' + stmt = IncrementalModeStmt.from_excellon(line) + assert_equal(stmt.mode, 'on') + + line = 'ICI,OFF' + stmt = IncrementalModeStmt.from_excellon(line) + assert_equal(stmt.mode, 'off') + + +def test_incrementalmode_dump(): + lines = ['ICI,ON', 'ICI,OFF', ] + for line in lines: + stmt = IncrementalModeStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_incrementalmode_validation(): + assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH') + + +def test_versionstmt_factory(): + line = 'VER,1' + stmt = VersionStmt.from_excellon(line) + assert_equal(stmt.version, 1) + + line = 'VER,2' + stmt = VersionStmt.from_excellon(line) + assert_equal(stmt.version, 2) + + +def test_versionstmt_dump(): + lines = ['VER,1', 'VER,2', ] + for line in lines: + stmt = VersionStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + +def test_versionstmt_validation(): + assert_raises(ValueError, VersionStmt, 3) + + +def test_formatstmt_factory(): + line = 'FMAT,1' + stmt = FormatStmt.from_excellon(line) + assert_equal(stmt.format, 1) + + line = 'FMAT,2' + stmt = FormatStmt.from_excellon(line) + assert_equal(stmt.format, 2) + + +def test_formatstmt_dump(): + lines = ['FMAT,1', 'FMAT,2', ] + for line in lines: + stmt = FormatStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_formatstmt_validation(): + assert_raises(ValueError, FormatStmt, 3) + + +def test_linktoolstmt_factory(): + line = '1/2/3/4' + stmt = LinkToolStmt.from_excellon(line) + assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + + line = '01/02/03/04' + stmt = LinkToolStmt.from_excellon(line) + assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + + +def test_linktoolstmt_dump(): + lines = ['1/2/3/4', '5/6/7', ] + for line in lines: + stmt = LinkToolStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_measuringmodestmt_factory(): + line = 'M72' + stmt = MeasuringModeStmt.from_excellon(line) + assert_equal(stmt.units, 'inch') + + line = 'M71' + stmt = MeasuringModeStmt.from_excellon(line) + assert_equal(stmt.units, 'metric') + + +def test_measuringmodestmt_dump(): + lines = ['M71', 'M72', ] + for line in lines: + stmt = MeasuringModeStmt.from_excellon(line) + assert_equal(stmt.to_excellon(), line) + + +def test_measuringmodestmt_validation(): + assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') + assert_raises(ValueError, MeasuringModeStmt, 'millimeters') -- cgit From af97dcf2a8200d9319e20d2789dbb0baa0611ba5 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 22:44:08 -0400 Subject: fix excellon render --- gerber/tests/test_excellon_statements.py | 48 +++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 4fa2b35..5e5e8dc 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -3,7 +3,7 @@ # Author: Hamilton Kibbe -from .tests import * +from .tests import assert_equal, assert_raises from ..excellon_statements import * @@ -65,6 +65,8 @@ def test_toolselection_dump(): def test_coordinatestmt_factory(): + """ Test CoordinateStmt factory method + """ line = 'X0278207Y0065293' stmt = CoordinateStmt.from_excellon(line) assert_equal(stmt.x, 2.78207) @@ -80,6 +82,8 @@ def test_coordinatestmt_factory(): def test_coordinatestmt_dump(): + """ Test CoordinateStmt to_excellon() + """ lines = ['X0278207Y0065293', 'X0243795', 'Y0082528', 'Y0086028', 'X0251295Y0081528', 'X02525Y0078', 'X0255Y00575', 'Y0052', 'X02675', 'Y00575', 'X02425', 'Y0052', 'X023', ] @@ -89,6 +93,8 @@ def test_coordinatestmt_dump(): def test_commentstmt_factory(): + """ Test CommentStmt factory method + """ line = ';Layer_Color=9474304' stmt = CommentStmt.from_excellon(line) assert_equal(stmt.comment, line[1:]) @@ -103,6 +109,8 @@ def test_commentstmt_factory(): def test_commentstmt_dump(): + """ Test CommentStmt to_excellon() + """ lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ] for line in lines: stmt = CommentStmt.from_excellon(line) @@ -110,6 +118,8 @@ def test_commentstmt_dump(): def test_unitstmt_factory(): + """ Test UnitStmt factory method + """ line = 'INCH,LZ' stmt = UnitStmt.from_excellon(line) assert_equal(stmt.units, 'inch') @@ -122,6 +132,8 @@ def test_unitstmt_factory(): def test_unitstmt_dump(): + """ Test UnitStmt to_excellon() + """ lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ] for line in lines: stmt = UnitStmt.from_excellon(line) @@ -129,6 +141,8 @@ def test_unitstmt_dump(): def test_incrementalmode_factory(): + """ Test IncrementalModeStmt factory method + """ line = 'ICI,ON' stmt = IncrementalModeStmt.from_excellon(line) assert_equal(stmt.mode, 'on') @@ -139,6 +153,8 @@ def test_incrementalmode_factory(): def test_incrementalmode_dump(): + """ Test IncrementalModeStmt to_excellon() + """ lines = ['ICI,ON', 'ICI,OFF', ] for line in lines: stmt = IncrementalModeStmt.from_excellon(line) @@ -146,10 +162,14 @@ def test_incrementalmode_dump(): def test_incrementalmode_validation(): + """ Test IncrementalModeStmt input validation + """ assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH') def test_versionstmt_factory(): + """ Test VersionStmt factory method + """ line = 'VER,1' stmt = VersionStmt.from_excellon(line) assert_equal(stmt.version, 1) @@ -160,16 +180,22 @@ def test_versionstmt_factory(): def test_versionstmt_dump(): + """ Test VersionStmt to_excellon() + """ lines = ['VER,1', 'VER,2', ] for line in lines: stmt = VersionStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) def test_versionstmt_validation(): + """ Test VersionStmt input validation + """ assert_raises(ValueError, VersionStmt, 3) def test_formatstmt_factory(): + """ Test FormatStmt factory method + """ line = 'FMAT,1' stmt = FormatStmt.from_excellon(line) assert_equal(stmt.format, 1) @@ -180,6 +206,8 @@ def test_formatstmt_factory(): def test_formatstmt_dump(): + """ Test FormatStmt to_excellon() + """ lines = ['FMAT,1', 'FMAT,2', ] for line in lines: stmt = FormatStmt.from_excellon(line) @@ -187,10 +215,14 @@ def test_formatstmt_dump(): def test_formatstmt_validation(): + """ Test FormatStmt input validation + """ assert_raises(ValueError, FormatStmt, 3) def test_linktoolstmt_factory(): + """ Test LinkToolStmt factory method + """ line = '1/2/3/4' stmt = LinkToolStmt.from_excellon(line) assert_equal(stmt.linked_tools, [1, 2, 3, 4]) @@ -201,13 +233,17 @@ def test_linktoolstmt_factory(): def test_linktoolstmt_dump(): + """ Test LinkToolStmt to_excellon() + """ lines = ['1/2/3/4', '5/6/7', ] for line in lines: stmt = LinkToolStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) -def test_measuringmodestmt_factory(): +def test_measmodestmt_factory(): + """ Test MeasuringModeStmt factory method + """ line = 'M72' stmt = MeasuringModeStmt.from_excellon(line) assert_equal(stmt.units, 'inch') @@ -217,13 +253,17 @@ def test_measuringmodestmt_factory(): assert_equal(stmt.units, 'metric') -def test_measuringmodestmt_dump(): +def test_measmodestmt_dump(): + """ Test MeasuringModeStmt to_excellon() + """ lines = ['M71', 'M72', ] for line in lines: stmt = MeasuringModeStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) -def test_measuringmodestmt_validation(): +def test_measmodestmt_validation(): + """ Test MeasuringModeStmt input validation + """ assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') assert_raises(ValueError, MeasuringModeStmt, 'millimeters') -- cgit From 18e3b87625ddb739faeddffcaed48e12db6c7e8b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 19 Oct 2014 22:23:00 -0400 Subject: Test update --- gerber/tests/test_excellon_statements.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 5e5e8dc..f2e17ee 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -5,14 +5,15 @@ from .tests import assert_equal, assert_raises from ..excellon_statements import * +from ..cam import FileSettings def test_excellontool_factory(): """ Test ExcellonTool factory method """ exc_line = 'T8F00S00C0.12500' - settings = {'format': (2, 5), 'zero_suppression': 'trailing', - 'units': 'inch', 'notation': 'absolute'} + settings = FileSettings(format=(2, 5), zero_suppression='trailing', + units='inch', notation='absolute') tool = ExcellonTool.from_excellon(exc_line, settings) assert_equal(tool.diameter, 0.125) assert_equal(tool.feed_rate, 0) @@ -25,16 +26,16 @@ def test_excellontool_dump(): exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968', 'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800', 'T7F00S00C0.04300', 'T8F00S00C0.12500', 'T9F00S00C0.13000', ] - settings = {'format': (2, 5), 'zero_suppression': 'trailing', - 'units': 'inch', 'notation': 'absolute'} + settings = FileSettings(format=(2, 5), zero_suppression='trailing', + units='inch', notation='absolute') for line in exc_lines: tool = ExcellonTool.from_excellon(line, settings) assert_equal(tool.to_excellon(), line) def test_excellontool_order(): - settings = {'format': (2, 5), 'zero_suppression': 'trailing', - 'units': 'inch', 'notation': 'absolute'} + settings = FileSettings(format=(2, 5), zero_suppression='trailing', + units='inch', notation='absolute') line = 'T8F00S00C0.12500' tool1 = ExcellonTool.from_excellon(line, settings) line = 'T8C0.12500F00S00' -- cgit From ab69ee0172353e64fbe5099a974341e88feaf24b Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 10 Nov 2014 12:24:09 -0200 Subject: Bunch of small fixes to improve Gerber read/write. --- gerber/tests/test_excellon_statements.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index f2e17ee..0e1efa6 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -23,9 +23,9 @@ def test_excellontool_factory(): def test_excellontool_dump(): """ Test ExcellonTool to_excellon() """ - exc_lines = ['T1F00S00C0.01200', 'T2F00S00C0.01500', 'T3F00S00C0.01968', - 'T4F00S00C0.02800', 'T5F00S00C0.03300', 'T6F00S00C0.03800', - 'T7F00S00C0.04300', 'T8F00S00C0.12500', 'T9F00S00C0.13000', ] + exc_lines = ['T1F0S0C0.01200', 'T2F0S0C0.01500', 'T3F0S0C0.01968', + 'T4F0S0C0.02800', 'T5F0S0C0.03300', 'T6F0S0C0.03800', + 'T7F0S0C0.04300', 'T8F0S0C0.12500', 'T9F0S0C0.13000', ] settings = FileSettings(format=(2, 5), zero_suppression='trailing', units='inch', notation='absolute') for line in exc_lines: -- cgit From 137c73f3e42281de67bde8f1c0b16938f5b8aeeb Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Wed, 14 Jan 2015 14:33:00 -0200 Subject: Many additions to Excellon parsing/creation. CAUTION: the original code used zero_suppression flags in the opposite sense as Gerber functions. This patch changes it to behave just like Gerber code. * Add metric/inch conversion support * Add settings context variable to to_gerber just like Gerber code. * Add some missing Excellon values. Tests are not entirely updated. --- gerber/tests/test_excellon_statements.py | 35 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 0e1efa6..13733f8 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -68,18 +68,31 @@ def test_toolselection_dump(): def test_coordinatestmt_factory(): """ Test CoordinateStmt factory method """ + settings = FileSettings(format=(2, 5), zero_suppression='trailing', + units='inch', notation='absolute') + line = 'X0278207Y0065293' - stmt = CoordinateStmt.from_excellon(line) + stmt = CoordinateStmt.from_excellon(line, settings) assert_equal(stmt.x, 2.78207) assert_equal(stmt.y, 0.65293) - line = 'X02945' - stmt = CoordinateStmt.from_excellon(line) - assert_equal(stmt.x, 2.945) + # line = 'X02945' + # stmt = CoordinateStmt.from_excellon(line) + # assert_equal(stmt.x, 2.945) + + # line = 'Y00575' + # stmt = CoordinateStmt.from_excellon(line) + # assert_equal(stmt.y, 0.575) + + settings = FileSettings(format=(2, 4), zero_suppression='leading', + units='inch', notation='absolute') + + line = 'X9660Y4639' + stmt = CoordinateStmt.from_excellon(line, settings) + assert_equal(stmt.x, 0.9660) + assert_equal(stmt.y, 0.4639) + assert_equal(stmt.to_excellon(settings), "X9660Y4639") - line = 'Y00575' - stmt = CoordinateStmt.from_excellon(line) - assert_equal(stmt.y, 0.575) def test_coordinatestmt_dump(): @@ -88,9 +101,13 @@ def test_coordinatestmt_dump(): lines = ['X0278207Y0065293', 'X0243795', 'Y0082528', 'Y0086028', 'X0251295Y0081528', 'X02525Y0078', 'X0255Y00575', 'Y0052', 'X02675', 'Y00575', 'X02425', 'Y0052', 'X023', ] + + settings = FileSettings(format=(2, 4), zero_suppression='leading', + units='inch', notation='absolute') + for line in lines: - stmt = CoordinateStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + stmt = CoordinateStmt.from_excellon(line, settings) + assert_equal(stmt.to_excellon(settings), line) def test_commentstmt_factory(): -- cgit From d5157c1d076360e3702a910f119b9fc44ff76df5 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 23 Jan 2015 13:05:25 -0500 Subject: Fix tests for leading zero suppression --- gerber/tests/test_excellon_statements.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 13733f8..4c3201b 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -23,9 +23,9 @@ def test_excellontool_factory(): def test_excellontool_dump(): """ Test ExcellonTool to_excellon() """ - exc_lines = ['T1F0S0C0.01200', 'T2F0S0C0.01500', 'T3F0S0C0.01968', - 'T4F0S0C0.02800', 'T5F0S0C0.03300', 'T6F0S0C0.03800', - 'T7F0S0C0.04300', 'T8F0S0C0.12500', 'T9F0S0C0.13000', ] + exc_lines = ['T01F0S0C0.01200', 'T02F0S0C0.01500', 'T03F0S0C0.01968', + 'T04F0S0C0.02800', 'T05F0S0C0.03300', 'T06F0S0C0.03800', + 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', ] settings = FileSettings(format=(2, 5), zero_suppression='trailing', units='inch', notation='absolute') for line in exc_lines: @@ -98,9 +98,9 @@ def test_coordinatestmt_factory(): def test_coordinatestmt_dump(): """ Test CoordinateStmt to_excellon() """ - lines = ['X0278207Y0065293', 'X0243795', 'Y0082528', 'Y0086028', - 'X0251295Y0081528', 'X02525Y0078', 'X0255Y00575', 'Y0052', - 'X02675', 'Y00575', 'X02425', 'Y0052', 'X023', ] + 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') -- cgit From b495d51354eff7b858dbbd41740865eba7f39100 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 25 Jan 2015 14:19:48 -0500 Subject: Changed zeros/zero suppression conventions to match file format specs --- gerber/tests/test_excellon_statements.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 4c3201b..2e508ff 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -141,12 +141,22 @@ def test_unitstmt_factory(): line = 'INCH,LZ' stmt = UnitStmt.from_excellon(line) assert_equal(stmt.units, 'inch') - assert_equal(stmt.zero_suppression, 'trailing') + assert_equal(stmt.zeros, 'leading') + + line = 'INCH,TZ' + stmt = UnitStmt.from_excellon(line) + assert_equal(stmt.units, 'inch') + assert_equal(stmt.zeros, 'trailing') + + line = 'METRIC,LZ' + stmt = UnitStmt.from_excellon(line) + assert_equal(stmt.units, 'metric') + assert_equal(stmt.zeros, 'leading') line = 'METRIC,TZ' stmt = UnitStmt.from_excellon(line) assert_equal(stmt.units, 'metric') - assert_equal(stmt.zero_suppression, 'leading') + assert_equal(stmt.zeros, 'trailing') def test_unitstmt_dump(): -- cgit From 5cf1fa74b42eb8feaab23078bef6f31f6d647c33 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 15 Feb 2015 02:20:02 -0500 Subject: Tests and bugfixes --- gerber/tests/test_excellon_statements.py | 129 ++++++++++++++++++++++++++++--- 1 file changed, 120 insertions(+), 9 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') 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), '') + tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 0.125}) + assert_equal(str(tool), '') 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), '') + + +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), '') 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), '') + +def test_unknownstmt_dump(): + stmt = UnknownStmt('TEST') + assert_equal(stmt.to_excellon(FileSettings()), 'TEST') -- cgit From 288ac27084b47166ac662402ea340d0aa25d8f56 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 04:31:23 -0500 Subject: Get unit conversion working for Gerber/Excellon files Started operations module for file operations/transforms --- gerber/tests/test_excellon_statements.py | 72 ++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 35bd045..4daeb4b 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -3,7 +3,7 @@ # Author: Hamilton Kibbe -from .tests import assert_equal, assert_raises +from .tests import assert_equal, assert_not_equal, assert_raises from ..excellon_statements import * from ..cam import FileSettings @@ -65,19 +65,34 @@ def test_excellontool_order(): assert_equal(tool1.rpm, tool2.rpm) def test_excellontool_conversion(): - tool = ExcellonTool.from_dict(FileSettings(), {'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(), {'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.to_inch() + assert_equal(tool.diameter, 25.4) + 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}) assert_equal(str(tool), '') tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 0.125}) assert_equal(str(tool), '') +def test_excellontool_equality(): + 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}) + assert_not_equal(t, t1) def test_toolselection_factory(): """ Test ToolSelectionStmt factory method """ @@ -166,6 +181,19 @@ def test_repeatholestmt_dump(): stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) assert_equal(stmt.to_excellon(FileSettings()), line) +def test_repeatholestmt_conversion(): + line = 'R4X0254Y254' + stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + stmt.to_inch() + assert_equal(stmt.xdelta, 0.1) + assert_equal(stmt.ydelta, 1.) + + line = 'R4X01Y1' + stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + 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), '') @@ -223,6 +251,16 @@ def test_endofprogramStmt_dump(): stmt = EndOfProgramStmt.from_excellon(line, FileSettings()) assert_equal(stmt.to_excellon(FileSettings()), line) +def test_endofprogramstmt_conversion(): + stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', FileSettings()) + stmt.to_inch() + assert_equal(stmt.x, 0.1) + assert_equal(stmt.y, 1.0) + + stmt = EndOfProgramStmt.from_excellon('M30X01Y1', FileSettings()) + stmt.to_metric() + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 254.) def test_unitstmt_factory(): """ Test UnitStmt factory method @@ -256,6 +294,14 @@ 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() + assert_equal(stmt.units, 'inch') + + stmt = UnitStmt.from_excellon('INCH,TZ') + stmt.to_metric() + assert_equal(stmt.units, 'metric') def test_incrementalmode_factory(): """ Test IncrementalModeStmt factory method @@ -385,6 +431,18 @@ 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) + assert_equal(stmt.units, 'inch') + stmt.to_metric() + assert_equal(stmt.units, 'metric') + + line = 'M71' + stmt = MeasuringModeStmt.from_excellon(line) + assert_equal(stmt.units, 'metric') + stmt.to_inch() + assert_equal(stmt.units, 'inch') def test_routemode_stmt(): stmt = RouteModeStmt() @@ -406,3 +464,11 @@ def test_unknownstmt(): def test_unknownstmt_dump(): stmt = UnknownStmt('TEST') assert_equal(stmt.to_excellon(FileSettings()), 'TEST') + + +def test_excellontstmt(): + """ Smoke test ExcellonStatement + """ + stmt = ExcellonStatement() + stmt.to_inch() + stmt.to_metric() \ No newline at end of file -- cgit From 5966d7830bda7f37ed5ddcc1bfccb93e7f780eaa Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 23:13:23 -0500 Subject: Add offset operation --- gerber/tests/test_excellon_statements.py | 56 +++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 4daeb4b..eb30db1 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -12,6 +12,14 @@ def test_excellon_statement_implementation(): assert_raises(NotImplementedError, stmt.from_excellon, None) assert_raises(NotImplementedError, stmt.to_excellon) +def test_excellontstmt(): + """ Smoke test ExcellonStatement + """ + stmt = ExcellonStatement() + stmt.to_inch() + stmt.to_metric() + stmt.offset() + def test_excellontool_factory(): """ Test ExcellonTool factory methods """ @@ -26,7 +34,7 @@ def test_excellontool_factory(): 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) @@ -93,6 +101,7 @@ def test_excellontool_equality(): assert_equal(t, t1) 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 """ @@ -103,7 +112,6 @@ def test_toolselection_factory(): assert_equal(stmt.tool, 2) assert_equal(stmt.compensation_index, 23) - def test_toolselection_dump(): """ Test ToolSelectionStmt to_excellon() """ @@ -112,7 +120,6 @@ def test_toolselection_dump(): stmt = ToolSelectionStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) - def test_coordinatestmt_factory(): """ Test CoordinateStmt factory method """ @@ -163,6 +170,19 @@ def test_coordinatestmt_conversion(): 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) + assert_equal(stmt.x, 2.) + assert_equal(stmt.y, 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') @@ -229,7 +249,7 @@ def test_header_begin_stmt(): 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), '%') @@ -262,6 +282,18 @@ def test_endofprogramstmt_conversion(): 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) + assert_equal(stmt.x, 2.) + assert_equal(stmt.y, 1.) + stmt.offset(0,1) + assert_equal(stmt.x, 2.) + assert_equal(stmt.y, 2.) + def test_unitstmt_factory(): """ Test UnitStmt factory method """ @@ -447,28 +479,20 @@ def test_measmodestmt_conversion(): 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), '') - + def test_unknownstmt_dump(): stmt = UnknownStmt('TEST') assert_equal(stmt.to_excellon(FileSettings()), 'TEST') - - -def test_excellontstmt(): - """ Smoke test ExcellonStatement - """ - stmt = ExcellonStatement() - stmt.to_inch() - stmt.to_metric() \ No newline at end of file -- cgit From b9b20a9644ca7b87493ca5786e2a25ecab132b75 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Wed, 18 Mar 2015 03:38:52 -0300 Subject: Fix Excellon repeat command --- gerber/tests/test_excellon_statements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index eb30db1..2da7c15 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -216,7 +216,7 @@ def test_repeatholestmt_conversion(): def test_repeathole_str(): stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings()) - assert_equal(str(stmt), '') + assert_equal(str(stmt), '') def test_commentstmt_factory(): """ Test CommentStmt factory method -- cgit From 21d963d244cbc762a736527b25cd8e82ff147f25 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 27 Apr 2015 03:58:39 -0300 Subject: Allow 3 digits on Excellon tool selection Fritzing uses more than 2 digits for tool in their Excellons. To comply with that, I check specifically for 3 or less digits and use as tool number, more than that we treat as the standard (2 for tool and 2 for compensation index) --- gerber/tests/test_excellon_statements.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 2da7c15..ada5194 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -111,6 +111,9 @@ def test_toolselection_factory(): stmt = ToolSelectionStmt.from_excellon('T0223') assert_equal(stmt.tool, 2) assert_equal(stmt.compensation_index, 23) + stmt = ToolSelectionStmt.from_excellon('T042') + assert_equal(stmt.tool, 42) + assert_equal(stmt.compensation_index, None) def test_toolselection_dump(): """ Test ToolSelectionStmt to_excellon() -- cgit From 8ec3077be988681bbbafcef18ea3a2f84dd61b2b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 16 May 2015 09:45:34 -0400 Subject: Add checks to ensure statement unit conversions are idempotent --- gerber/tests/test_excellon_statements.py | 116 ++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 10 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index ada5194..1e8ef91 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -150,7 +150,13 @@ def test_coordinatestmt_factory(): assert_equal(stmt.x, 0.9660) 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() """ @@ -164,11 +170,40 @@ def test_coordinatestmt_dump(): assert_equal(stmt.to_excellon(settings), line) def test_coordinatestmt_conversion(): - stmt = CoordinateStmt.from_excellon('X254Y254', FileSettings()) + + settings = FileSettings() + settings.units = 'metric' + stmt = CoordinateStmt.from_excellon('X254Y254', settings) + + #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.) - stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + + #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 + 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 stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 25.4) @@ -194,10 +229,14 @@ def test_coordinatestmt_string(): def test_repeathole_stmt_factory(): - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading')) + 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')) + assert_equal(stmt.units, 'metric') def test_repeatholestmt_dump(): line = 'R4X015Y32' @@ -206,13 +245,40 @@ def test_repeatholestmt_dump(): def test_repeatholestmt_conversion(): line = 'R4X0254Y254' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #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 stmt.to_inch() assert_equal(stmt.xdelta, 0.1) assert_equal(stmt.ydelta, 1.) line = 'R4X01Y1' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings.units = 'inch' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #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 stmt.to_metric() assert_equal(stmt.xdelta, 25.4) assert_equal(stmt.ydelta, 254.) @@ -258,12 +324,16 @@ def test_rewindstop_stmt(): assert_equal(stmt.to_excellon(None), '%') def test_endofprogramstmt_factory(): - stmt = EndOfProgramStmt.from_excellon('M30X01Y02', FileSettings()) + settings = FileSettings(units='inch') + stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, 2.) - stmt = EndOfProgramStmt.from_excellon('M30X01', FileSettings()) + assert_equal(stmt.units, 'inch') + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X01', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, None) + assert_equal(stmt.units, 'metric') stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) assert_equal(stmt.x, None) assert_equal(stmt.y, 2.) @@ -275,12 +345,38 @@ def test_endofprogramStmt_dump(): assert_equal(stmt.to_excellon(FileSettings()), line) def test_endofprogramstmt_conversion(): - stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings) + #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 stmt.to_inch() assert_equal(stmt.x, 0.1) assert_equal(stmt.y, 1.0) - stmt = EndOfProgramStmt.from_excellon('M30X01Y1', FileSettings()) + settings.units = 'inch' + stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings) + + #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 stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 254.) -- cgit From 9ca75f991a240b0ea233382ff23264a009b0324e Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Fri, 13 Nov 2015 03:31:32 -0200 Subject: Improve Excellon parsing coverage Add some not so used codes that were generating unknown stmt. --- gerber/tests/test_excellon_statements.py | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 1e8ef91..2f0ef10 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -123,6 +123,28 @@ 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 + """ + stmt = ZAxisInfeedRateStmt.from_excellon('F01') + assert_equal(stmt.rate, 1) + stmt = ZAxisInfeedRateStmt.from_excellon('F2') + assert_equal(stmt.rate, 2) + stmt = ZAxisInfeedRateStmt.from_excellon('F03') + assert_equal(stmt.rate, 3) + +def test_z_axis_infeed_rate_dump(): + """ Test ZAxisInfeedRateStmt to_excellon() + """ + inputs = [ + ('F01', 'F01'), + ('F2', 'F02'), + ('F00003', 'F03') + ] + for input_rate, expected_output in inputs: + stmt = ZAxisInfeedRateStmt.from_excellon(input_rate) + assert_equal(stmt.to_excellon(), expected_output) + def test_coordinatestmt_factory(): """ Test CoordinateStmt factory method """ @@ -323,6 +345,30 @@ 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) @@ -579,6 +625,10 @@ 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') -- cgit From 5476da8aa3f4ee424f56f4f2491e7af1c4b7b758 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: 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 --- gerber/tests/test_excellon_statements.py | 173 ++++++++++++++++++++----------- 1 file changed, 113 insertions(+), 60 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') 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), '') - 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), '') + 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), '') 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), '') + 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), '') + def test_unknownstmt_dump(): stmt = UnknownStmt('TEST') assert_equal(stmt.to_excellon(FileSettings()), 'TEST') -- cgit From ef589a064015de3a1ce6487dbb56b99332673e9d Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Tue, 26 Nov 2019 00:37:41 -0300 Subject: Migrate to pytest (#111) * Migrate to pytest All tests were update to use pytest. Tests were alse black formatted. Eventually all code will be black formatted but need to merge some PRs first. --- gerber/tests/test_excellon_statements.py | 616 ++++++++++++++++--------------- 1 file changed, 325 insertions(+), 291 deletions(-) (limited to 'gerber/tests/test_excellon_statements.py') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 8e6e06e..41fe294 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -3,15 +3,15 @@ # Author: Hamilton Kibbe -from .tests import assert_equal, assert_not_equal, assert_raises +import pytest 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) + pytest.raises(NotImplementedError, stmt.from_excellon, None) + pytest.raises(NotImplementedError, stmt.to_excellon) def test_excellontstmt(): @@ -26,154 +26,173 @@ def test_excellontstmt(): def test_excellontool_factory(): """ Test ExcellonTool factory methods """ - exc_line = 'T8F01B02S00003H04Z05C0.12500' - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') + 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, 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} + assert tool.number == 8 + assert tool.diameter == 0.125 + assert tool.feed_rate == 1 + assert tool.retract_rate == 2 + assert tool.rpm == 3 + assert tool.max_hit_count == 4 + assert 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) + assert tool.number == 8 + assert tool.diameter == 0.125 + assert tool.feed_rate == 1 + assert tool.retract_rate == 2 + assert tool.rpm == 3 + assert tool.max_hit_count == 4 + assert tool.depth_offset == 5 def test_excellontool_dump(): """ Test ExcellonTool to_excellon() """ - exc_lines = ['T01F0S0C0.01200', 'T02F0S0C0.01500', 'T03F0S0C0.01968', - 'T04F0S0C0.02800', 'T05F0S0C0.03300', 'T06F0S0C0.03800', - 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', - 'T08B01F02H03S00003C0.12500Z04', 'T01F0S300.999C0.01200'] - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') + exc_lines = [ + "T01F0S0C0.01200", + "T02F0S0C0.01500", + "T03F0S0C0.01968", + "T04F0S0C0.02800", + "T05F0S0C0.03300", + "T06F0S0C0.03800", + "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: tool = ExcellonTool.from_excellon(line, settings) - assert_equal(tool.to_excellon(), line) + assert tool.to_excellon() == line def test_excellontool_order(): - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') - line = 'T8F00S00C0.12500' + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) + line = "T8F00S00C0.12500" tool1 = ExcellonTool.from_excellon(line, settings) - line = 'T8C0.12500F00S00' + line = "T8C0.12500F00S00" tool2 = ExcellonTool.from_excellon(line, settings) - assert_equal(tool1.diameter, tool2.diameter) - assert_equal(tool1.feed_rate, tool2.feed_rate) - assert_equal(tool1.rpm, tool2.rpm) + assert tool1.diameter == tool2.diameter + assert tool1.feed_rate == tool2.feed_rate + assert 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.}) + assert tool.diameter == 1.0 + tool = ExcellonTool.from_dict( + FileSettings(units="inch"), {"number": 8, "diameter": 1.0} + ) tool.to_metric() - assert_equal(tool.diameter, 25.4) + assert 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.}) + assert tool.diameter == 25.4 + tool = ExcellonTool.from_dict( + FileSettings(units="metric"), {"number": 8, "diameter": 1.0} + ) tool.to_metric() - assert_equal(tool.diameter, 1.) + assert tool.diameter == 1.0 def test_excellontool_repr(): - tool = ExcellonTool.from_dict(FileSettings(), - {'number': 8, 'diameter': 0.125}) - assert_equal(str(tool), '') - tool = ExcellonTool.from_dict(FileSettings(units='metric'), - {'number': 8, 'diameter': 0.125}) - assert_equal(str(tool), '') + tool = ExcellonTool.from_dict(FileSettings(), {"number": 8, "diameter": 0.125}) + assert str(tool) == "" + tool = ExcellonTool.from_dict( + FileSettings(units="metric"), {"number": 8, "diameter": 0.125} + ) + assert str(tool) == "" def test_excellontool_equality(): - t = 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 t == t1 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}) - assert_not_equal(t, t1) + FileSettings(units="metric"), {"number": 8, "diameter": 0.125} + ) + assert t != t1 def test_toolselection_factory(): """ Test ToolSelectionStmt factory method """ - stmt = ToolSelectionStmt.from_excellon('T01') - assert_equal(stmt.tool, 1) - assert_equal(stmt.compensation_index, None) - stmt = ToolSelectionStmt.from_excellon('T0223') - assert_equal(stmt.tool, 2) - assert_equal(stmt.compensation_index, 23) - stmt = ToolSelectionStmt.from_excellon('T042') - assert_equal(stmt.tool, 42) - assert_equal(stmt.compensation_index, None) + stmt = ToolSelectionStmt.from_excellon("T01") + assert stmt.tool == 1 + assert stmt.compensation_index == None + stmt = ToolSelectionStmt.from_excellon("T0223") + assert stmt.tool == 2 + assert stmt.compensation_index == 23 + stmt = ToolSelectionStmt.from_excellon("T042") + assert stmt.tool == 42 + assert stmt.compensation_index == None def test_toolselection_dump(): """ Test ToolSelectionStmt to_excellon() """ - lines = ['T01', 'T0223', 'T10', 'T09', 'T0000'] + lines = ["T01", "T0223", "T10", "T09", "T0000"] for line in lines: stmt = ToolSelectionStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_z_axis_infeed_rate_factory(): """ Test ZAxisInfeedRateStmt factory method """ - stmt = ZAxisInfeedRateStmt.from_excellon('F01') - assert_equal(stmt.rate, 1) - stmt = ZAxisInfeedRateStmt.from_excellon('F2') - assert_equal(stmt.rate, 2) - stmt = ZAxisInfeedRateStmt.from_excellon('F03') - assert_equal(stmt.rate, 3) + stmt = ZAxisInfeedRateStmt.from_excellon("F01") + assert stmt.rate == 1 + stmt = ZAxisInfeedRateStmt.from_excellon("F2") + assert stmt.rate == 2 + stmt = ZAxisInfeedRateStmt.from_excellon("F03") + assert stmt.rate == 3 def test_z_axis_infeed_rate_dump(): """ Test ZAxisInfeedRateStmt to_excellon() """ - inputs = [ - ('F01', 'F01'), - ('F2', 'F02'), - ('F00003', 'F03') - ] + inputs = [("F01", "F01"), ("F2", "F02"), ("F00003", "F03")] for input_rate, expected_output in inputs: stmt = ZAxisInfeedRateStmt.from_excellon(input_rate) - assert_equal(stmt.to_excellon(), expected_output) + assert 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') + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) - line = 'X0278207Y0065293' + line = "X0278207Y0065293" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.x, 2.78207) - assert_equal(stmt.y, 0.65293) + assert stmt.x == 2.78207 + assert stmt.y == 0.65293 # line = 'X02945' # stmt = CoordinateStmt.from_excellon(line) @@ -183,518 +202,533 @@ def test_coordinatestmt_factory(): # stmt = CoordinateStmt.from_excellon(line) # assert_equal(stmt.y, 0.575) - settings = FileSettings(format=(2, 4), zero_suppression='leading', - units='inch', notation='absolute') + settings = FileSettings( + format=(2, 4), zero_suppression="leading", units="inch", notation="absolute" + ) - line = 'X9660Y4639' + line = "X9660Y4639" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.x, 0.9660) - assert_equal(stmt.y, 0.4639) - assert_equal(stmt.to_excellon(settings), "X9660Y4639") - assert_equal(stmt.units, 'inch') + assert stmt.x == 0.9660 + assert stmt.y == 0.4639 + assert stmt.to_excellon(settings) == "X9660Y4639" + assert stmt.units == "inch" - settings.units = 'metric' + settings.units = "metric" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" 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') + 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) + assert stmt.to_excellon(settings) == line def test_coordinatestmt_conversion(): settings = FileSettings() - settings.units = 'metric' - stmt = CoordinateStmt.from_excellon('X254Y254', settings) + settings.units = "metric" + stmt = CoordinateStmt.from_excellon("X254Y254", settings) # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.x == 25.4 + assert stmt.y == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.units == "inch" + assert stmt.x == 1.0 + assert stmt.y == 1.0 # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.x == 1.0 + assert stmt.y == 1.0 - settings.units = 'inch' - stmt = CoordinateStmt.from_excellon('X01Y01', settings) + settings.units = "inch" + stmt = CoordinateStmt.from_excellon("X01Y01", settings) # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.x == 1.0 + assert stmt.y == 1.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.units == "metric" + assert stmt.x == 25.4 + assert stmt.y == 25.4 # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.x == 25.4 + assert stmt.y == 25.4 def test_coordinatestmt_offset(): - stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + stmt = CoordinateStmt.from_excellon("X01Y01", FileSettings()) stmt.offset() - assert_equal(stmt.x, 1) - assert_equal(stmt.y, 1) + assert stmt.x == 1 + assert stmt.y == 1 stmt.offset(1, 0) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 1.) + assert stmt.x == 2.0 + assert stmt.y == 1.0 stmt.offset(0, 1) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 2.) + assert stmt.x == 2.0 + assert stmt.y == 2.0 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), '') + settings = FileSettings( + format=(2, 4), zero_suppression="leading", units="inch", notation="absolute" + ) + stmt = CoordinateStmt.from_excellon("X9660Y4639", settings) + assert str(stmt) == "" def test_repeathole_stmt_factory(): - 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="inch") + ) + assert stmt.count == 4 + assert stmt.xdelta == 1.5 + assert stmt.ydelta == 32 + assert stmt.units == "inch" - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', - FileSettings(zeros='leading', - units='metric')) - assert_equal(stmt.units, 'metric') + stmt = RepeatHoleStmt.from_excellon( + "R0004X015Y32", FileSettings(zeros="leading", units="metric") + ) + assert stmt.units == "metric" def test_repeatholestmt_dump(): - line = 'R4X015Y32' + line = "R4X015Y32" stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) - assert_equal(stmt.to_excellon(FileSettings()), line) + assert stmt.to_excellon(FileSettings()) == line def test_repeatholestmt_conversion(): - line = 'R4X0254Y254' + line = "R4X0254Y254" settings = FileSettings() - settings.units = 'metric' + settings.units = "metric" stmt = RepeatHoleStmt.from_excellon(line, settings) # No effect stmt.to_metric() - assert_equal(stmt.xdelta, 2.54) - assert_equal(stmt.ydelta, 25.4) + assert stmt.xdelta == 2.54 + assert stmt.ydelta == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.xdelta, 0.1) - assert_equal(stmt.ydelta, 1.) + assert stmt.units == "inch" + assert stmt.xdelta == 0.1 + assert stmt.ydelta == 1.0 # no effect stmt.to_inch() - assert_equal(stmt.xdelta, 0.1) - assert_equal(stmt.ydelta, 1.) + assert stmt.xdelta == 0.1 + assert stmt.ydelta == 1.0 - line = 'R4X01Y1' - settings.units = 'inch' + line = "R4X01Y1" + settings.units = "inch" stmt = RepeatHoleStmt.from_excellon(line, settings) # no effect stmt.to_inch() - assert_equal(stmt.xdelta, 1.) - assert_equal(stmt.ydelta, 10.) + assert stmt.xdelta == 1.0 + assert stmt.ydelta == 10.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.xdelta, 25.4) - assert_equal(stmt.ydelta, 254.) + assert stmt.units == "metric" + assert stmt.xdelta == 25.4 + assert stmt.ydelta == 254.0 # No effect stmt.to_metric() - assert_equal(stmt.xdelta, 25.4) - assert_equal(stmt.ydelta, 254.) + assert stmt.xdelta == 25.4 + assert stmt.ydelta == 254.0 def test_repeathole_str(): - stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings()) - assert_equal(str(stmt), '') + stmt = RepeatHoleStmt.from_excellon("R4X015Y32", FileSettings()) + assert str(stmt) == "" def test_commentstmt_factory(): """ Test CommentStmt factory method """ - line = ';Layer_Color=9474304' + line = ";Layer_Color=9474304" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] - line = ';FILE_FORMAT=2:5' + line = ";FILE_FORMAT=2:5" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] - line = ';TYPE=PLATED' + line = ";TYPE=PLATED" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] def test_commentstmt_dump(): """ Test CommentStmt to_excellon() """ - lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ] + lines = [";Layer_Color=9474304", ";FILE_FORMAT=2:5", ";TYPE=PLATED"] for line in lines: stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_header_begin_stmt(): stmt = HeaderBeginStmt() - assert_equal(stmt.to_excellon(None), 'M48') + assert stmt.to_excellon(None) == "M48" def test_header_end_stmt(): stmt = HeaderEndStmt() - assert_equal(stmt.to_excellon(None), 'M95') + assert stmt.to_excellon(None) == "M95" def test_rewindstop_stmt(): stmt = RewindStopStmt() - assert_equal(stmt.to_excellon(None), '%') + assert stmt.to_excellon(None) == "%" def test_z_axis_rout_position_stmt(): stmt = ZAxisRoutPositionStmt() - assert_equal(stmt.to_excellon(None), 'M15') + assert stmt.to_excellon(None) == "M15" def test_retract_with_clamping_stmt(): stmt = RetractWithClampingStmt() - assert_equal(stmt.to_excellon(None), 'M16') + assert stmt.to_excellon(None) == "M16" def test_retract_without_clamping_stmt(): stmt = RetractWithoutClampingStmt() - assert_equal(stmt.to_excellon(None), 'M17') + assert stmt.to_excellon(None) == "M17" def test_cutter_compensation_off_stmt(): stmt = CutterCompensationOffStmt() - assert_equal(stmt.to_excellon(None), 'G40') + assert stmt.to_excellon(None) == "G40" def test_cutter_compensation_left_stmt(): stmt = CutterCompensationLeftStmt() - assert_equal(stmt.to_excellon(None), 'G41') + assert stmt.to_excellon(None) == "G41" def test_cutter_compensation_right_stmt(): stmt = CutterCompensationRightStmt() - assert_equal(stmt.to_excellon(None), 'G42') + assert stmt.to_excellon(None) == "G42" def test_endofprogramstmt_factory(): - settings = FileSettings(units='inch') - stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings) - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 2.) - assert_equal(stmt.units, 'inch') - settings.units = 'metric' - stmt = EndOfProgramStmt.from_excellon('M30X01', settings) - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, None) - assert_equal(stmt.units, 'metric') - stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) - assert_equal(stmt.x, None) - assert_equal(stmt.y, 2.) + settings = FileSettings(units="inch") + stmt = EndOfProgramStmt.from_excellon("M30X01Y02", settings) + assert stmt.x == 1.0 + assert stmt.y == 2.0 + assert stmt.units == "inch" + settings.units = "metric" + stmt = EndOfProgramStmt.from_excellon("M30X01", settings) + assert stmt.x == 1.0 + assert stmt.y == None + assert stmt.units == "metric" + stmt = EndOfProgramStmt.from_excellon("M30Y02", FileSettings()) + assert stmt.x == None + assert stmt.y == 2.0 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) + assert stmt.to_excellon(FileSettings()) == line def test_endofprogramstmt_conversion(): settings = FileSettings() - settings.units = 'metric' - stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings) + settings.units = "metric" + stmt = EndOfProgramStmt.from_excellon("M30X0254Y254", settings) # No effect stmt.to_metric() - assert_equal(stmt.x, 2.54) - assert_equal(stmt.y, 25.4) + assert stmt.x == 2.54 + assert stmt.y == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.x, 0.1) - assert_equal(stmt.y, 1.0) + assert stmt.units == "inch" + assert stmt.x == 0.1 + assert stmt.y == 1.0 # No effect stmt.to_inch() - assert_equal(stmt.x, 0.1) - assert_equal(stmt.y, 1.0) + assert stmt.x == 0.1 + assert stmt.y == 1.0 - settings.units = 'inch' - stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings) + settings.units = "inch" + stmt = EndOfProgramStmt.from_excellon("M30X01Y1", settings) # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 10.0) + assert stmt.x == 1.0 + assert stmt.y == 10.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 254.) + assert stmt.units == "metric" + assert stmt.x == 25.4 + assert stmt.y == 254.0 # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 254.) + assert stmt.x == 25.4 + assert stmt.y == 254.0 def test_endofprogramstmt_offset(): stmt = EndOfProgramStmt(1, 1) stmt.offset() - assert_equal(stmt.x, 1) - assert_equal(stmt.y, 1) + assert stmt.x == 1 + assert stmt.y == 1 stmt.offset(1, 0) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 1.) + assert stmt.x == 2.0 + assert stmt.y == 1.0 stmt.offset(0, 1) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 2.) + assert stmt.x == 2.0 + assert stmt.y == 2.0 def test_unitstmt_factory(): """ Test UnitStmt factory method """ - line = 'INCH,LZ' + line = "INCH,LZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') - assert_equal(stmt.zeros, 'leading') + assert stmt.units == "inch" + assert stmt.zeros == "leading" - line = 'INCH,TZ' + line = "INCH,TZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') - assert_equal(stmt.zeros, 'trailing') + assert stmt.units == "inch" + assert stmt.zeros == "trailing" - line = 'METRIC,LZ' + line = "METRIC,LZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') - assert_equal(stmt.zeros, 'leading') + assert stmt.units == "metric" + assert stmt.zeros == "leading" - line = 'METRIC,TZ' + line = "METRIC,TZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') - assert_equal(stmt.zeros, 'trailing') + assert stmt.units == "metric" + assert stmt.zeros == "trailing" def test_unitstmt_dump(): """ Test UnitStmt to_excellon() """ - lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ] + lines = ["INCH,LZ", "INCH,TZ", "METRIC,LZ", "METRIC,TZ"] for line in lines: stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_unitstmt_conversion(): - stmt = UnitStmt.from_excellon('METRIC,TZ') + stmt = UnitStmt.from_excellon("METRIC,TZ") stmt.to_inch() - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" - stmt = UnitStmt.from_excellon('INCH,TZ') + stmt = UnitStmt.from_excellon("INCH,TZ") stmt.to_metric() - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" def test_incrementalmode_factory(): """ Test IncrementalModeStmt factory method """ - line = 'ICI,ON' + line = "ICI,ON" stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.mode, 'on') + assert stmt.mode == "on" - line = 'ICI,OFF' + line = "ICI,OFF" stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.mode, 'off') + assert stmt.mode == "off" def test_incrementalmode_dump(): """ Test IncrementalModeStmt to_excellon() """ - lines = ['ICI,ON', 'ICI,OFF', ] + lines = ["ICI,ON", "ICI,OFF"] for line in lines: stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_incrementalmode_validation(): """ Test IncrementalModeStmt input validation """ - assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH') + pytest.raises(ValueError, IncrementalModeStmt, "OFF-ISH") def test_versionstmt_factory(): """ Test VersionStmt factory method """ - line = 'VER,1' + line = "VER,1" stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.version, 1) + assert stmt.version == 1 - line = 'VER,2' + line = "VER,2" stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.version, 2) + assert stmt.version == 2 def test_versionstmt_dump(): """ Test VersionStmt to_excellon() """ - lines = ['VER,1', 'VER,2', ] + lines = ["VER,1", "VER,2"] for line in lines: stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_versionstmt_validation(): """ Test VersionStmt input validation """ - assert_raises(ValueError, VersionStmt, 3) + pytest.raises(ValueError, VersionStmt, 3) def test_formatstmt_factory(): """ Test FormatStmt factory method """ - line = 'FMAT,1' + line = "FMAT,1" stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.format, 1) + assert stmt.format == 1 - line = 'FMAT,2' + line = "FMAT,2" stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.format, 2) + assert stmt.format == 2 def test_formatstmt_dump(): """ Test FormatStmt to_excellon() """ - lines = ['FMAT,1', 'FMAT,2', ] + lines = ["FMAT,1", "FMAT,2"] for line in lines: stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_formatstmt_validation(): """ Test FormatStmt input validation """ - assert_raises(ValueError, FormatStmt, 3) + pytest.raises(ValueError, FormatStmt, 3) def test_linktoolstmt_factory(): """ Test LinkToolStmt factory method """ - line = '1/2/3/4' + line = "1/2/3/4" stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + assert stmt.linked_tools == [1, 2, 3, 4] - line = '01/02/03/04' + line = "01/02/03/04" stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + assert stmt.linked_tools == [1, 2, 3, 4] def test_linktoolstmt_dump(): """ Test LinkToolStmt to_excellon() """ - lines = ['1/2/3/4', '5/6/7', ] + lines = ["1/2/3/4", "5/6/7"] for line in lines: stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_measmodestmt_factory(): """ Test MeasuringModeStmt factory method """ - line = 'M72' + line = "M72" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" - line = 'M71' + line = "M71" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" def test_measmodestmt_dump(): """ Test MeasuringModeStmt to_excellon() """ - lines = ['M71', 'M72', ] + lines = ["M71", "M72"] for line in lines: stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_measmodestmt_validation(): """ Test MeasuringModeStmt input validation """ - assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') - assert_raises(ValueError, MeasuringModeStmt, 'millimeters') + pytest.raises(ValueError, MeasuringModeStmt.from_excellon, "M70") + pytest.raises(ValueError, MeasuringModeStmt, "millimeters") def test_measmodestmt_conversion(): - line = 'M72' + line = "M72" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" stmt.to_metric() - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" - line = 'M71' + line = "M71" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" stmt.to_inch() - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" def test_routemode_stmt(): stmt = RouteModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G00') + assert stmt.to_excellon(FileSettings()) == "G00" def test_linearmode_stmt(): stmt = LinearModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G01') + assert stmt.to_excellon(FileSettings()) == "G01" def test_drillmode_stmt(): stmt = DrillModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G05') + assert stmt.to_excellon(FileSettings()) == "G05" def test_absolutemode_stmt(): stmt = AbsoluteModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G90') + assert stmt.to_excellon(FileSettings()) == "G90" def test_unknownstmt(): - stmt = UnknownStmt('TEST') - assert_equal(stmt.stmt, 'TEST') - assert_equal(str(stmt), '') + stmt = UnknownStmt("TEST") + assert stmt.stmt == "TEST" + assert str(stmt) == "" def test_unknownstmt_dump(): - stmt = UnknownStmt('TEST') - assert_equal(stmt.to_excellon(FileSettings()), 'TEST') + stmt = UnknownStmt("TEST") + assert stmt.to_excellon(FileSettings()) == "TEST" -- cgit