From af97dcf2a8200d9319e20d2789dbb0baa0611ba5 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 22:44:08 -0400 Subject: fix excellon render --- gerber/tests/test_excellon_statements.py | 48 +++++++++++++++++-- gerber/tests/test_utils.py | 81 +++++++++++++++++++------------- 2 files changed, 92 insertions(+), 37 deletions(-) (limited to 'gerber/tests') diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 4fa2b35..5e5e8dc 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -3,7 +3,7 @@ # Author: Hamilton Kibbe -from .tests import * +from .tests import assert_equal, assert_raises from ..excellon_statements import * @@ -65,6 +65,8 @@ def test_toolselection_dump(): def test_coordinatestmt_factory(): + """ Test CoordinateStmt factory method + """ line = 'X0278207Y0065293' stmt = CoordinateStmt.from_excellon(line) assert_equal(stmt.x, 2.78207) @@ -80,6 +82,8 @@ def test_coordinatestmt_factory(): def test_coordinatestmt_dump(): + """ Test CoordinateStmt to_excellon() + """ lines = ['X0278207Y0065293', 'X0243795', 'Y0082528', 'Y0086028', 'X0251295Y0081528', 'X02525Y0078', 'X0255Y00575', 'Y0052', 'X02675', 'Y00575', 'X02425', 'Y0052', 'X023', ] @@ -89,6 +93,8 @@ def test_coordinatestmt_dump(): def test_commentstmt_factory(): + """ Test CommentStmt factory method + """ line = ';Layer_Color=9474304' stmt = CommentStmt.from_excellon(line) assert_equal(stmt.comment, line[1:]) @@ -103,6 +109,8 @@ def test_commentstmt_factory(): def test_commentstmt_dump(): + """ Test CommentStmt to_excellon() + """ lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ] for line in lines: stmt = CommentStmt.from_excellon(line) @@ -110,6 +118,8 @@ def test_commentstmt_dump(): def test_unitstmt_factory(): + """ Test UnitStmt factory method + """ line = 'INCH,LZ' stmt = UnitStmt.from_excellon(line) assert_equal(stmt.units, 'inch') @@ -122,6 +132,8 @@ def test_unitstmt_factory(): def test_unitstmt_dump(): + """ Test UnitStmt to_excellon() + """ lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ] for line in lines: stmt = UnitStmt.from_excellon(line) @@ -129,6 +141,8 @@ def test_unitstmt_dump(): def test_incrementalmode_factory(): + """ Test IncrementalModeStmt factory method + """ line = 'ICI,ON' stmt = IncrementalModeStmt.from_excellon(line) assert_equal(stmt.mode, 'on') @@ -139,6 +153,8 @@ def test_incrementalmode_factory(): def test_incrementalmode_dump(): + """ Test IncrementalModeStmt to_excellon() + """ lines = ['ICI,ON', 'ICI,OFF', ] for line in lines: stmt = IncrementalModeStmt.from_excellon(line) @@ -146,10 +162,14 @@ def test_incrementalmode_dump(): def test_incrementalmode_validation(): + """ Test IncrementalModeStmt input validation + """ assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH') def test_versionstmt_factory(): + """ Test VersionStmt factory method + """ line = 'VER,1' stmt = VersionStmt.from_excellon(line) assert_equal(stmt.version, 1) @@ -160,16 +180,22 @@ def test_versionstmt_factory(): def test_versionstmt_dump(): + """ Test VersionStmt to_excellon() + """ lines = ['VER,1', 'VER,2', ] for line in lines: stmt = VersionStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) def test_versionstmt_validation(): + """ Test VersionStmt input validation + """ assert_raises(ValueError, VersionStmt, 3) def test_formatstmt_factory(): + """ Test FormatStmt factory method + """ line = 'FMAT,1' stmt = FormatStmt.from_excellon(line) assert_equal(stmt.format, 1) @@ -180,6 +206,8 @@ def test_formatstmt_factory(): def test_formatstmt_dump(): + """ Test FormatStmt to_excellon() + """ lines = ['FMAT,1', 'FMAT,2', ] for line in lines: stmt = FormatStmt.from_excellon(line) @@ -187,10 +215,14 @@ def test_formatstmt_dump(): def test_formatstmt_validation(): + """ Test FormatStmt input validation + """ assert_raises(ValueError, FormatStmt, 3) def test_linktoolstmt_factory(): + """ Test LinkToolStmt factory method + """ line = '1/2/3/4' stmt = LinkToolStmt.from_excellon(line) assert_equal(stmt.linked_tools, [1, 2, 3, 4]) @@ -201,13 +233,17 @@ def test_linktoolstmt_factory(): def test_linktoolstmt_dump(): + """ Test LinkToolStmt to_excellon() + """ lines = ['1/2/3/4', '5/6/7', ] for line in lines: stmt = LinkToolStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) -def test_measuringmodestmt_factory(): +def test_measmodestmt_factory(): + """ Test MeasuringModeStmt factory method + """ line = 'M72' stmt = MeasuringModeStmt.from_excellon(line) assert_equal(stmt.units, 'inch') @@ -217,13 +253,17 @@ def test_measuringmodestmt_factory(): assert_equal(stmt.units, 'metric') -def test_measuringmodestmt_dump(): +def test_measmodestmt_dump(): + """ Test MeasuringModeStmt to_excellon() + """ lines = ['M71', 'M72', ] for line in lines: stmt = MeasuringModeStmt.from_excellon(line) assert_equal(stmt.to_excellon(), line) -def test_measuringmodestmt_validation(): +def test_measmodestmt_validation(): + """ Test MeasuringModeStmt input validation + """ assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') assert_raises(ValueError, MeasuringModeStmt, 'millimeters') diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py index 50e2403..001a32f 100644 --- a/gerber/tests/test_utils.py +++ b/gerber/tests/test_utils.py @@ -3,6 +3,7 @@ # Author: Hamilton Kibbe +from .tests import assert_equal from ..utils import decimal_string, parse_gerber_value, write_gerber_value @@ -10,59 +11,73 @@ def test_zero_suppression(): """ Test gerber value parser and writer handle zero suppression correctly. """ # Default format - format = (2, 5) - + fmt = (2, 5) + # Test leading zero suppression zero_suppression = 'leading' test_cases = [('1', 0.00001), ('10', 0.0001), ('100', 0.001), - ('1000', 0.01), ('10000', 0.1), ('100000', 1.0),('1000000', 10.0), - ('-1', -0.00001), ('-10', -0.0001), ('-100', -0.001), - ('-1000', -0.01), ('-10000', -0.1), ('-100000', -1.0),('-1000000', -10.0),] + ('1000', 0.01), ('10000', 0.1), ('100000', 1.0), + ('1000000', 10.0), ('-1', -0.00001), ('-10', -0.0001), + ('-100', -0.001), ('-1000', -0.01), ('-10000', -0.1), + ('-100000', -1.0), ('-1000000', -10.0), ] for string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) + # Test trailing zero suppression zero_suppression = 'trailing' test_cases = [('1', 10.0), ('01', 1.0), ('001', 0.1), ('0001', 0.01), - ('00001', 0.001), ('000001', 0.0001), ('0000001', 0.00001), - ('-1', -10.0), ('-01', -1.0), ('-001', -0.1), ('-0001', -0.01), - ('-00001', -0.001), ('-000001', -0.0001), ('-0000001', -0.00001)] + ('00001', 0.001), ('000001', 0.0001), + ('0000001', 0.00001), ('-1', -10.0), ('-01', -1.0), + ('-001', -0.1), ('-0001', -0.01), ('-00001', -0.001), + ('-000001', -0.0001), ('-0000001', -0.00001)] for string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) def test_format(): """ Test gerber value parser and writer handle format correctly """ zero_suppression = 'leading' - test_cases = [((2,7),'1',0.0000001), ((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,7),'-1',-0.0000001), - ((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),] - for format, string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + test_cases = [((2, 7), '1', 0.0000001), ((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, 7), '-1', -0.0000001), + ((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), ] + for fmt, string, value in test_cases: + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) + zero_suppression = 'trailing' - test_cases = [((6, 5), '1' , 100000.0), ((5, 5), '1', 10000.0), - ((4, 5), '1', 1000.0), ((3, 5), '1', 100.0),((2, 5), '1', 10.0), - ((1, 5), '1', 1.0), ((6, 5), '-1' , -100000.0), - ((5, 5), '-1', -10000.0), ((4, 5), '-1', -1000.0), - ((3, 5), '-1', -100.0),((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0),] - for format, string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) + test_cases = [((6, 5), '1', 100000.0), ((5, 5), '1', 10000.0), + ((4, 5), '1', 1000.0), ((3, 5), '1', 100.0), + ((2, 5), '1', 10.0), ((1, 5), '1', 1.0), + ((6, 5), '-1', -100000.0), ((5, 5), '-1', -10000.0), + ((4, 5), '-1', -1000.0), ((3, 5), '-1', -100.0), + ((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0), ] + for fmt, string, value in test_cases: + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) def test_decimal_truncation(): - """ Test decimal string truncates value to the correct precision + """ Test decimal_string truncates value to the correct precision """ 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)) - assert(result == calculated) \ No newline at end of file + assert(result == calculated) + + +def test_decimal_padding(): + """ Test decimal_string padding + """ + value = 1.123 + assert_equal(decimal_string(value, precision=3, padding=True), '1.123') + assert_equal(decimal_string(value, precision=4, padding=True), '1.1230') + assert_equal(decimal_string(value, precision=5, padding=True), '1.12300') + assert_equal(decimal_string(value, precision=6, padding=True), '1.123000') -- cgit