From b3e0ceb5c3ec755b09d2f005b8e3dcbed22d45a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 20 Feb 2015 22:24:34 -0500 Subject: Add IPC-D-356 Netlist Parsing --- gerber/tests/test_ipc356.py | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 gerber/tests/test_ipc356.py (limited to 'gerber/tests/test_ipc356.py') diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py new file mode 100644 index 0000000..760608c --- /dev/null +++ b/gerber/tests/test_ipc356.py @@ -0,0 +1,116 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe +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') +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') + assert_equal(ipcfile.settings.angle_units, 'degrees') + assert_equal(len(ipcfile.comments), 3) + assert_equal(len(ipcfile.parameters), 4) + assert_equal(len(ipcfile.test_records), 105) + assert_equal(len(ipcfile.components), 21) + assert_equal(len(ipcfile.vias), 14) + assert_equal(ipcfile.test_records[-1].net_name, 'A_REALLY_LONG_NET_NAME') + assert_equal(set(ipcfile.board_outline), + {(0., 0.), (2.25, 0.), (2.25, 1.5), (0., 1.5)}) + +def test_comment(): + c = IPC356_Comment('Layer Stackup:') + assert_equal(c.comment, 'Layer Stackup:') + c = IPC356_Comment.from_line('C Layer Stackup: ') + assert_equal(c.comment, 'Layer Stackup:') + 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') + assert_equal(p.value, 'IPC-D-356A') + 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_equal(str(p), '') + +def test_eof(): + e = IPC356_EndOfFile() + assert_equal(e.to_netlist(), '999') + assert_equal(str(e), '') + +def test_board_edge(): + points = [(0.01, 0.01), (2., 2.), (4., 2.), (4., 6.)] + b = IPC356_BoardEdge(points) + assert_equal(b.points, points) + b = IPC356_BoardEdge.from_line('389BOARD_EDGE X100Y100 X20000Y20000' + ' X40000 Y60000', FileSettings(units='inch')) + assert_equal(b.points, points) + +def test_test_record(): + 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') + assert_equal(r.net_name, '+5VDC') + assert_equal(r.id, 'VIA') + assert_almost_equal(r.hole_diameter, 0.015) + assert_true(r.plated) + assert_equal(r.access, 'both') + assert_almost_equal(r.x_coord, 0.6647) + assert_almost_equal(r.y_coord, 1.29) + assert_equal(r.rect_x, 0.) + assert_equal(r.soldermask_info, '3') + r = IPC356_TestRecord.from_line(record_string, FileSettings(units='metric')) + assert_almost_equal(r.hole_diameter, 0.15) + 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), + '') + + record_string = '327+3.3VDC R40 -1 PA01X 032100Y 007124X0236Y0315R180 S0' + r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) + assert_equal(r.feature_type, 'smt') + assert_equal(r.net_name, '+3.3VDC') + assert_equal(r.id, 'R40') + assert_equal(r.pin, '1') + assert_true(r.plated) + assert_equal(r.access, 'top') + assert_almost_equal(r.x_coord, 3.21) + assert_almost_equal(r.y_coord, 0.7124) + assert_almost_equal(r.rect_x, 0.0236) + assert_almost_equal(r.rect_y, 0.0315) + assert_equal(r.rect_rotation, 180) + assert_equal(r.soldermask_info, '0') + 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 S0' + r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) + assert_equal(r.feature_type, 'through-hole') + assert_equal(r.id, 'J4') + assert_equal(r.pin, 'M2') + assert_almost_equal(r.hole_diameter, 0.033) + assert_true(r.plated) + assert_equal(r.access, 'both') + assert_almost_equal(r.x_coord, 1.2447) + assert_almost_equal(r.y_coord, 0.8030) + assert_almost_equal(r.rect_x, 0.) + assert_equal(r.soldermask_info, '0') + -- cgit From 68619d4d5a7beb38dc81d953b43bf4196ca1d3a6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 5 Mar 2015 22:42:42 -0500 Subject: Fix parsing for multiline ipc-d-356 records --- gerber/tests/test_ipc356.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/tests/test_ipc356.py') diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index 760608c..88726a5 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -25,7 +25,7 @@ def test_parser(): assert_equal(len(ipcfile.vias), 14) assert_equal(ipcfile.test_records[-1].net_name, 'A_REALLY_LONG_NET_NAME') assert_equal(set(ipcfile.board_outline), - {(0., 0.), (2.25, 0.), (2.25, 1.5), (0., 1.5)}) + {(0., 0.), (2.25, 0.), (2.25, 1.5), (0., 1.5), (0.13, 0.024)}) def test_comment(): c = IPC356_Comment('Layer Stackup:') -- cgit From 45372cfff3d228851e546a2603496db1e499f86b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 6 Mar 2015 17:00:40 -0500 Subject: fix tests --- gerber/tests/test_ipc356.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'gerber/tests/test_ipc356.py') diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index 88726a5..5ccc7b8 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -24,7 +24,8 @@ def test_parser(): assert_equal(len(ipcfile.components), 21) assert_equal(len(ipcfile.vias), 14) assert_equal(ipcfile.test_records[-1].net_name, 'A_REALLY_LONG_NET_NAME') - assert_equal(set(ipcfile.board_outline), + assert_equal(ipcfile.outlines[0].type, 'BOARD_EDGE') + 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(): @@ -50,12 +51,15 @@ def test_eof(): assert_equal(e.to_netlist(), '999') assert_equal(str(e), '') -def test_board_edge(): +def test_outline(): + type = 'BOARD_EDGE' points = [(0.01, 0.01), (2., 2.), (4., 2.), (4., 6.)] - b = IPC356_BoardEdge(points) + b = IPC356_Outline(type, points) + assert_equal(b.type, type) assert_equal(b.points, points) - b = IPC356_BoardEdge.from_line('389BOARD_EDGE X100Y100 X20000Y20000' + 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(): @@ -71,14 +75,14 @@ def test_test_record(): assert_almost_equal(r.x_coord, 0.6647) assert_almost_equal(r.y_coord, 1.29) assert_equal(r.rect_x, 0.) - assert_equal(r.soldermask_info, '3') + assert_equal(r.soldermask_info, 'both') r = IPC356_TestRecord.from_line(record_string, FileSettings(units='metric')) assert_almost_equal(r.hole_diameter, 0.15) 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), - '') + '') record_string = '327+3.3VDC R40 -1 PA01X 032100Y 007124X0236Y0315R180 S0' r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) @@ -93,7 +97,7 @@ def test_test_record(): assert_almost_equal(r.rect_x, 0.0236) assert_almost_equal(r.rect_y, 0.0315) assert_equal(r.rect_rotation, 180) - assert_equal(r.soldermask_info, '0') + assert_equal(r.soldermask_info, 'none') 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) @@ -101,7 +105,7 @@ def test_test_record(): assert_almost_equal(r.rect_y, 0.315) - record_string = '317 J4 -M2 D0330PA00X 012447Y 008030X0000 S0' + 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') assert_equal(r.id, 'J4') @@ -112,5 +116,5 @@ def test_test_record(): assert_almost_equal(r.x_coord, 1.2447) assert_almost_equal(r.y_coord, 0.8030) assert_almost_equal(r.rect_x, 0.) - assert_equal(r.soldermask_info, '0') + assert_equal(r.soldermask_info, 'primary side') -- cgit From faa44ab73135ee111b9856dcdd155540cb67cfc3 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Mon, 1 Jun 2015 20:58:16 -0400 Subject: Fix IPC-D-356 parser. Handle too-long reference designators exported by eagle per #28. --- gerber/tests/test_ipc356.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gerber/tests/test_ipc356.py') diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index 5ccc7b8..f123a38 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -118,3 +118,13 @@ def test_test_record(): assert_almost_equal(r.rect_x, 0.) assert_equal(r.soldermask_info, 'primary side') + record_string = '317SCL COMMUNICATION-1 D 40PA00X 34000Y 20000X 600Y1200R270 ' + r = IPC356_TestRecord.from_line(record_string, FileSettings(units='inch')) + assert_equal(r.feature_type, 'through-hole') + assert_equal(r.net_name, 'SCL') + assert_equal(r.id, 'COMMUNICATION') + assert_equal(r.pin, '1') + assert_almost_equal(r.hole_diameter, 0.004) + assert_true(r.plated) + assert_almost_equal(r.x_coord, 3.4) + assert_almost_equal(r.y_coord, 2.0) -- cgit From 8cd842a41a55ab3d8f558a2e3e198beba7da58a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Manually mere rendering changes --- gerber/tests/test_ipc356.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'gerber/tests/test_ipc356.py') 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') -- cgit