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_am_statements.py | 65 +++-- gerber/tests/test_cam.py | 26 +- gerber/tests/test_common.py | 8 +- gerber/tests/test_excellon.py | 10 +- gerber/tests/test_excellon_statements.py | 173 ++++++++----- gerber/tests/test_gerber_statements.py | 145 ++++++++--- gerber/tests/test_ipc356.py | 29 ++- gerber/tests/test_layers.py | 2 +- gerber/tests/test_primitives.py | 427 ++++++++++++++++++------------- gerber/tests/test_rs274x.py | 9 +- gerber/tests/test_utils.py | 25 +- gerber/tests/tests.py | 3 +- 12 files changed, 598 insertions(+), 324 deletions(-) (limited to 'gerber/tests') diff --git a/gerber/tests/test_am_statements.py b/gerber/tests/test_am_statements.py index 0cee13d..8c95e6a 100644 --- a/gerber/tests/test_am_statements.py +++ b/gerber/tests/test_am_statements.py @@ -7,6 +7,7 @@ from .tests import * from ..am_statements import * from ..am_statements import inch, metric + def test_AMPrimitive_ctor(): for exposure in ('on', 'off', 'ON', 'OFF'): for code in (0, 1, 2, 4, 5, 6, 7, 20, 21, 22): @@ -20,13 +21,13 @@ def test_AMPrimitive_validation(): assert_raises(ValueError, AMPrimitive, 0, 'exposed') assert_raises(ValueError, AMPrimitive, 3, 'off') + def test_AMPrimitive_conversion(): p = AMPrimitive(4, 'on') assert_raises(NotImplementedError, p.to_inch) assert_raises(NotImplementedError, p.to_metric) - def test_AMCommentPrimitive_ctor(): c = AMCommentPrimitive(0, ' This is a comment *') assert_equal(c.code, 0) @@ -47,6 +48,7 @@ def test_AMCommentPrimitive_dump(): c = AMCommentPrimitive(0, 'Rectangle with rounded corners.') assert_equal(c.to_gerber(), '0 Rectangle with rounded corners. *') + def test_AMCommentPrimitive_conversion(): c = AMCommentPrimitive(0, 'Rectangle with rounded corners.') ci = c @@ -56,6 +58,7 @@ def test_AMCommentPrimitive_conversion(): assert_equal(c, ci) assert_equal(c, cm) + def test_AMCommentPrimitive_string(): c = AMCommentPrimitive(0, 'Test Comment') assert_equal(str(c), '') @@ -83,7 +86,7 @@ def test_AMCirclePrimitive_factory(): assert_equal(c.code, 1) assert_equal(c.exposure, 'off') assert_equal(c.diameter, 5) - assert_equal(c.position, (0,0)) + assert_equal(c.position, (0, 0)) def test_AMCirclePrimitive_dump(): @@ -92,6 +95,7 @@ def test_AMCirclePrimitive_dump(): c = AMCirclePrimitive(1, 'on', 5, (0, 0)) assert_equal(c.to_gerber(), '1,1,5,0,0*') + def test_AMCirclePrimitive_conversion(): c = AMCirclePrimitive(1, 'off', 25.4, (25.4, 0)) c.to_inch() @@ -103,8 +107,11 @@ def test_AMCirclePrimitive_conversion(): assert_equal(c.diameter, 25.4) assert_equal(c.position, (25.4, 0)) + def test_AMVectorLinePrimitive_validation(): - assert_raises(ValueError, AMVectorLinePrimitive, 3, 'on', 0.1, (0,0), (3.3, 5.4), 0) + assert_raises(ValueError, AMVectorLinePrimitive, + 3, 'on', 0.1, (0, 0), (3.3, 5.4), 0) + def test_AMVectorLinePrimitive_factory(): l = AMVectorLinePrimitive.from_gerber('20,1,0.9,0,0.45,12,0.45,0*') @@ -115,26 +122,32 @@ def test_AMVectorLinePrimitive_factory(): assert_equal(l.end, (12, 0.45)) assert_equal(l.rotation, 0) + def test_AMVectorLinePrimitive_dump(): l = AMVectorLinePrimitive.from_gerber('20,1,0.9,0,0.45,12,0.45,0*') assert_equal(l.to_gerber(), '20,1,0.9,0.0,0.45,12.0,0.45,0.0*') + def test_AMVectorLinePrimtive_conversion(): - l = AMVectorLinePrimitive(20, 'on', 25.4, (0,0), (25.4, 25.4), 0) + l = AMVectorLinePrimitive(20, 'on', 25.4, (0, 0), (25.4, 25.4), 0) l.to_inch() assert_equal(l.width, 1) assert_equal(l.start, (0, 0)) assert_equal(l.end, (1, 1)) - l = AMVectorLinePrimitive(20, 'on', 1, (0,0), (1, 1), 0) + l = AMVectorLinePrimitive(20, 'on', 1, (0, 0), (1, 1), 0) l.to_metric() assert_equal(l.width, 25.4) assert_equal(l.start, (0, 0)) assert_equal(l.end, (25.4, 25.4)) + def test_AMOutlinePrimitive_validation(): - assert_raises(ValueError, AMOutlinePrimitive, 7, 'on', (0,0), [(3.3, 5.4), (4.0, 5.4), (0, 0)], 0) - assert_raises(ValueError, AMOutlinePrimitive, 4, 'on', (0,0), [(3.3, 5.4), (4.0, 5.4), (0, 1)], 0) + assert_raises(ValueError, AMOutlinePrimitive, 7, 'on', + (0, 0), [(3.3, 5.4), (4.0, 5.4), (0, 0)], 0) + assert_raises(ValueError, AMOutlinePrimitive, 4, 'on', + (0, 0), [(3.3, 5.4), (4.0, 5.4), (0, 1)], 0) + def test_AMOutlinePrimitive_factory(): o = AMOutlinePrimitive.from_gerber('4,1,3,0,0,3,3,3,0,0,0,0*') @@ -144,12 +157,15 @@ def test_AMOutlinePrimitive_factory(): assert_equal(o.points, [(3, 3), (3, 0), (0, 0)]) assert_equal(o.rotation, 0) + def test_AMOUtlinePrimitive_dump(): o = AMOutlinePrimitive(4, 'on', (0, 0), [(3, 3), (3, 0), (0, 0)], 0) assert_equal(o.to_gerber(), '4,1,3,0,0,3,3,3,0,0,0,0*') + def test_AMOutlinePrimitive_conversion(): - o = AMOutlinePrimitive(4, 'on', (0, 0), [(25.4, 25.4), (25.4, 0), (0, 0)], 0) + o = AMOutlinePrimitive( + 4, 'on', (0, 0), [(25.4, 25.4), (25.4, 0), (0, 0)], 0) o.to_inch() assert_equal(o.start_point, (0, 0)) assert_equal(o.points, ((1., 1.), (1., 0.), (0., 0.))) @@ -165,6 +181,7 @@ def test_AMPolygonPrimitive_validation(): assert_raises(ValueError, AMPolygonPrimitive, 5, 'on', 2, (3.3, 5.4), 3, 0) assert_raises(ValueError, AMPolygonPrimitive, 5, 'on', 13, (3.3, 5.4), 3, 0) + def test_AMPolygonPrimitive_factory(): p = AMPolygonPrimitive.from_gerber('5,1,3,3.3,5.4,3,0') assert_equal(p.code, 5) @@ -174,10 +191,12 @@ def test_AMPolygonPrimitive_factory(): assert_equal(p.diameter, 3) assert_equal(p.rotation, 0) + def test_AMPolygonPrimitive_dump(): p = AMPolygonPrimitive(5, 'on', 3, (3.3, 5.4), 3, 0) assert_equal(p.to_gerber(), '5,1,3,3.3,5.4,3,0*') + def test_AMPolygonPrimitive_conversion(): p = AMPolygonPrimitive(5, 'off', 3, (25.4, 0), 25.4, 0) p.to_inch() @@ -191,7 +210,9 @@ def test_AMPolygonPrimitive_conversion(): def test_AMMoirePrimitive_validation(): - assert_raises(ValueError, AMMoirePrimitive, 7, (0, 0), 5.1, 0.2, 0.4, 6, 0.1, 6.1, 0) + assert_raises(ValueError, AMMoirePrimitive, 7, + (0, 0), 5.1, 0.2, 0.4, 6, 0.1, 6.1, 0) + def test_AMMoirePrimitive_factory(): m = AMMoirePrimitive.from_gerber('6,0,0,5,0.5,0.5,2,0.1,6,0*') @@ -205,10 +226,12 @@ def test_AMMoirePrimitive_factory(): assert_equal(m.crosshair_length, 6) assert_equal(m.rotation, 0) + def test_AMMoirePrimitive_dump(): m = AMMoirePrimitive.from_gerber('6,0,0,5,0.5,0.5,2,0.1,6,0*') assert_equal(m.to_gerber(), '6,0,0,5.0,0.5,0.5,2,0.1,6.0,0.0*') + def test_AMMoirePrimitive_conversion(): m = AMMoirePrimitive(6, (25.4, 25.4), 25.4, 25.4, 25.4, 6, 25.4, 25.4, 0) m.to_inch() @@ -228,10 +251,12 @@ def test_AMMoirePrimitive_conversion(): assert_equal(m.crosshair_thickness, 25.4) assert_equal(m.crosshair_length, 25.4) + def test_AMThermalPrimitive_validation(): assert_raises(ValueError, AMThermalPrimitive, 8, (0.0, 0.0), 7, 5, 0.2) assert_raises(TypeError, AMThermalPrimitive, 7, (0.0, '0'), 7, 5, 0.2) + def test_AMThermalPrimitive_factory(): t = AMThermalPrimitive.from_gerber('7,0,0,7,6,0.2*') assert_equal(t.code, 7) @@ -240,10 +265,12 @@ def test_AMThermalPrimitive_factory(): assert_equal(t.inner_diameter, 6) assert_equal(t.gap, 0.2) + def test_AMThermalPrimitive_dump(): t = AMThermalPrimitive.from_gerber('7,0,0,7,6,0.2*') assert_equal(t.to_gerber(), '7,0,0,7.0,6.0,0.2*') + def test_AMThermalPrimitive_conversion(): t = AMThermalPrimitive(7, (25.4, 25.4), 25.4, 25.4, 25.4) t.to_inch() @@ -261,7 +288,9 @@ def test_AMThermalPrimitive_conversion(): def test_AMCenterLinePrimitive_validation(): - assert_raises(ValueError, AMCenterLinePrimitive, 22, 1, 0.2, 0.5, (0, 0), 0) + assert_raises(ValueError, AMCenterLinePrimitive, + 22, 1, 0.2, 0.5, (0, 0), 0) + def test_AMCenterLinePrimtive_factory(): l = AMCenterLinePrimitive.from_gerber('21,1,6.8,1.2,3.4,0.6,0*') @@ -272,10 +301,12 @@ def test_AMCenterLinePrimtive_factory(): assert_equal(l.center, (3.4, 0.6)) assert_equal(l.rotation, 0) + def test_AMCenterLinePrimitive_dump(): l = AMCenterLinePrimitive.from_gerber('21,1,6.8,1.2,3.4,0.6,0*') assert_equal(l.to_gerber(), '21,1,6.8,1.2,3.4,0.6,0.0*') + def test_AMCenterLinePrimitive_conversion(): l = AMCenterLinePrimitive(21, 'on', 25.4, 25.4, (25.4, 25.4), 0) l.to_inch() @@ -289,8 +320,11 @@ def test_AMCenterLinePrimitive_conversion(): assert_equal(l.height, 25.4) assert_equal(l.center, (25.4, 25.4)) + def test_AMLowerLeftLinePrimitive_validation(): - assert_raises(ValueError, AMLowerLeftLinePrimitive, 23, 1, 0.2, 0.5, (0, 0), 0) + assert_raises(ValueError, AMLowerLeftLinePrimitive, + 23, 1, 0.2, 0.5, (0, 0), 0) + def test_AMLowerLeftLinePrimtive_factory(): l = AMLowerLeftLinePrimitive.from_gerber('22,1,6.8,1.2,3.4,0.6,0*') @@ -301,10 +335,12 @@ def test_AMLowerLeftLinePrimtive_factory(): assert_equal(l.lower_left, (3.4, 0.6)) assert_equal(l.rotation, 0) + def test_AMLowerLeftLinePrimitive_dump(): l = AMLowerLeftLinePrimitive.from_gerber('22,1,6.8,1.2,3.4,0.6,0*') assert_equal(l.to_gerber(), '22,1,6.8,1.2,3.4,0.6,0.0*') + def test_AMLowerLeftLinePrimitive_conversion(): l = AMLowerLeftLinePrimitive(22, 'on', 25.4, 25.4, (25.4, 25.4), 0) l.to_inch() @@ -318,24 +354,23 @@ def test_AMLowerLeftLinePrimitive_conversion(): assert_equal(l.height, 25.4) assert_equal(l.lower_left, (25.4, 25.4)) + def test_AMUnsupportPrimitive(): u = AMUnsupportPrimitive.from_gerber('Test') assert_equal(u.primitive, 'Test') u = AMUnsupportPrimitive('Test') assert_equal(u.to_gerber(), 'Test') + def test_AMUnsupportPrimitive_smoketest(): u = AMUnsupportPrimitive.from_gerber('Test') u.to_inch() u.to_metric() - def test_inch(): assert_equal(inch(25.4), 1) + def test_metric(): assert_equal(metric(1), 25.4) - - - diff --git a/gerber/tests/test_cam.py b/gerber/tests/test_cam.py index 00a8285..2f0a905 100644 --- a/gerber/tests/test_cam.py +++ b/gerber/tests/test_cam.py @@ -54,17 +54,20 @@ def test_filesettings_dict_assign(): assert_equal(fs.zero_suppression, 'leading') assert_equal(fs.format, (1, 2)) + def test_camfile_init(): """ Smoke test CamFile test """ cf = CamFile() + def test_camfile_settings(): """ Test CamFile Default Settings """ cf = CamFile() assert_equal(cf.settings, FileSettings()) + def test_bounds_override_smoketest(): cf = CamFile() cf.bounds @@ -89,7 +92,7 @@ def test_zeros(): assert_equal(fs.zeros, 'trailing') assert_equal(fs.zero_suppression, 'leading') - fs.zeros= 'leading' + fs.zeros = 'leading' assert_equal(fs.zeros, 'leading') assert_equal(fs.zero_suppression, 'trailing') @@ -113,12 +116,19 @@ def test_zeros(): def test_filesettings_validation(): """ Test FileSettings constructor argument validation """ - assert_raises(ValueError, FileSettings, 'absolute-ish', 'inch', None, (2, 5), None) - assert_raises(ValueError, FileSettings, 'absolute', 'degrees kelvin', None, (2, 5), None) - assert_raises(ValueError, FileSettings, 'absolute', 'inch', 'leading', (2, 5), 'leading') - assert_raises(ValueError, FileSettings, 'absolute', 'inch', 'following', (2, 5), None) - assert_raises(ValueError, FileSettings, 'absolute', 'inch', None, (2, 5), 'following') - assert_raises(ValueError, FileSettings, 'absolute', 'inch', None, (2, 5, 6), None) + assert_raises(ValueError, FileSettings, 'absolute-ish', + 'inch', None, (2, 5), None) + assert_raises(ValueError, FileSettings, 'absolute', + 'degrees kelvin', None, (2, 5), None) + assert_raises(ValueError, FileSettings, 'absolute', + 'inch', 'leading', (2, 5), 'leading') + assert_raises(ValueError, FileSettings, 'absolute', + 'inch', 'following', (2, 5), None) + assert_raises(ValueError, FileSettings, 'absolute', + 'inch', None, (2, 5), 'following') + assert_raises(ValueError, FileSettings, 'absolute', + 'inch', None, (2, 5, 6), None) + def test_key_validation(): fs = FileSettings() @@ -129,5 +139,3 @@ def test_key_validation(): assert_raises(ValueError, fs.__setitem__, 'zero_suppression', 'following') assert_raises(ValueError, fs.__setitem__, 'zeros', 'following') assert_raises(ValueError, fs.__setitem__, 'format', (2, 5, 6)) - - diff --git a/gerber/tests/test_common.py b/gerber/tests/test_common.py index 5991e5e..357ed18 100644 --- a/gerber/tests/test_common.py +++ b/gerber/tests/test_common.py @@ -12,9 +12,10 @@ import os NCDRILL_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ncdrill.DRD') + 'resources/ncdrill.DRD') TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), - 'resources/top_copper.GTL') + 'resources/top_copper.GTL') + def test_file_type_detection(): """ Test file type detection @@ -38,6 +39,3 @@ def test_file_type_validation(): """ Test file format validation """ assert_raises(ParseError, read, 'LICENSE') - - - diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index a9a33c7..e7c77c6 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -13,6 +13,7 @@ from .tests import * NCDRILL_FILE = os.path.join(os.path.dirname(__file__), 'resources/ncdrill.DRD') + def test_format_detection(): """ Test file type detection """ @@ -75,10 +76,11 @@ def test_conversion(): for statement in ncdrill_inch.statements: statement.to_metric() - for m_tool, i_tool in zip(iter(ncdrill.tools.values()), iter(ncdrill_inch.tools.values())): + for m_tool, i_tool in zip(iter(ncdrill.tools.values()), + iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) - for m, i in zip(ncdrill.primitives,inch_primitives): + for m, i in zip(ncdrill.primitives, inch_primitives): assert_equal(m, i) @@ -187,12 +189,10 @@ def test_parse_incremental_position(): p = ExcellonParser(FileSettings(notation='incremental')) p._parse_line('X01Y01') p._parse_line('X01Y01') - assert_equal(p.pos, [2.,2.]) + assert_equal(p.pos, [2., 2.]) def test_parse_unknown(): p = ExcellonParser(FileSettings()) p._parse_line('Not A Valid Statement') assert_equal(p.statements[0].stmt, 'Not A Valid Statement') - - 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') diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index 79ce76b..c1985e6 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -7,6 +7,7 @@ from .tests import * from ..gerber_statements import * from ..cam import FileSettings + def test_Statement_smoketest(): stmt = Statement('Test') assert_equal(stmt.type, 'Test') @@ -16,7 +17,8 @@ def test_Statement_smoketest(): assert_in('units=inch', str(stmt)) stmt.to_metric() stmt.offset(1, 1) - assert_in('type=Test',str(stmt)) + assert_in('type=Test', str(stmt)) + def test_FSParamStmt_factory(): """ Test FSParamStruct factory @@ -35,6 +37,7 @@ def test_FSParamStmt_factory(): assert_equal(fs.notation, 'incremental') assert_equal(fs.format, (2, 7)) + def test_FSParamStmt(): """ Test FSParamStmt initialization """ @@ -48,6 +51,7 @@ def test_FSParamStmt(): assert_equal(stmt.notation, notation) assert_equal(stmt.format, fmt) + def test_FSParamStmt_dump(): """ Test FSParamStmt to_gerber() """ @@ -62,16 +66,20 @@ def test_FSParamStmt_dump(): settings = FileSettings(zero_suppression='leading', notation='absolute') assert_equal(fs.to_gerber(settings), '%FSLAX25Y25*%') + def test_FSParamStmt_string(): """ Test FSParamStmt.__str__() """ stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} fs = FSParamStmt.from_dict(stmt) - assert_equal(str(fs), '') + assert_equal(str(fs), + '') stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '25'} fs = FSParamStmt.from_dict(stmt) - assert_equal(str(fs), '') + assert_equal(str(fs), + '') + def test_MOParamStmt_factory(): """ Test MOParamStruct factory @@ -94,6 +102,7 @@ def test_MOParamStmt_factory(): stmt = {'param': 'MO', 'mo': 'degrees kelvin'} assert_raises(ValueError, MOParamStmt.from_dict, stmt) + def test_MOParamStmt(): """ Test MOParamStmt initialization """ @@ -106,6 +115,7 @@ def test_MOParamStmt(): stmt = MOParamStmt(param, mode) assert_equal(stmt.mode, mode) + def test_MOParamStmt_dump(): """ Test MOParamStmt to_gerber() """ @@ -117,6 +127,7 @@ def test_MOParamStmt_dump(): mo = MOParamStmt.from_dict(stmt) assert_equal(mo.to_gerber(), '%MOMM*%') + def test_MOParamStmt_conversion(): stmt = {'param': 'MO', 'mo': 'MM'} mo = MOParamStmt.from_dict(stmt) @@ -128,6 +139,7 @@ def test_MOParamStmt_conversion(): mo.to_metric() assert_equal(mo.mode, 'metric') + def test_MOParamStmt_string(): """ Test MOParamStmt.__str__() """ @@ -139,6 +151,7 @@ def test_MOParamStmt_string(): mo = MOParamStmt.from_dict(stmt) assert_equal(str(mo), '') + def test_IPParamStmt_factory(): """ Test IPParamStruct factory """ @@ -150,6 +163,7 @@ def test_IPParamStmt_factory(): ip = IPParamStmt.from_dict(stmt) assert_equal(ip.ip, 'negative') + def test_IPParamStmt(): """ Test IPParamStmt initialization """ @@ -159,6 +173,7 @@ def test_IPParamStmt(): assert_equal(stmt.param, param) assert_equal(stmt.ip, ip) + def test_IPParamStmt_dump(): """ Test IPParamStmt to_gerber() """ @@ -170,6 +185,7 @@ def test_IPParamStmt_dump(): ip = IPParamStmt.from_dict(stmt) assert_equal(ip.to_gerber(), '%IPNEG*%') + def test_IPParamStmt_string(): stmt = {'param': 'IP', 'ip': 'POS'} ip = IPParamStmt.from_dict(stmt) @@ -179,22 +195,26 @@ def test_IPParamStmt_string(): ip = IPParamStmt.from_dict(stmt) assert_equal(str(ip), '') + def test_IRParamStmt_factory(): stmt = {'param': 'IR', 'angle': '45'} ir = IRParamStmt.from_dict(stmt) assert_equal(ir.param, 'IR') assert_equal(ir.angle, 45) + def test_IRParamStmt_dump(): stmt = {'param': 'IR', 'angle': '45'} ir = IRParamStmt.from_dict(stmt) assert_equal(ir.to_gerber(), '%IR45*%') + def test_IRParamStmt_string(): stmt = {'param': 'IR', 'angle': '45'} ir = IRParamStmt.from_dict(stmt) assert_equal(str(ir), '') + def test_OFParamStmt_factory(): """ Test OFParamStmt factory """ @@ -203,6 +223,7 @@ def test_OFParamStmt_factory(): assert_equal(of.a, 0.1234567) assert_equal(of.b, 0.1234567) + def test_OFParamStmt(): """ Test IPParamStmt initialization """ @@ -213,6 +234,7 @@ def test_OFParamStmt(): assert_equal(stmt.a, val) assert_equal(stmt.b, val) + def test_OFParamStmt_dump(): """ Test OFParamStmt to_gerber() """ @@ -220,10 +242,11 @@ def test_OFParamStmt_dump(): of = OFParamStmt.from_dict(stmt) assert_equal(of.to_gerber(), '%OFA0.12345B0.12345*%') + def test_OFParamStmt_conversion(): stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} of = OFParamStmt.from_dict(stmt) - of.units='metric' + of.units = 'metric' # No effect of.to_metric() @@ -235,7 +258,7 @@ def test_OFParamStmt_conversion(): assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) - #No effect + # No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) @@ -244,7 +267,7 @@ def test_OFParamStmt_conversion(): of = OFParamStmt.from_dict(stmt) of.units = 'inch' - #No effect + # No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) @@ -254,11 +277,12 @@ def test_OFParamStmt_conversion(): assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) - #No effect + # No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) + def test_OFParamStmt_offset(): s = OFParamStmt('OF', 0, 0) s.offset(1, 0) @@ -268,6 +292,7 @@ def test_OFParamStmt_offset(): assert_equal(s.a, 1.) assert_equal(s.b, 1.) + def test_OFParamStmt_string(): """ Test OFParamStmt __str__ """ @@ -275,6 +300,7 @@ def test_OFParamStmt_string(): of = OFParamStmt.from_dict(stmt) assert_equal(str(of), '') + def test_SFParamStmt_factory(): stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} sf = SFParamStmt.from_dict(stmt) @@ -282,18 +308,20 @@ def test_SFParamStmt_factory(): assert_equal(sf.a, 1.4) assert_equal(sf.b, 0.9) + def test_SFParamStmt_dump(): stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} sf = SFParamStmt.from_dict(stmt) assert_equal(sf.to_gerber(), '%SFA1.4B0.9*%') + def test_SFParamStmt_conversion(): stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} of = SFParamStmt.from_dict(stmt) of.units = 'metric' of.to_metric() - #No effect + # No effect assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) @@ -302,7 +330,7 @@ def test_SFParamStmt_conversion(): assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) - #No effect + # No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) @@ -311,7 +339,7 @@ def test_SFParamStmt_conversion(): of = SFParamStmt.from_dict(stmt) of.units = 'inch' - #No effect + # No effect of.to_inch() assert_equal(of.a, 0.1) assert_equal(of.b, 1.0) @@ -321,11 +349,12 @@ def test_SFParamStmt_conversion(): assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) - #No effect + # No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) + def test_SFParamStmt_offset(): s = SFParamStmt('OF', 0, 0) s.offset(1, 0) @@ -335,11 +364,13 @@ def test_SFParamStmt_offset(): assert_equal(s.a, 1.) assert_equal(s.b, 1.) + def test_SFParamStmt_string(): stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} sf = SFParamStmt.from_dict(stmt) assert_equal(str(sf), '') + def test_LPParamStmt_factory(): """ Test LPParamStmt factory """ @@ -351,6 +382,7 @@ def test_LPParamStmt_factory(): lp = LPParamStmt.from_dict(stmt) assert_equal(lp.lp, 'dark') + def test_LPParamStmt_dump(): """ Test LPParamStmt to_gerber() """ @@ -362,6 +394,7 @@ def test_LPParamStmt_dump(): lp = LPParamStmt.from_dict(stmt) assert_equal(lp.to_gerber(), '%LPD*%') + def test_LPParamStmt_string(): """ Test LPParamStmt.__str__() """ @@ -373,6 +406,7 @@ def test_LPParamStmt_string(): lp = LPParamStmt.from_dict(stmt) assert_equal(str(lp), '') + def test_AMParamStmt_factory(): name = 'DONUTVAR' macro = ( @@ -387,7 +421,7 @@ def test_AMParamStmt_factory(): 7,0,0,7,6,0.2,0* 8,THIS IS AN UNSUPPORTED PRIMITIVE* ''') - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) s.build() assert_equal(len(s.primitives), 10) assert_true(isinstance(s.primitives[0], AMCommentPrimitive)) @@ -401,15 +435,16 @@ def test_AMParamStmt_factory(): assert_true(isinstance(s.primitives[8], AMThermalPrimitive)) assert_true(isinstance(s.primitives[9], AMUnsupportPrimitive)) + def testAMParamStmt_conversion(): name = 'POLYGON' macro = '5,1,8,25.4,25.4,25.4,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) s.build() s.units = 'metric' - #No effect + # No effect s.to_metric() assert_equal(s.primitives[0].position, (25.4, 25.4)) assert_equal(s.primitives[0].diameter, 25.4) @@ -419,17 +454,17 @@ def testAMParamStmt_conversion(): assert_equal(s.primitives[0].position, (1., 1.)) assert_equal(s.primitives[0].diameter, 1.) - #No effect + # No effect s.to_inch() assert_equal(s.primitives[0].position, (1., 1.)) assert_equal(s.primitives[0].diameter, 1.) macro = '5,1,8,1,1,1,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) s.build() s.units = 'inch' - #No effect + # No effect s.to_inch() assert_equal(s.primitives[0].position, (1., 1.)) assert_equal(s.primitives[0].diameter, 1.) @@ -439,42 +474,48 @@ def testAMParamStmt_conversion(): assert_equal(s.primitives[0].position, (25.4, 25.4)) assert_equal(s.primitives[0].diameter, 25.4) - #No effect + # No effect s.to_metric() assert_equal(s.primitives[0].position, (25.4, 25.4)) assert_equal(s.primitives[0].diameter, 25.4) + def test_AMParamStmt_dump(): name = 'POLYGON' macro = '5,1,8,25.4,25.4,25.4,0.0' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) s.build() assert_equal(s.to_gerber(), '%AMPOLYGON*5,1,8,25.4,25.4,25.4,0.0*%') + def test_AMParamStmt_string(): name = 'POLYGON' macro = '5,1,8,25.4,25.4,25.4,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) + s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) s.build() assert_equal(str(s), '') + def test_ASParamStmt_factory(): stmt = {'param': 'AS', 'mode': 'AXBY'} s = ASParamStmt.from_dict(stmt) assert_equal(s.param, 'AS') assert_equal(s.mode, 'AXBY') + def test_ASParamStmt_dump(): stmt = {'param': 'AS', 'mode': 'AXBY'} s = ASParamStmt.from_dict(stmt) assert_equal(s.to_gerber(), '%ASAXBY*%') + def test_ASParamStmt_string(): stmt = {'param': 'AS', 'mode': 'AXBY'} s = ASParamStmt.from_dict(stmt) assert_equal(str(s), '') + def test_INParamStmt_factory(): """ Test INParamStmt factory """ @@ -482,6 +523,7 @@ def test_INParamStmt_factory(): inp = INParamStmt.from_dict(stmt) assert_equal(inp.name, 'test') + def test_INParamStmt_dump(): """ Test INParamStmt to_gerber() """ @@ -489,11 +531,13 @@ def test_INParamStmt_dump(): inp = INParamStmt.from_dict(stmt) assert_equal(inp.to_gerber(), '%INtest*%') + def test_INParamStmt_string(): stmt = {'param': 'IN', 'name': 'test'} inp = INParamStmt.from_dict(stmt) assert_equal(str(inp), '') + def test_LNParamStmt_factory(): """ Test LNParamStmt factory """ @@ -501,6 +545,7 @@ def test_LNParamStmt_factory(): lnp = LNParamStmt.from_dict(stmt) assert_equal(lnp.name, 'test') + def test_LNParamStmt_dump(): """ Test LNParamStmt to_gerber() """ @@ -508,11 +553,13 @@ def test_LNParamStmt_dump(): lnp = LNParamStmt.from_dict(stmt) assert_equal(lnp.to_gerber(), '%LNtest*%') + def test_LNParamStmt_string(): stmt = {'param': 'LN', 'name': 'test'} lnp = LNParamStmt.from_dict(stmt) assert_equal(str(lnp), '') + def test_comment_stmt(): """ Test comment statement """ @@ -520,31 +567,37 @@ def test_comment_stmt(): assert_equal(stmt.type, 'COMMENT') assert_equal(stmt.comment, 'A comment') + def test_comment_stmt_dump(): """ Test CommentStmt to_gerber() """ stmt = CommentStmt('A comment') assert_equal(stmt.to_gerber(), 'G04A comment*') + def test_comment_stmt_string(): stmt = CommentStmt('A comment') assert_equal(str(stmt), '') + def test_eofstmt(): """ Test EofStmt """ stmt = EofStmt() assert_equal(stmt.type, 'EOF') + def test_eofstmt_dump(): """ Test EofStmt to_gerber() """ stmt = EofStmt() assert_equal(stmt.to_gerber(), 'M02*') + def test_eofstmt_string(): assert_equal(str(EofStmt()), '') + def test_quadmodestmt_factory(): """ Test QuadrantModeStmt.from_gerber() """ @@ -557,6 +610,7 @@ def test_quadmodestmt_factory(): stmt = QuadrantModeStmt.from_gerber(line) assert_equal(stmt.mode, 'multi-quadrant') + def test_quadmodestmt_validation(): """ Test QuadrantModeStmt input validation """ @@ -564,6 +618,7 @@ def test_quadmodestmt_validation(): assert_raises(ValueError, QuadrantModeStmt.from_gerber, line) assert_raises(ValueError, QuadrantModeStmt, 'quadrant-ful') + def test_quadmodestmt_dump(): """ Test QuadrantModeStmt.to_gerber() """ @@ -571,6 +626,7 @@ def test_quadmodestmt_dump(): stmt = QuadrantModeStmt.from_gerber(line) assert_equal(stmt.to_gerber(), line) + def test_regionmodestmt_factory(): """ Test RegionModeStmt.from_gerber() """ @@ -583,6 +639,7 @@ def test_regionmodestmt_factory(): stmt = RegionModeStmt.from_gerber(line) assert_equal(stmt.mode, 'off') + def test_regionmodestmt_validation(): """ Test RegionModeStmt input validation """ @@ -590,6 +647,7 @@ def test_regionmodestmt_validation(): assert_raises(ValueError, RegionModeStmt.from_gerber, line) assert_raises(ValueError, RegionModeStmt, 'off-ish') + def test_regionmodestmt_dump(): """ Test RegionModeStmt.to_gerber() """ @@ -597,6 +655,7 @@ def test_regionmodestmt_dump(): stmt = RegionModeStmt.from_gerber(line) assert_equal(stmt.to_gerber(), line) + def test_unknownstmt(): """ Test UnknownStmt """ @@ -605,6 +664,7 @@ def test_unknownstmt(): assert_equal(stmt.type, 'UNKNOWN') assert_equal(stmt.line, line) + def test_unknownstmt_dump(): """ Test UnknownStmt.to_gerber() """ @@ -613,15 +673,17 @@ def test_unknownstmt_dump(): stmt = UnknownStmt(line) assert_equal(stmt.to_gerber(), line) + def test_statement_string(): """ Test Statement.__str__() """ stmt = Statement('PARAM') assert_in('type=PARAM', str(stmt)) - stmt.test='PASS' + stmt.test = 'PASS' assert_in('test=PASS', str(stmt)) assert_in('type=PARAM', str(stmt)) + def test_ADParamStmt_factory(): """ Test ADParamStmt factory """ @@ -653,12 +715,14 @@ def test_ADParamStmt_factory(): assert_equal(ad.shape, 'R') assert_equal(ad.modifiers, [(1.42, 1.24)]) + def test_ADParamStmt_conversion(): - stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '25.4X25.4,25.4X25.4'} + stmt = {'param': 'AD', 'd': 0, 'shape': 'C', + 'modifiers': '25.4X25.4,25.4X25.4'} ad = ADParamStmt.from_dict(stmt) ad.units = 'metric' - #No effect + # No effect ad.to_metric() assert_equal(ad.modifiers[0], (25.4, 25.4)) assert_equal(ad.modifiers[1], (25.4, 25.4)) @@ -668,7 +732,7 @@ def test_ADParamStmt_conversion(): assert_equal(ad.modifiers[0], (1., 1.)) assert_equal(ad.modifiers[1], (1., 1.)) - #No effect + # No effect ad.to_inch() assert_equal(ad.modifiers[0], (1., 1.)) assert_equal(ad.modifiers[1], (1., 1.)) @@ -677,7 +741,7 @@ def test_ADParamStmt_conversion(): ad = ADParamStmt.from_dict(stmt) ad.units = 'inch' - #No effect + # No effect ad.to_inch() assert_equal(ad.modifiers[0], (1., 1.)) assert_equal(ad.modifiers[1], (1., 1.)) @@ -686,11 +750,12 @@ def test_ADParamStmt_conversion(): assert_equal(ad.modifiers[0], (25.4, 25.4)) assert_equal(ad.modifiers[1], (25.4, 25.4)) - #No effect + # No effect ad.to_metric() assert_equal(ad.modifiers[0], (25.4, 25.4)) assert_equal(ad.modifiers[1], (25.4, 25.4)) + def test_ADParamStmt_dump(): stmt = {'param': 'AD', 'd': 0, 'shape': 'C'} ad = ADParamStmt.from_dict(stmt) @@ -699,6 +764,7 @@ def test_ADParamStmt_dump(): ad = ADParamStmt.from_dict(stmt) assert_equal(ad.to_gerber(), '%ADD0C,1X1,1X1*%') + def test_ADPamramStmt_string(): stmt = {'param': 'AD', 'd': 0, 'shape': 'C'} ad = ADParamStmt.from_dict(stmt) @@ -716,12 +782,14 @@ def test_ADPamramStmt_string(): ad = ADParamStmt.from_dict(stmt) assert_equal(str(ad), '') + def test_MIParamStmt_factory(): stmt = {'param': 'MI', 'a': 1, 'b': 1} mi = MIParamStmt.from_dict(stmt) assert_equal(mi.a, 1) assert_equal(mi.b, 1) + def test_MIParamStmt_dump(): stmt = {'param': 'MI', 'a': 1, 'b': 1} mi = MIParamStmt.from_dict(stmt) @@ -733,6 +801,7 @@ def test_MIParamStmt_dump(): mi = MIParamStmt.from_dict(stmt) assert_equal(mi.to_gerber(), '%MIA0B1*%') + def test_MIParamStmt_string(): stmt = {'param': 'MI', 'a': 1, 'b': 1} mi = MIParamStmt.from_dict(stmt) @@ -746,6 +815,7 @@ def test_MIParamStmt_string(): mi = MIParamStmt.from_dict(stmt) assert_equal(str(mi), '') + def test_coordstmt_ctor(): cs = CoordStmt('G04', 0.0, 0.1, 0.2, 0.3, 'D01', FileSettings()) assert_equal(cs.function, 'G04') @@ -755,8 +825,10 @@ def test_coordstmt_ctor(): assert_equal(cs.j, 0.3) assert_equal(cs.op, 'D01') + def test_coordstmt_factory(): - stmt = {'function': 'G04', 'x': '0', 'y': '001', 'i': '002', 'j': '003', 'op': 'D01'} + stmt = {'function': 'G04', 'x': '0', 'y': '001', + 'i': '002', 'j': '003', 'op': 'D01'} cs = CoordStmt.from_dict(stmt, FileSettings()) assert_equal(cs.function, 'G04') assert_equal(cs.x, 0.0) @@ -765,15 +837,17 @@ def test_coordstmt_factory(): assert_equal(cs.j, 0.3) assert_equal(cs.op, 'D01') + def test_coordstmt_dump(): cs = CoordStmt('G04', 0.0, 0.1, 0.2, 0.3, 'D01', FileSettings()) assert_equal(cs.to_gerber(FileSettings()), 'G04X0Y001I002J003D01*') + def test_coordstmt_conversion(): cs = CoordStmt('G71', 25.4, 25.4, 25.4, 25.4, 'D01', FileSettings()) cs.units = 'metric' - #No effect + # No effect cs.to_metric() assert_equal(cs.x, 25.4) assert_equal(cs.y, 25.4) @@ -789,7 +863,7 @@ def test_coordstmt_conversion(): assert_equal(cs.j, 1.) assert_equal(cs.function, 'G70') - #No effect + # No effect cs.to_inch() assert_equal(cs.x, 1.) assert_equal(cs.y, 1.) @@ -800,7 +874,7 @@ def test_coordstmt_conversion(): cs = CoordStmt('G70', 1., 1., 1., 1., 'D01', FileSettings()) cs.units = 'inch' - #No effect + # No effect cs.to_inch() assert_equal(cs.x, 1.) assert_equal(cs.y, 1.) @@ -815,7 +889,7 @@ def test_coordstmt_conversion(): assert_equal(cs.j, 25.4) assert_equal(cs.function, 'G71') - #No effect + # No effect cs.to_metric() assert_equal(cs.x, 25.4) assert_equal(cs.y, 25.4) @@ -823,6 +897,7 @@ def test_coordstmt_conversion(): assert_equal(cs.j, 25.4) assert_equal(cs.function, 'G71') + def test_coordstmt_offset(): c = CoordStmt('G71', 0, 0, 0, 0, 'D01', FileSettings()) c.offset(1, 0) @@ -836,9 +911,11 @@ def test_coordstmt_offset(): assert_equal(c.i, 1.) assert_equal(c.j, 1.) + def test_coordstmt_string(): cs = CoordStmt('G04', 0, 1, 2, 3, 'D01', FileSettings()) - assert_equal(str(cs), '') + assert_equal(str(cs), + '') cs = CoordStmt('G04', None, None, None, None, 'D02', FileSettings()) assert_equal(str(cs), '') cs = CoordStmt('G04', None, None, None, None, 'D03', FileSettings()) @@ -846,6 +923,7 @@ def test_coordstmt_string(): cs = CoordStmt('G04', None, None, None, None, 'TEST', FileSettings()) assert_equal(str(cs), '') + def test_aperturestmt_ctor(): ast = ApertureStmt(3, False) assert_equal(ast.d, 3) @@ -860,11 +938,10 @@ def test_aperturestmt_ctor(): assert_equal(ast.d, 3) assert_equal(ast.deprecated, False) + def test_aperturestmt_dump(): ast = ApertureStmt(3, False) assert_equal(ast.to_gerber(), 'D3*') ast = ApertureStmt(3, True) assert_equal(ast.to_gerber(), 'G54D3*') assert_equal(str(ast), '') - - diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index f123a38..45bb01b 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -2,18 +2,21 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe -from ..ipc356 import * +from ..ipc356 import * from ..cam import FileSettings from .tests import * import os IPC_D_356_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ipc-d-356.ipc') + 'resources/ipc-d-356.ipc') + + def test_read(): ipcfile = read(IPC_D_356_FILE) assert(isinstance(ipcfile, IPC_D_356)) + def test_parser(): ipcfile = read(IPC_D_356_FILE) assert_equal(ipcfile.settings.units, 'inch') @@ -28,6 +31,7 @@ def test_parser(): assert_equal(set(ipcfile.outlines[0].points), {(0., 0.), (2.25, 0.), (2.25, 1.5), (0., 1.5), (0.13, 0.024)}) + def test_comment(): c = IPC356_Comment('Layer Stackup:') assert_equal(c.comment, 'Layer Stackup:') @@ -36,6 +40,7 @@ def test_comment(): assert_raises(ValueError, IPC356_Comment.from_line, 'P JOB') assert_equal(str(c), '') + def test_parameter(): p = IPC356_Parameter('VER', 'IPC-D-356A') assert_equal(p.parameter, 'VER') @@ -43,27 +48,32 @@ def test_parameter(): p = IPC356_Parameter.from_line('P VER IPC-D-356A ') assert_equal(p.parameter, 'VER') assert_equal(p.value, 'IPC-D-356A') - assert_raises(ValueError, IPC356_Parameter.from_line, 'C Layer Stackup: ') + assert_raises(ValueError, IPC356_Parameter.from_line, + 'C Layer Stackup: ') assert_equal(str(p), '') + def test_eof(): e = IPC356_EndOfFile() assert_equal(e.to_netlist(), '999') assert_equal(str(e), '') + def test_outline(): type = 'BOARD_EDGE' points = [(0.01, 0.01), (2., 2.), (4., 2.), (4., 6.)] b = IPC356_Outline(type, points) assert_equal(b.type, type) assert_equal(b.points, points) - b = IPC356_Outline.from_line('389BOARD_EDGE X100Y100 X20000Y20000' - ' X40000 Y60000', FileSettings(units='inch')) + b = IPC356_Outline.from_line('389BOARD_EDGE X100Y100 X20000Y20000 X40000 Y60000', + FileSettings(units='inch')) assert_equal(b.type, 'BOARD_EDGE') assert_equal(b.points, points) + def test_test_record(): - assert_raises(ValueError, IPC356_TestRecord.from_line, 'P JOB', FileSettings()) + assert_raises(ValueError, IPC356_TestRecord.from_line, + 'P JOB', FileSettings()) record_string = '317+5VDC VIA - D0150PA00X 006647Y 012900X0000 S3' r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) assert_equal(r.feature_type, 'through-hole') @@ -81,8 +91,7 @@ def test_test_record(): assert_almost_equal(r.x_coord, 6.647) assert_almost_equal(r.y_coord, 12.9) assert_equal(r.rect_x, 0.) - assert_equal(str(r), - '') + assert_equal(str(r), '') record_string = '327+3.3VDC R40 -1 PA01X 032100Y 007124X0236Y0315R180 S0' r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) @@ -98,13 +107,13 @@ def test_test_record(): assert_almost_equal(r.rect_y, 0.0315) assert_equal(r.rect_rotation, 180) assert_equal(r.soldermask_info, 'none') - r = IPC356_TestRecord.from_line(record_string, FileSettings(units='metric')) + r = IPC356_TestRecord.from_line( + record_string, FileSettings(units='metric')) assert_almost_equal(r.x_coord, 32.1) assert_almost_equal(r.y_coord, 7.124) assert_almost_equal(r.rect_x, 0.236) assert_almost_equal(r.rect_y, 0.315) - record_string = '317 J4 -M2 D0330PA00X 012447Y 008030X0000 S1' r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) assert_equal(r.feature_type, 'through-hole') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index c77084d..3f2bcfc 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -15,7 +15,7 @@ def test_guess_layer_class(): test_vectors = [(None, 'unknown'), ('NCDRILL.TXT', 'unknown'), ('example_board.gtl', 'top'), ('exampmle_board.sst', 'topsilk'), - ('ipc-d-356.ipc', 'ipc_netlist'),] + ('ipc-d-356.ipc', 'ipc_netlist'), ] for hint in hints: for ext in hint.ext: diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index f8a32da..e6ed1cd 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -9,11 +9,12 @@ from operator import add def test_primitive_smoketest(): p = Primitive() - assert_raises(NotImplementedError, p.bounding_box) + #assert_raises(NotImplementedError, p.bounding_box) p.to_metric() p.to_inch() p.offset(1, 1) + def test_line_angle(): """ Test Line primitive angle calculation """ @@ -24,19 +25,20 @@ def test_line_angle(): ((0, 0), (-1, 0), math.radians(180)), ((0, 0), (-1, -1), math.radians(225)), ((0, 0), (0, -1), math.radians(270)), - ((0, 0), (1, -1), math.radians(315)),] + ((0, 0), (1, -1), math.radians(315)), ] for start, end, expected in cases: l = Line(start, end, 0) line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) assert_almost_equal(line_angle, expected) + def test_line_bounds(): """ Test Line primitive bounding box calculation """ cases = [((0, 0), (1, 1), ((-1, 2), (-1, 2))), ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), - ((-1, 1), (1, -1), ((-2, 2), (-2, 2))),] + ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), ] c = Circle((0, 0), 2) r = Rectangle((0, 0), 2, 2) @@ -49,11 +51,12 @@ def test_line_bounds(): cases = [((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))), ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))), ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))), - ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))),] + ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))), ] for start, end, expected in cases: l = Line(start, end, r) assert_equal(l.bounding_box, expected) + def test_line_vertices(): c = Circle((0, 0), 2) l = Line((0, 0), (1, 1), c) @@ -61,20 +64,25 @@ def test_line_vertices(): # All 4 compass points, all 4 quadrants and the case where start == end test_cases = [((0, 0), (1, 0), ((-1, -1), (-1, 1), (2, 1), (2, -1))), - ((0, 0), (1, 1), ((-1, -1), (-1, 1), (0, 2), (2, 2), (2, 0), (1,-1))), - ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), - ((0, 0), (-1, 1), ((-1, -1), (-2, 0), (-2, 2), (0, 2), (1, 1), (1, -1))), - ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), - ((0, 0), (-1, -1), ((-2, -2), (1, -1), (1, 1), (-1, 1), (-2, 0), (0,-2))), - ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), - ((0, 0), (1, -1), ((-1, -1), (0, -2), (2, -2), (2, 0), (1, 1), (-1, 1))), - ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))),] + ((0, 0), (1, 1), ((-1, -1), (-1, 1), + (0, 2), (2, 2), (2, 0), (1, -1))), + ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), + ((0, 0), (-1, 1), ((-1, -1), (-2, 0), + (-2, 2), (0, 2), (1, 1), (1, -1))), + ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), + ((0, 0), (-1, -1), ((-2, -2), (1, -1), + (1, 1), (-1, 1), (-2, 0), (0, -2))), + ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), + ((0, 0), (1, -1), ((-1, -1), (0, -2), + (2, -2), (2, 0), (1, 1), (-1, 1))), + ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))), ] r = Rectangle((0, 0), 2, 2) for start, end, vertices in test_cases: l = Line(start, end, r) assert_equal(set(vertices), set(l.vertices)) + def test_line_conversion(): c = Circle((0, 0), 25.4, units='metric') l = Line((2.54, 25.4), (254.0, 2540.0), c, units='metric') @@ -105,13 +113,12 @@ def test_line_conversion(): assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.diameter, 1.0) - l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) assert_equal(l.aperture.diameter, 25.4) - #No effect + # No effect l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) @@ -133,56 +140,63 @@ def test_line_conversion(): assert_equal(l.aperture.width, 25.4) assert_equal(l.aperture.height, 254.0) + def test_line_offset(): c = Circle((0, 0), 1) l = Line((0, 0), (1, 1), c) l.offset(1, 0) - assert_equal(l.start,(1., 0.)) + assert_equal(l.start, (1., 0.)) assert_equal(l.end, (2., 1.)) l.offset(0, 1) - assert_equal(l.start,(1., 1.)) + assert_equal(l.start, (1., 1.)) assert_equal(l.end, (2., 2.)) + def test_arc_radius(): """ Test Arc primitive radius calculation """ cases = [((-3, 4), (5, 0), (0, 0), 5), - ((0, 1), (1, 0), (0, 0), 1),] + ((0, 1), (1, 0), (0, 0), 1), ] for start, end, center, radius in cases: a = Arc(start, end, center, 'clockwise', 0) assert_equal(a.radius, radius) + def test_arc_sweep_angle(): """ Test Arc primitive sweep angle calculation """ cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)), ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)), ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)), - ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),] + ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)), ] for start, end, center, direction, sweep in cases: - c = Circle((0,0), 1) + c = Circle((0, 0), 1) a = Arc(start, end, center, direction, c) assert_equal(a.sweep_angle, sweep) + def test_arc_bounds(): """ Test Arc primitive bounding box calculation """ - cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((-0.5, 1.5), (-0.5, 1.5))), - #TODO: ADD MORE TEST CASES HERE + cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (0, 1), (0, 0), 'counterclockwise', + ((-0.5, 1.5), (-0.5, 1.5))), + # TODO: ADD MORE TEST CASES HERE ] for start, end, center, direction, bounds in cases: - c = Circle((0,0), 1) + c = Circle((0, 0), 1) a = Arc(start, end, center, direction, c) assert_equal(a.bounding_box, bounds) + def test_arc_conversion(): c = Circle((0, 0), 25.4, units='metric') - a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, units='metric') + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0), + 'clockwise', c, units='metric') - #No effect + # No effect a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) @@ -195,7 +209,7 @@ def test_arc_conversion(): assert_equal(a.center, (1000.0, 10000.0)) assert_equal(a.aperture.diameter, 1.0) - #no effect + # no effect a.to_inch() assert_equal(a.start, (0.1, 1.0)) assert_equal(a.end, (10.0, 100.0)) @@ -203,41 +217,46 @@ def test_arc_conversion(): assert_equal(a.aperture.diameter, 1.0) c = Circle((0, 0), 1.0, units='inch') - a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c, units='inch') + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), + 'clockwise', c, units='inch') a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) assert_equal(a.center, (25400.0, 254000.0)) assert_equal(a.aperture.diameter, 25.4) + def test_arc_offset(): c = Circle((0, 0), 1) a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c) a.offset(1, 0) - assert_equal(a.start,(1., 0.)) + assert_equal(a.start, (1., 0.)) assert_equal(a.end, (2., 1.)) assert_equal(a.center, (3., 2.)) a.offset(0, 1) - assert_equal(a.start,(1., 1.)) + assert_equal(a.start, (1., 1.)) assert_equal(a.end, (2., 2.)) assert_equal(a.center, (3., 3.)) + def test_circle_radius(): """ Test Circle primitive radius calculation """ c = Circle((1, 1), 2) assert_equal(c.radius, 1) + def test_circle_bounds(): """ Test Circle bounding box calculation """ c = Circle((1, 1), 2) assert_equal(c.bounding_box, ((0, 2), (0, 2))) + def test_circle_conversion(): c = Circle((2.54, 25.4), 254.0, units='metric') - c.to_metric() #shouldn't do antyhing + c.to_metric() # shouldn't do antyhing assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) @@ -245,13 +264,13 @@ def test_circle_conversion(): assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) - #no effect + # no effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) c = Circle((0.1, 1.0), 10.0, units='inch') - #No effect + # No effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) @@ -260,17 +279,19 @@ def test_circle_conversion(): assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) - #no effect + # no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) + def test_circle_offset(): c = Circle((0, 0), 1) c.offset(1, 0) - assert_equal(c.position,(1., 0.)) + assert_equal(c.position, (1., 0.)) c.offset(0, 1) - assert_equal(c.position,(1., 1.)) + assert_equal(c.position, (1., 1.)) + def test_ellipse_ctor(): """ Test ellipse creation @@ -280,6 +301,7 @@ def test_ellipse_ctor(): assert_equal(e.width, 3) assert_equal(e.height, 2) + def test_ellipse_bounds(): """ Test ellipse bounding box calculation """ @@ -292,10 +314,11 @@ def test_ellipse_bounds(): e = Ellipse((2, 2), 4, 2, rotation=270) assert_equal(e.bounding_box, ((1, 3), (0, 4))) + def test_ellipse_conversion(): e = Ellipse((2.54, 25.4), 254.0, 2540., units='metric') - #No effect + # No effect e.to_metric() assert_equal(e.position, (2.54, 25.4)) assert_equal(e.width, 254.) @@ -306,7 +329,7 @@ def test_ellipse_conversion(): assert_equal(e.width, 10.) assert_equal(e.height, 100.) - #No effect + # No effect e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) @@ -314,7 +337,7 @@ def test_ellipse_conversion(): e = Ellipse((0.1, 1.), 10.0, 100., units='inch') - #no effect + # no effect e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) @@ -331,40 +354,44 @@ def test_ellipse_conversion(): assert_equal(e.width, 254.) assert_equal(e.height, 2540.) + def test_ellipse_offset(): e = Ellipse((0, 0), 1, 2) e.offset(1, 0) - assert_equal(e.position,(1., 0.)) + assert_equal(e.position, (1., 0.)) e.offset(0, 1) - assert_equal(e.position,(1., 1.)) + assert_equal(e.position, (1., 1.)) + def test_rectangle_ctor(): """ Test rectangle creation """ - test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: r = Rectangle(pos, width, height) assert_equal(r.position, pos) assert_equal(r.width, width) assert_equal(r.height, height) + def test_rectangle_bounds(): """ Test rectangle bounding box calculation """ - r = Rectangle((0,0), 2, 2) + r = Rectangle((0, 0), 2, 2) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = Rectangle((0,0), 2, 2, rotation=45) + r = Rectangle((0, 0), 2, 2, rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_rectangle_conversion(): r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) @@ -385,44 +412,48 @@ def test_rectangle_conversion(): assert_equal(r.height, 100.0) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) + def test_rectangle_offset(): r = Rectangle((0, 0), 1, 2) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_diamond_ctor(): """ Test diamond creation """ - test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: d = Diamond(pos, width, height) assert_equal(d.position, pos) assert_equal(d.width, width) assert_equal(d.height, height) + def test_diamond_bounds(): """ Test diamond bounding box calculation """ - d = Diamond((0,0), 2, 2) + d = Diamond((0, 0), 2, 2) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - d = Diamond((0,0), math.sqrt(2), math.sqrt(2), rotation=45) + d = Diamond((0, 0), math.sqrt(2), math.sqrt(2), rotation=45) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_diamond_conversion(): d = Diamond((2.54, 25.4), 254.0, 2540.0, units='metric') @@ -458,19 +489,21 @@ def test_diamond_conversion(): assert_equal(d.width, 254.0) assert_equal(d.height, 2540.0) + def test_diamond_offset(): d = Diamond((0, 0), 1, 2) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation """ - test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1,1), 1, 2, 0.4, (False, False, False, False))) + ((1, 1), 1, 2, 0.4, (False, False, False, False))) for pos, width, height, chamfer, corners in test_cases: r = ChamferRectangle(pos, width, height, chamfer, corners) assert_equal(r.position, pos) @@ -479,23 +512,27 @@ def test_chamfer_rectangle_ctor(): assert_equal(r.chamfer, chamfer) assert_array_almost_equal(r.corners, corners) + def test_chamfer_rectangle_bounds(): """ Test chamfer rectangle bounding box calculation """ - r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + r = ChamferRectangle( + (0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_chamfer_rectangle_conversion(): - r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, + (True, True, False, False), units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) @@ -512,7 +549,8 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.height, 100.0) assert_equal(r.chamfer, 0.01) - r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, + (True, True, False, False), units='inch') r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) @@ -520,30 +558,32 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.chamfer, 0.01) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) + def test_chamfer_rectangle_offset(): r = ChamferRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_round_rectangle_ctor(): """ Test round rectangle creation """ - test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1,1), 1, 2, 0.4, (False, False, False, False))) + ((1, 1), 1, 2, 0.4, (False, False, False, False))) for pos, width, height, radius, corners in test_cases: r = RoundRectangle(pos, width, height, radius, corners) assert_equal(r.position, pos) @@ -552,23 +592,27 @@ def test_round_rectangle_ctor(): assert_equal(r.radius, radius) assert_array_almost_equal(r.corners, corners) + def test_round_rectangle_bounds(): """ Test round rectangle bounding box calculation """ - r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + r = RoundRectangle((0, 0), 2, 2, 0.2, + (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_round_rectangle_conversion(): - r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, + (True, True, False, False), units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) @@ -585,7 +629,8 @@ def test_round_rectangle_conversion(): assert_equal(r.height, 100.0) assert_equal(r.radius, 0.01) - r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, + (True, True, False, False), units='inch') r.to_inch() assert_equal(r.position, (0.1, 1.0)) @@ -594,70 +639,76 @@ def test_round_rectangle_conversion(): assert_equal(r.radius, 0.01) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) + def test_round_rectangle_offset(): r = RoundRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_obround_ctor(): """ Test obround creation """ - test_cases = (((0,0), 1, 1), + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), - ((1,1), 1, 2)) + ((1, 1), 1, 2)) for pos, width, height in test_cases: o = Obround(pos, width, height) assert_equal(o.position, pos) assert_equal(o.width, width) assert_equal(o.height, height) + def test_obround_bounds(): """ Test obround bounding box calculation """ - o = Obround((2,2),2,4) + o = Obround((2, 2), 2, 4) xbounds, ybounds = o.bounding_box assert_array_almost_equal(xbounds, (1, 3)) assert_array_almost_equal(ybounds, (0, 4)) - o = Obround((2,2),4,2) + o = Obround((2, 2), 4, 2) xbounds, ybounds = o.bounding_box assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (1, 3)) + def test_obround_orientation(): o = Obround((0, 0), 2, 1) assert_equal(o.orientation, 'horizontal') o = Obround((0, 0), 1, 2) assert_equal(o.orientation, 'vertical') + def test_obround_subshapes(): - o = Obround((0,0), 1, 4) + o = Obround((0, 0), 1, 4) ss = o.subshapes assert_array_almost_equal(ss['rectangle'].position, (0, 0)) assert_array_almost_equal(ss['circle1'].position, (0, 1.5)) assert_array_almost_equal(ss['circle2'].position, (0, -1.5)) - o = Obround((0,0), 4, 1) + o = Obround((0, 0), 4, 1) ss = o.subshapes assert_array_almost_equal(ss['rectangle'].position, (0, 0)) assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) + def test_obround_conversion(): - o = Obround((2.54,25.4), 254.0, 2540.0, units='metric') + o = Obround((2.54, 25.4), 254.0, 2540.0, units='metric') - #No effect + # No effect o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) @@ -668,15 +719,15 @@ def test_obround_conversion(): assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) - #No effect + # No effect o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) - o= Obround((0.1, 1.0), 10.0, 100.0, units='inch') + o = Obround((0.1, 1.0), 10.0, 100.0, units='inch') - #No effect + # No effect o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) @@ -687,98 +738,107 @@ def test_obround_conversion(): assert_equal(o.width, 254.0) assert_equal(o.height, 2540.0) - #No effect + # No effect o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) assert_equal(o.height, 2540.0) + def test_obround_offset(): o = Obround((0, 0), 1, 2) o.offset(1, 0) - assert_equal(o.position,(1., 0.)) + assert_equal(o.position, (1., 0.)) o.offset(0, 1) - assert_equal(o.position,(1., 1.)) + assert_equal(o.position, (1., 1.)) + def test_polygon_ctor(): """ Test polygon creation """ - test_cases = (((0,0), 3, 5), + test_cases = (((0, 0), 3, 5), ((0, 0), 5, 6), - ((1,1), 7, 7)) + ((1, 1), 7, 7)) for pos, sides, radius in test_cases: p = Polygon(pos, sides, radius) assert_equal(p.position, pos) assert_equal(p.sides, sides) assert_equal(p.radius, radius) + def test_polygon_bounds(): """ Test polygon bounding box calculation """ - p = Polygon((2,2), 3, 2) + p = Polygon((2, 2), 3, 2) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (0, 4)) - p = Polygon((2,2),3, 4) + p = Polygon((2, 2), 3, 4) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (-2, 6)) assert_array_almost_equal(ybounds, (-2, 6)) + def test_polygon_conversion(): p = Polygon((2.54, 25.4), 3, 254.0, units='metric') - - #No effect + + # No effect p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) - + p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - - #No effect + + # No effect p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) p = Polygon((0.1, 1.0), 3, 10.0, units='inch') - - #No effect + + # No effect p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - + p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) - - #No effect + + # No effect p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) + def test_polygon_offset(): p = Polygon((0, 0), 5, 10) p.offset(1, 0) - assert_equal(p.position,(1., 0.)) + assert_equal(p.position, (1., 0.)) p.offset(0, 1) - assert_equal(p.position,(1., 1.)) + assert_equal(p.position, (1., 1.)) + def test_region_ctor(): """ Test Region creation """ - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) - points = ((0, 0), (1,0), (1,1), (0,1)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) + points = ((0, 0), (1, 0), (1, 1), (0, 1)) r = Region(lines) for i, p in enumerate(lines): assert_equal(r.primitives[i], p) + def test_region_bounds(): """ Test region bounding box calculation """ - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) r = Region(lines) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (0, 1)) @@ -786,68 +846,76 @@ def test_region_bounds(): def test_region_offset(): - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) r = Region(lines) xlim, ylim = r.bounding_box r.offset(0, 1) - assert_array_almost_equal((xlim, tuple([y+1 for y in ylim])), r.bounding_box) + new_xlim, new_ylim = r.bounding_box + assert_array_almost_equal(new_xlim, xlim) + assert_array_almost_equal(new_ylim, tuple([y + 1 for y in ylim])) + def test_round_butterfly_ctor(): """ Test round butterfly creation """ - test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, diameter in test_cases: b = RoundButterfly(pos, diameter) assert_equal(b.position, pos) assert_equal(b.diameter, diameter) - assert_equal(b.radius, diameter/2.) + assert_equal(b.radius, diameter / 2.) + def test_round_butterfly_ctor_validation(): """ Test RoundButterfly argument validation """ assert_raises(TypeError, RoundButterfly, 3, 5) - assert_raises(TypeError, RoundButterfly, (3,4,5), 5) + assert_raises(TypeError, RoundButterfly, (3, 4, 5), 5) + def test_round_butterfly_conversion(): b = RoundButterfly((2.54, 25.4), 254.0, units='metric') - - #No Effect + + # No Effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) - + b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) b = RoundButterfly((0.1, 1.0), 10.0, units='inch') - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) - + b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) - - #No Effect + + # No Effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) + def test_round_butterfly_offset(): b = RoundButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position,(1., 0.)) + assert_equal(b.position, (1., 0.)) b.offset(0, 1) - assert_equal(b.position,(1., 1.)) + assert_equal(b.position, (1., 1.)) + def test_round_butterfly_bounds(): """ Test RoundButterfly bounding box calculation @@ -857,20 +925,23 @@ def test_round_butterfly_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_square_butterfly_ctor(): """ Test SquareButterfly creation """ - test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, side in test_cases: b = SquareButterfly(pos, side) assert_equal(b.position, pos) assert_equal(b.side, side) + def test_square_butterfly_ctor_validation(): """ Test SquareButterfly argument validation """ assert_raises(TypeError, SquareButterfly, 3, 5) - assert_raises(TypeError, SquareButterfly, (3,4,5), 5) + assert_raises(TypeError, SquareButterfly, (3, 4, 5), 5) + def test_square_butterfly_bounds(): """ Test SquareButterfly bounding box calculation @@ -880,51 +951,54 @@ def test_square_butterfly_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_squarebutterfly_conversion(): b = SquareButterfly((2.54, 25.4), 254.0, units='metric') - - #No effect + + # No effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) - + b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) b = SquareButterfly((0.1, 1.0), 10.0, units='inch') - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) - + b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) - - #No effect + + # No effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) + def test_square_butterfly_offset(): b = SquareButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position,(1., 0.)) + assert_equal(b.position, (1., 0.)) b.offset(0, 1) - assert_equal(b.position,(1., 1.)) + assert_equal(b.position, (1., 1.)) + def test_donut_ctor(): """ Test Donut primitive creation """ - test_cases = (((0,0), 'round', 3, 5), ((0, 0), 'square', 5, 7), - ((1,1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) + test_cases = (((0, 0), 'round', 3, 5), ((0, 0), 'square', 5, 7), + ((1, 1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) for pos, shape, in_d, out_d in test_cases: d = Donut(pos, shape, in_d, out_d) assert_equal(d.position, pos) @@ -932,65 +1006,68 @@ def test_donut_ctor(): assert_equal(d.inner_diameter, in_d) assert_equal(d.outer_diameter, out_d) + def test_donut_ctor_validation(): assert_raises(TypeError, Donut, 3, 'round', 5, 7) assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) + def test_donut_bounds(): d = Donut((0, 0), 'round', 0.0, 2.0) - assert_equal(d.lower_left, (-1.0, -1.0)) - assert_equal(d.upper_right, (1.0, 1.0)) xbounds, ybounds = d.bounding_box assert_equal(xbounds, (-1., 1.)) assert_equal(ybounds, (-1., 1.)) + def test_donut_conversion(): d = Donut((2.54, 25.4), 'round', 254.0, 2540.0, units='metric') - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) - + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) d = Donut((0.1, 1.0), 'round', 10.0, 100.0, units='inch') - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) - + d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) + def test_donut_offset(): d = Donut((0, 0), 'round', 1, 10) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_drill_ctor(): """ Test drill primitive creation @@ -1000,13 +1077,15 @@ def test_drill_ctor(): d = Drill(position, diameter) assert_equal(d.position, position) assert_equal(d.diameter, diameter) - assert_equal(d.radius, diameter/2.) + assert_equal(d.radius, diameter / 2.) + def test_drill_ctor_validation(): """ Test drill argument validation """ assert_raises(TypeError, Drill, 3, 5) - assert_raises(TypeError, Drill, (3,4,5), 5) + assert_raises(TypeError, Drill, (3, 4, 5), 5) + def test_drill_bounds(): d = Drill((0, 0), 2) @@ -1018,46 +1097,48 @@ def test_drill_bounds(): assert_array_almost_equal(xbounds, (0, 2)) assert_array_almost_equal(ybounds, (1, 3)) + def test_drill_conversion(): d = Drill((2.54, 25.4), 254., units='metric') - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) - + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - d = Drill((0.1, 1.0), 10., units='inch') - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - + d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) + def test_drill_offset(): d = Drill((0, 0), 1.) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_drill_equality(): d = Drill((2.54, 25.4), 254.) diff --git a/gerber/tests/test_rs274x.py b/gerber/tests/test_rs274x.py index c084e80..d5acfe8 100644 --- a/gerber/tests/test_rs274x.py +++ b/gerber/tests/test_rs274x.py @@ -9,31 +9,35 @@ from .tests import * TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), - 'resources/top_copper.GTL') + 'resources/top_copper.GTL') MULTILINE_READ_FILE = os.path.join(os.path.dirname(__file__), - 'resources/multiline_read.ger') + 'resources/multiline_read.ger') def test_read(): top_copper = read(TOP_COPPER_FILE) assert(isinstance(top_copper, GerberFile)) + def test_multiline_read(): multiline = read(MULTILINE_READ_FILE) assert(isinstance(multiline, GerberFile)) assert_equal(10, len(multiline.statements)) + def test_comments_parameter(): top_copper = read(TOP_COPPER_FILE) assert_equal(top_copper.comments[0], 'This is a comment,:') + def test_size_parameter(): top_copper = read(TOP_COPPER_FILE) size = top_copper.size assert_almost_equal(size[0], 2.256900, 6) assert_almost_equal(size[1], 1.500000, 6) + def test_conversion(): import copy top_copper = read(TOP_COPPER_FILE) @@ -50,4 +54,3 @@ def test_conversion(): for i, m in zip(top_copper.primitives, top_copper_inch.primitives): assert_equal(i, m) - diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py index fe9b2e6..35f6f47 100644 --- a/gerber/tests/test_utils.py +++ b/gerber/tests/test_utils.py @@ -52,7 +52,7 @@ def test_format(): ((2, 6), '-1', -0.000001), ((2, 5), '-1', -0.00001), ((2, 4), '-1', -0.0001), ((2, 3), '-1', -0.001), ((2, 2), '-1', -0.01), ((2, 1), '-1', -0.1), - ((2, 6), '0', 0) ] + ((2, 6), '0', 0)] for fmt, string, value in test_cases: assert_equal(value, parse_gerber_value(string, fmt, zero_suppression)) assert_equal(string, write_gerber_value(value, fmt, zero_suppression)) @@ -76,7 +76,7 @@ def test_decimal_truncation(): value = 1.123456789 for x in range(10): result = decimal_string(value, precision=x) - calculated = '1.' + ''.join(str(y) for y in range(1,x+1)) + calculated = '1.' + ''.join(str(y) for y in range(1, x + 1)) assert_equal(result, calculated) @@ -96,25 +96,34 @@ def test_parse_format_validation(): """ assert_raises(ValueError, parse_gerber_value, '00001111', (7, 5)) assert_raises(ValueError, parse_gerber_value, '00001111', (5, 8)) - assert_raises(ValueError, parse_gerber_value, '00001111', (13,1)) - + assert_raises(ValueError, parse_gerber_value, '00001111', (13, 1)) + + def test_write_format_validation(): """ Test write_gerber_value() format validation """ assert_raises(ValueError, write_gerber_value, 69.0, (7, 5)) assert_raises(ValueError, write_gerber_value, 69.0, (5, 8)) - assert_raises(ValueError, write_gerber_value, 69.0, (13,1)) + assert_raises(ValueError, write_gerber_value, 69.0, (13, 1)) def test_detect_format_with_short_file(): """ Verify file format detection works with short files """ assert_equal('unknown', detect_file_format('gerber/tests/__init__.py')) - + + def test_validate_coordinates(): assert_raises(TypeError, validate_coordinates, 3) assert_raises(TypeError, validate_coordinates, 3.1) assert_raises(TypeError, validate_coordinates, '14') assert_raises(TypeError, validate_coordinates, (0,)) - assert_raises(TypeError, validate_coordinates, (0,1,2)) - assert_raises(TypeError, validate_coordinates, (0,'string')) + assert_raises(TypeError, validate_coordinates, (0, 1, 2)) + assert_raises(TypeError, validate_coordinates, (0, 'string')) + + +def test_convex_hull(): + points = [(0, 0), (1, 0), (1, 1), (0.5, 0.5), (0, 1), (0, 0)] + expected = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)] + assert_equal(set(convex_hull(points)), set(expected)) + \ No newline at end of file diff --git a/gerber/tests/tests.py b/gerber/tests/tests.py index 2c75acd..ac08208 100644 --- a/gerber/tests/tests.py +++ b/gerber/tests/tests.py @@ -16,7 +16,8 @@ from nose import with_setup __all__ = ['assert_in', 'assert_not_in', 'assert_equal', 'assert_not_equal', 'assert_almost_equal', 'assert_array_almost_equal', 'assert_true', - 'assert_false', 'assert_raises', 'raises', 'with_setup' ] + 'assert_false', 'assert_raises', 'raises', 'with_setup'] + def assert_array_almost_equal(arr1, arr2, decimal=6): assert_equal(len(arr1), len(arr2)) -- cgit From 5df38c014fd09792995b2b12b1982c535c962c9a Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 28 Jan 2016 12:19:03 -0500 Subject: Cleanup, rendering fixes. fixed rendering of tented vias fixed rendering of semi-transparent layers fixed file type detection issues added some examples --- gerber/tests/test_ipc356.py | 2 +- gerber/tests/test_layers.py | 75 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) (limited to 'gerber/tests') diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index 45bb01b..4710633 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -14,7 +14,7 @@ IPC_D_356_FILE = os.path.join(os.path.dirname(__file__), def test_read(): ipcfile = read(IPC_D_356_FILE) - assert(isinstance(ipcfile, IPC_D_356)) + assert(isinstance(ipcfile, IPCNetlist)) def test_parser(): diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 3f2bcfc..7e36dc2 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -1,11 +1,33 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -# Author: Hamilton Kibbe +# copyright 2016 Hamilton Kibbe +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os from .tests import * -from ..layers import guess_layer_class, hints +from ..layers import * +from ..common import read +NCDRILL_FILE = os.path.join(os.path.dirname(__file__), + 'resources/ncdrill.DRD') +NETLIST_FILE = os.path.join(os.path.dirname(__file__), + 'resources/ipc-d-356.ipc') +COPPER_FILE = os.path.join(os.path.dirname(__file__), + 'resources/top_copper.GTL') def test_guess_layer_class(): """ Test layer type inferred correctly from filename @@ -30,4 +52,51 @@ def test_guess_layer_class(): def test_sort_layers(): """ Test layer ordering """ - pass + layers = [ + PCBLayer(layer_class='drawing'), + PCBLayer(layer_class='drill'), + PCBLayer(layer_class='bottompaste'), + PCBLayer(layer_class='bottomsilk'), + PCBLayer(layer_class='bottommask'), + PCBLayer(layer_class='bottom'), + PCBLayer(layer_class='internal'), + PCBLayer(layer_class='top'), + PCBLayer(layer_class='topmask'), + PCBLayer(layer_class='topsilk'), + PCBLayer(layer_class='toppaste'), + PCBLayer(layer_class='outline'), + ] + + layer_order = ['outline', 'toppaste', 'topsilk', 'topmask', 'top', + 'internal', 'bottom', 'bottommask', 'bottomsilk', + 'bottompaste', 'drill', 'drawing'] + bottom_order = list(reversed(layer_order[:10])) + layer_order[10:] + assert_equal([l.layer_class for l in sort_layers(layers)], layer_order) + assert_equal([l.layer_class for l in sort_layers(layers, from_top=False)], + bottom_order) + + +def test_PCBLayer_from_file(): + layer = PCBLayer.from_cam(read(COPPER_FILE)) + assert_true(isinstance(layer, PCBLayer)) + layer = PCBLayer.from_cam(read(NCDRILL_FILE)) + assert_true(isinstance(layer, DrillLayer)) + layer = PCBLayer.from_cam(read(NETLIST_FILE)) + assert_true(isinstance(layer, PCBLayer)) + assert_equal(layer.layer_class, 'ipc_netlist') + + +def test_PCBLayer_bounds(): + source = read(COPPER_FILE) + layer = PCBLayer.from_cam(source) + assert_equal(source.bounds, layer.bounds) + + +def test_DrillLayer_from_cam(): + no_exceptions = True + try: + layer = DrillLayer.from_cam(read(NCDRILL_FILE)) + assert_true(isinstance(layer, DrillLayer)) + except: + no_exceptions = False + assert_true(no_exceptions) -- cgit