diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-05-16 09:45:34 -0400 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-05-16 09:45:34 -0400 |
commit | 8ec3077be988681bbbafcef18ea3a2f84dd61b2b (patch) | |
tree | 97b108fe6ca1d128420f58360f9976a3ca0ee0f0 /gerber/tests | |
parent | 21d963d244cbc762a736527b25cd8e82ff147f25 (diff) | |
download | gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.tar.gz gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.tar.bz2 gerbonara-8ec3077be988681bbbafcef18ea3a2f84dd61b2b.zip |
Add checks to ensure statement unit conversions are idempotent
Diffstat (limited to 'gerber/tests')
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 116 | ||||
-rw-r--r-- | gerber/tests/test_gerber_statements.py | 152 |
2 files changed, 254 insertions, 14 deletions
diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index ada5194..1e8ef91 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -150,7 +150,13 @@ def test_coordinatestmt_factory(): assert_equal(stmt.x, 0.9660) assert_equal(stmt.y, 0.4639) assert_equal(stmt.to_excellon(settings), "X9660Y4639") - + assert_equal(stmt.units, 'inch') + + settings.units = 'metric' + stmt = CoordinateStmt.from_excellon(line, settings) + assert_equal(stmt.units, 'metric') + + def test_coordinatestmt_dump(): """ Test CoordinateStmt to_excellon() """ @@ -164,11 +170,40 @@ def test_coordinatestmt_dump(): assert_equal(stmt.to_excellon(settings), line) def test_coordinatestmt_conversion(): - stmt = CoordinateStmt.from_excellon('X254Y254', FileSettings()) + + settings = FileSettings() + settings.units = 'metric' + stmt = CoordinateStmt.from_excellon('X254Y254', settings) + + #No effect + stmt.to_metric() + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 25.4) + stmt.to_inch() + assert_equal(stmt.units, 'inch') assert_equal(stmt.x, 1.) assert_equal(stmt.y, 1.) - stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 1.) + + settings.units = 'inch' + stmt = CoordinateStmt.from_excellon('X01Y01', settings) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 1.) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 25.4) + + #No effect stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 25.4) @@ -194,10 +229,14 @@ def test_coordinatestmt_string(): def test_repeathole_stmt_factory(): - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading')) + stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='inch')) assert_equal(stmt.count, 4) assert_equal(stmt.xdelta, 1.5) assert_equal(stmt.ydelta, 32) + assert_equal(stmt.units, 'inch') + + stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', FileSettings(zeros='leading', units='metric')) + assert_equal(stmt.units, 'metric') def test_repeatholestmt_dump(): line = 'R4X015Y32' @@ -206,13 +245,40 @@ def test_repeatholestmt_dump(): def test_repeatholestmt_conversion(): line = 'R4X0254Y254' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #No effect + stmt.to_metric() + assert_equal(stmt.xdelta, 2.54) + assert_equal(stmt.ydelta, 25.4) + + stmt.to_inch() + assert_equal(stmt.units, 'inch') + assert_equal(stmt.xdelta, 0.1) + assert_equal(stmt.ydelta, 1.) + + #no effect stmt.to_inch() assert_equal(stmt.xdelta, 0.1) assert_equal(stmt.ydelta, 1.) line = 'R4X01Y1' - stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) + settings.units = 'inch' + stmt = RepeatHoleStmt.from_excellon(line, settings) + + #no effect + stmt.to_inch() + assert_equal(stmt.xdelta, 1.) + assert_equal(stmt.ydelta, 10.) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.xdelta, 25.4) + assert_equal(stmt.ydelta, 254.) + + #No effect stmt.to_metric() assert_equal(stmt.xdelta, 25.4) assert_equal(stmt.ydelta, 254.) @@ -258,12 +324,16 @@ def test_rewindstop_stmt(): assert_equal(stmt.to_excellon(None), '%') def test_endofprogramstmt_factory(): - stmt = EndOfProgramStmt.from_excellon('M30X01Y02', FileSettings()) + settings = FileSettings(units='inch') + stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, 2.) - stmt = EndOfProgramStmt.from_excellon('M30X01', FileSettings()) + assert_equal(stmt.units, 'inch') + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X01', settings) assert_equal(stmt.x, 1.) assert_equal(stmt.y, None) + assert_equal(stmt.units, 'metric') stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) assert_equal(stmt.x, None) assert_equal(stmt.y, 2.) @@ -275,12 +345,38 @@ def test_endofprogramStmt_dump(): assert_equal(stmt.to_excellon(FileSettings()), line) def test_endofprogramstmt_conversion(): - stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', FileSettings()) + settings = FileSettings() + settings.units = 'metric' + stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings) + #No effect + stmt.to_metric() + assert_equal(stmt.x, 2.54) + assert_equal(stmt.y, 25.4) + + stmt.to_inch() + assert_equal(stmt.units, 'inch') + assert_equal(stmt.x, 0.1) + assert_equal(stmt.y, 1.0) + + #No effect stmt.to_inch() assert_equal(stmt.x, 0.1) assert_equal(stmt.y, 1.0) - stmt = EndOfProgramStmt.from_excellon('M30X01Y1', FileSettings()) + settings.units = 'inch' + stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings) + + #No effect + stmt.to_inch() + assert_equal(stmt.x, 1.) + assert_equal(stmt.y, 10.0) + + stmt.to_metric() + assert_equal(stmt.units, 'metric') + assert_equal(stmt.x, 25.4) + assert_equal(stmt.y, 254.) + + #No effect stmt.to_metric() assert_equal(stmt.x, 25.4) assert_equal(stmt.y, 254.) diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index a8a4a1a..f3249b1 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -10,10 +10,13 @@ from ..cam import FileSettings def test_Statement_smoketest(): stmt = Statement('Test') assert_equal(stmt.type, 'Test') + stmt.to_metric() + assert_in('units=metric', str(stmt)) stmt.to_inch() + assert_in('units=inch', str(stmt)) stmt.to_metric() stmt.offset(1, 1) - assert_equal(str(stmt), '<Statement type=Test>') + assert_in('type=Test',str(stmt)) def test_FSParamStmt_factory(): """ Test FSParamStruct factory @@ -220,12 +223,38 @@ def test_OFParamStmt_dump(): def test_OFParamStmt_conversion(): stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} of = OFParamStmt.from_dict(stmt) + of.units='metric' + + # No effect + of.to_metric() + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + of.to_inch() + assert_equal(of.units, 'inch') + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + #No effect 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.units = 'inch' + + #No effect + of.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + of.to_metric() + assert_equal(of.units, 'metric') + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + #No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) @@ -261,12 +290,38 @@ def test_SFParamStmt_dump(): 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 + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + of.to_inch() + assert_equal(of.units, 'inch') + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + #No effect 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.units = 'inch' + + #No effect + of.to_inch() + assert_equal(of.a, 0.1) + assert_equal(of.b, 1.0) + + of.to_metric() + assert_equal(of.units, 'metric') + assert_equal(of.a, 2.54) + assert_equal(of.b, 25.4) + + #No effect of.to_metric() assert_equal(of.a, 2.54) assert_equal(of.b, 25.4) @@ -350,7 +405,21 @@ 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.build() + s.units = 'metric' + + #No effect + s.to_metric() + assert_equal(s.primitives[0].position, (25.4, 25.4)) + assert_equal(s.primitives[0].diameter, 25.4) + + s.to_inch() + assert_equal(s.units, 'inch') + assert_equal(s.primitives[0].position, (1., 1.)) + assert_equal(s.primitives[0].diameter, 1.) + + #No effect s.to_inch() assert_equal(s.primitives[0].position, (1., 1.)) assert_equal(s.primitives[0].diameter, 1.) @@ -358,6 +427,19 @@ def testAMParamStmt_conversion(): macro = '5,1,8,1,1,1,0*' s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro }) s.build() + s.units = 'inch' + + #No effect + s.to_inch() + assert_equal(s.primitives[0].position, (1., 1.)) + assert_equal(s.primitives[0].diameter, 1.) + + s.to_metric() + assert_equal(s.units, 'metric') + assert_equal(s.primitives[0].position, (25.4, 25.4)) + assert_equal(s.primitives[0].diameter, 25.4) + + #No effect s.to_metric() assert_equal(s.primitives[0].position, (25.4, 25.4)) assert_equal(s.primitives[0].diameter, 25.4) @@ -535,10 +617,10 @@ def test_statement_string(): """ Test Statement.__str__() """ stmt = Statement('PARAM') - assert_equal(str(stmt), '<Statement type=PARAM>') + assert_in('type=PARAM', str(stmt)) stmt.test='PASS' - assert_true('test=PASS' in str(stmt)) - assert_true('type=PARAM' in str(stmt)) + assert_in('test=PASS', str(stmt)) + assert_in('type=PARAM', str(stmt)) def test_ADParamStmt_factory(): """ Test ADParamStmt factory @@ -556,12 +638,37 @@ def test_ADParamStmt_factory(): def test_ADParamStmt_conversion(): stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '25.4X25.4,25.4X25.4'} ad = ADParamStmt.from_dict(stmt) + ad.units = 'metric' + + #No effect + ad.to_metric() + assert_equal(ad.modifiers[0], (25.4, 25.4)) + assert_equal(ad.modifiers[1], (25.4, 25.4)) + + ad.to_inch() + assert_equal(ad.units, 'inch') + assert_equal(ad.modifiers[0], (1., 1.)) + assert_equal(ad.modifiers[1], (1., 1.)) + + #No effect ad.to_inch() assert_equal(ad.modifiers[0], (1., 1.)) assert_equal(ad.modifiers[1], (1., 1.)) stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '1X1,1X1'} ad = ADParamStmt.from_dict(stmt) + ad.units = 'inch' + + #No effect + ad.to_inch() + assert_equal(ad.modifiers[0], (1., 1.)) + assert_equal(ad.modifiers[1], (1., 1.)) + + ad.to_metric() + assert_equal(ad.modifiers[0], (25.4, 25.4)) + assert_equal(ad.modifiers[1], (25.4, 25.4)) + + #No effect ad.to_metric() assert_equal(ad.modifiers[0], (25.4, 25.4)) assert_equal(ad.modifiers[1], (25.4, 25.4)) @@ -646,6 +753,25 @@ def test_coordstmt_dump(): def test_coordstmt_conversion(): cs = CoordStmt('G71', 25.4, 25.4, 25.4, 25.4, 'D01', FileSettings()) + cs.units = 'metric' + + #No effect + cs.to_metric() + assert_equal(cs.x, 25.4) + assert_equal(cs.y, 25.4) + assert_equal(cs.i, 25.4) + assert_equal(cs.j, 25.4) + assert_equal(cs.function, 'G71') + + cs.to_inch() + assert_equal(cs.units, 'inch') + assert_equal(cs.x, 1.) + assert_equal(cs.y, 1.) + assert_equal(cs.i, 1.) + assert_equal(cs.j, 1.) + assert_equal(cs.function, 'G70') + + #No effect cs.to_inch() assert_equal(cs.x, 1.) assert_equal(cs.y, 1.) @@ -654,6 +780,24 @@ def test_coordstmt_conversion(): assert_equal(cs.function, 'G70') cs = CoordStmt('G70', 1., 1., 1., 1., 'D01', FileSettings()) + cs.units = 'inch' + + #No effect + cs.to_inch() + assert_equal(cs.x, 1.) + assert_equal(cs.y, 1.) + assert_equal(cs.i, 1.) + assert_equal(cs.j, 1.) + assert_equal(cs.function, 'G70') + + cs.to_metric() + assert_equal(cs.x, 25.4) + assert_equal(cs.y, 25.4) + assert_equal(cs.i, 25.4) + assert_equal(cs.j, 25.4) + assert_equal(cs.function, 'G71') + + #No effect cs.to_metric() assert_equal(cs.x, 25.4) assert_equal(cs.y, 25.4) |