diff options
Diffstat (limited to 'gerber/tests')
-rw-r--r-- | gerber/tests/test_am_statements.py | 5 | ||||
-rw-r--r-- | gerber/tests/test_cam.py | 6 | ||||
-rw-r--r-- | gerber/tests/test_excellon.py | 26 | ||||
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 72 | ||||
-rw-r--r-- | gerber/tests/test_gerber_statements.py | 45 | ||||
-rw-r--r-- | gerber/tests/test_primitives.py | 235 | ||||
-rw-r--r-- | gerber/tests/test_rs274x.py | 20 |
7 files changed, 388 insertions, 21 deletions
diff --git a/gerber/tests/test_am_statements.py b/gerber/tests/test_am_statements.py index 696d951..0cee13d 100644 --- a/gerber/tests/test_am_statements.py +++ b/gerber/tests/test_am_statements.py @@ -324,6 +324,11 @@ def test_AMUnsupportPrimitive(): 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(): diff --git a/gerber/tests/test_cam.py b/gerber/tests/test_cam.py index 185e716..6296cc9 100644 --- a/gerber/tests/test_cam.py +++ b/gerber/tests/test_cam.py @@ -65,9 +65,9 @@ def test_camfile_settings(): cf = CamFile() assert_equal(cf.settings, FileSettings()) -#def test_bounds_override(): -# cf = CamFile() -# assert_raises(NotImplementedError, cf.bounds) +def test_bounds_override_smoketest(): + cf = CamFile() + cf.bounds def test_zeros(): diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index ea067b5..24cf793 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -2,12 +2,13 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe <ham@hamiltonkib.be> +import os + from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from ..excellon_statements import ExcellonTool from tests import * -import os NCDRILL_FILE = os.path.join(os.path.dirname(__file__), 'resources/ncdrill.DRD') @@ -37,6 +38,29 @@ def test_bounds(): def test_report(): ncdrill = read(NCDRILL_FILE) + +def test_conversion(): + import copy + ncdrill = read(NCDRILL_FILE) + assert_equal(ncdrill.settings.units, 'inch') + ncdrill_inch = copy.deepcopy(ncdrill) + ncdrill.to_metric() + assert_equal(ncdrill.settings.units, 'metric') + + for tool in ncdrill_inch.tools.itervalues(): + tool.to_metric() + for primitive in ncdrill_inch.primitives: + primitive.to_metric() + for statement in ncdrill_inch.statements: + statement.to_metric() + + for m_tool, i_tool in zip(ncdrill.tools.itervalues(), ncdrill_inch.tools.itervalues()): + assert_equal(i_tool, m_tool) + + for m, i in zip(ncdrill.primitives,ncdrill_inch.primitives): + assert_equal(m, i) + + def test_parser_hole_count(): settings = FileSettings(**detect_excellon_format(NCDRILL_FILE)) p = ExcellonParser(settings) 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 <ham@hamiltonkib.be> -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), '<ExcellonTool 08: 0.125in. dia.>') tool = ExcellonTool.from_dict(FileSettings(units='metric'), {'number': 8, 'diameter': 0.125}) assert_equal(str(tool), '<ExcellonTool 08: 0.125mm dia.>') +def test_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), '<Repeat Hole: 4 times>') @@ -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 diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index c6040c0..bf7035f 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -7,6 +7,12 @@ from .tests import * from ..gerber_statements import * from ..cam import FileSettings +def test_Statement_smoketest(): + stmt = Statement('Test') + assert_equal(stmt.type, 'Test') + stmt.to_inch() + stmt.to_metric() + assert_equal(str(stmt), '<Statement type=Test>') def test_FSParamStmt_factory(): """ Test FSParamStruct factory @@ -114,6 +120,17 @@ def test_MOParamStmt_dump(): assert_equal(mo.to_gerber(), '%MOMM*%') +def test_MOParamStmt_conversion(): + stmt = {'param': 'MO', 'mo': 'MM'} + mo = MOParamStmt.from_dict(stmt) + mo.to_inch() + assert_equal(mo.mode, 'inch') + + stmt = {'param': 'MO', 'mo': 'IN'} + mo = MOParamStmt.from_dict(stmt) + mo.to_metric() + assert_equal(mo.mode, 'metric') + def test_MOParamStmt_string(): """ Test MOParamStmt.__str__() """ @@ -213,6 +230,20 @@ def test_OFParamStmt_dump(): 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.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} + of = OFParamStmt.from_dict(stmt) + of.to_metric() + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + def test_OFParamStmt_string(): """ Test OFParamStmt __str__ """ @@ -232,6 +263,19 @@ def test_SFParamStmt_dump(): 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.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} + of = SFParamStmt.from_dict(stmt) + of.to_metric() + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + def test_SFParamStmt_string(): stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} sf = SFParamStmt.from_dict(stmt) @@ -651,4 +695,3 @@ def test_aperturestmt_dump(): assert_equal(str(ast), '<Aperture: 3>') -
\ No newline at end of file diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index f8b8620..cada6d4 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -51,6 +51,57 @@ def test_line_bounds(): 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) + assert_equal(l.vertices, None) + + # 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))),] + 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) + l = Line((2.54, 25.4), (254.0, 2540.0), c) + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.diameter, 1.0) + + c = Circle((0, 0), 1.0) + l = Line((0.1, 1.0), (10.0, 100.0), c) + 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) + + r = Rectangle((0, 0), 25.4, 254.0) + l = Line((2.54, 25.4), (254.0, 2540.0), r) + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.width, 1.0) + assert_equal(l.aperture.height, 10.0) + + r = Rectangle((0, 0), 1.0, 10.0) + l = Line((0.1, 1.0), (10.0, 100.0), r) + l.to_metric() + assert_equal(l.start, (2.54, 25.4)) + assert_equal(l.end, (254.0, 2540.0)) + assert_equal(l.aperture.width, 25.4) + assert_equal(l.aperture.height, 254.0) def test_arc_radius(): @@ -89,6 +140,24 @@ def test_arc_bounds(): a = Arc(start, end, center, direction, c) assert_equal(a.bounding_box, bounds) +def test_arc_conversion(): + c = Circle((0, 0), 25.4) + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c) + a.to_inch() + assert_equal(a.start, (0.1, 1.0)) + assert_equal(a.end, (10.0, 100.0)) + assert_equal(a.center, (1000.0, 10000.0)) + assert_equal(a.aperture.diameter, 1.0) + + c = Circle((0, 0), 1.0) + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c) + 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_circle_radius(): """ Test Circle primitive radius calculation @@ -146,7 +215,7 @@ def test_rectangle_bounds(): 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_diamond_ctor(): """ Test diamond creation """ @@ -169,6 +238,19 @@ def test_diamond_bounds(): 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) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.width, 10.0) + assert_equal(d.height, 100.0) + + d = Diamond((0.1, 1.0), 10.0, 100.0) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.width, 254.0) + assert_equal(d.height, 2540.0) + def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation @@ -198,6 +280,21 @@ def test_chamfer_rectangle_bounds(): 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)) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + 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)) + r.to_metric() + 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_round_rectangle_ctor(): """ Test round rectangle creation """ @@ -226,6 +323,21 @@ def test_round_rectangle_bounds(): 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)) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + 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)) + r.to_metric() + 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_obround_ctor(): """ Test obround creation """ @@ -270,7 +382,22 @@ def test_obround_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) + 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) + 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_polygon_ctor(): """ Test polygon creation """ @@ -282,7 +409,7 @@ def test_polygon_ctor(): assert_equal(p.position, pos) assert_equal(p.sides, sides) assert_equal(p.radius, radius) - + def test_polygon_bounds(): """ Test polygon bounding box calculation """ @@ -296,6 +423,18 @@ def test_polygon_bounds(): assert_array_almost_equal(ybounds, (-2, 6)) +def test_polygon_conversion(): + p = Polygon((2.54, 25.4), 3, 254.0) + 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) + p.to_metric() + assert_equal(p.position, (2.54, 25.4)) + assert_equal(p.radius, 254.0) + + def test_region_ctor(): """ Test Region creation """ @@ -313,8 +452,20 @@ def test_region_bounds(): xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (0, 1)) assert_array_almost_equal(ybounds, (0, 1)) - - + +def test_region_conversion(): + points = ((2.54, 25.4), (254.0,2540.0), (25400.0,254000.0), (2.54,25.4)) + r = Region(points) + r.to_inch() + assert_equal(set(r.points), {(0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0)}) + + points = ((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), (0.1, 1.0)) + r = Region(points) + r.to_metric() + assert_equal(set(r.points), {(2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0)}) + + + def test_round_butterfly_ctor(): """ Test round butterfly creation """ @@ -331,6 +482,18 @@ def test_round_butterfly_ctor_validation(): assert_raises(TypeError, RoundButterfly, 3, 5) assert_raises(TypeError, RoundButterfly, (3,4,5), 5) + +def test_round_butterfly_conversion(): + b = RoundButterfly((2.54, 25.4), 254.0) + 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) + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.diameter, (254.0)) + def test_round_butterfly_bounds(): """ Test RoundButterfly bounding box calculation """ @@ -338,7 +501,7 @@ def test_round_butterfly_bounds(): xbounds, ybounds = b.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - + def test_square_butterfly_ctor(): """ Test SquareButterfly creation """ @@ -363,6 +526,17 @@ 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) + 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) + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.side, (254.0)) + def test_donut_ctor(): """ Test Donut primitive creation """ @@ -380,9 +554,28 @@ def test_donut_ctor_validation(): assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) - + def test_donut_bounds(): - pass + 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) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.inner_diameter, 10.0) + assert_equal(d.outer_diaemter, 100.0) + + d = Donut((0.1, 1.0), 'round', 10.0, 100.0) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.inner_diameter, 254.0) + assert_equal(d.outer_diaemter, 2540.0) + def test_drill_ctor(): """ Test drill primitive creation @@ -393,13 +586,15 @@ def test_drill_ctor(): assert_equal(d.position, position) assert_equal(d.diameter, diameter) assert_equal(d.radius, diameter/2.) - + + def test_drill_ctor_validation(): """ Test drill argument validation """ assert_raises(TypeError, Drill, 3, 5) assert_raises(TypeError, Drill, (3,4,5), 5) - + + def test_drill_bounds(): d = Drill((0, 0), 2) xbounds, ybounds = d.bounding_box @@ -409,5 +604,21 @@ def test_drill_bounds(): xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (0, 2)) assert_array_almost_equal(ybounds, (1, 3)) - -
\ No newline at end of file + +def test_drill_conversion(): + d = Drill((2.54, 25.4), 254.) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.diameter, 10.0) + + d = Drill((0.1, 1.0), 10.) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.diameter, 254.0) + +def test_drill_equality(): + d = Drill((2.54, 25.4), 254.) + d1 = Drill((2.54, 25.4), 254.) + assert_equal(d, d1) + d1 = Drill((2.54, 25.4), 254.2) + assert_not_equal(d, d1) diff --git a/gerber/tests/test_rs274x.py b/gerber/tests/test_rs274x.py index 5d528dc..27f6f49 100644 --- a/gerber/tests/test_rs274x.py +++ b/gerber/tests/test_rs274x.py @@ -2,10 +2,11 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe <ham@hamiltonkib.be> +import os + from ..rs274x import read, GerberFile from tests import * -import os TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), 'resources/top_copper.GTL') @@ -25,3 +26,20 @@ def test_size_parameter(): assert_equal(size[0], 2.2869) assert_equal(size[1], 1.8064) +def test_conversion(): + import copy + top_copper = read(TOP_COPPER_FILE) + assert_equal(top_copper.units, 'inch') + top_copper_inch = copy.deepcopy(top_copper) + top_copper.to_metric() + for statement in top_copper_inch.statements: + statement.to_metric() + for primitive in top_copper_inch.primitives: + primitive.to_metric() + assert_equal(top_copper.units, 'metric') + for i, m in zip(top_copper.statements, top_copper_inch.statements): + assert_equal(i, m) + + for i, m in zip(top_copper.primitives, top_copper_inch.primitives): + assert_equal(i, m) + |