diff options
Diffstat (limited to 'gerbonara/gerber/tests')
-rw-r--r-- | gerbonara/gerber/tests/test_ipc356.py | 191 | ||||
-rw-r--r-- | gerbonara/gerber/tests/test_pcb.py | 7 | ||||
-rw-r--r-- | gerbonara/gerber/tests/test_rs274x_backend.py | 68 |
3 files changed, 52 insertions, 214 deletions
diff --git a/gerbonara/gerber/tests/test_ipc356.py b/gerbonara/gerber/tests/test_ipc356.py index 77f0782..2a39a79 100644 --- a/gerbonara/gerber/tests/test_ipc356.py +++ b/gerbonara/gerber/tests/test_ipc356.py @@ -3,146 +3,59 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> import pytest + from ..ipc356 import * from ..cam import FileSettings -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, IPCNetlist) - - -def test_parser(): - ipcfile = read(IPC_D_356_FILE) - assert ipcfile.settings.units == "inch" - assert ipcfile.settings.angle_units == "degrees" - assert len(ipcfile.comments) == 3 - assert len(ipcfile.parameters) == 4 - assert len(ipcfile.test_records) == 105 - assert len(ipcfile.components) == 21 - assert len(ipcfile.vias) == 14 - assert ipcfile.test_records[-1].net_name == "A_REALLY_LONG_NET_NAME" - assert ipcfile.outlines[0].type == "BOARD_EDGE" - assert set(ipcfile.outlines[0].points) == { - (0.0, 0.0), - (2.25, 0.0), - (2.25, 1.5), - (0.0, 1.5), - (0.13, 0.024), - } - - -def test_comment(): - c = IPC356_Comment("Layer Stackup:") - assert c.comment == "Layer Stackup:" - c = IPC356_Comment.from_line("C Layer Stackup: ") - assert c.comment == "Layer Stackup:" - pytest.raises(ValueError, IPC356_Comment.from_line, "P JOB") - assert str(c) == "<IPC-D-356 Comment: Layer Stackup:>" - - -def test_parameter(): - p = IPC356_Parameter("VER", "IPC-D-356A") - assert p.parameter == "VER" - assert p.value == "IPC-D-356A" - p = IPC356_Parameter.from_line("P VER IPC-D-356A ") - assert p.parameter == "VER" - assert p.value == "IPC-D-356A" - pytest.raises(ValueError, IPC356_Parameter.from_line, "C Layer Stackup: ") - assert str(p) == "<IPC-D-356 Parameter: VER=IPC-D-356A>" - - -def test_eof(): - e = IPC356_EndOfFile() - assert e.to_netlist() == "999" - assert str(e) == "<IPC-D-356 EOF>" - - -def test_outline(): - type = "BOARD_EDGE" - points = [(0.01, 0.01), (2.0, 2.0), (4.0, 2.0), (4.0, 6.0)] - b = IPC356_Outline(type, points) - assert b.type == type - assert b.points == points - b = IPC356_Outline.from_line( - "389BOARD_EDGE X100Y100 X20000Y20000 X40000 Y60000", - FileSettings(units="inch"), - ) - assert b.type == "BOARD_EDGE" - assert b.points == points - - -def test_test_record(): - pytest.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 r.feature_type == "through-hole" - assert r.net_name == "+5VDC" - assert r.id == "VIA" - pytest.approx(r.hole_diameter, 0.015) - assert r.plated - assert r.access == "both" - pytest.approx(r.x_coord, 0.6647) - pytest.approx(r.y_coord, 1.29) - assert r.rect_x == 0.0 - assert r.soldermask_info == "both" - r = IPC356_TestRecord.from_line(record_string, FileSettings(units="metric")) - pytest.approx(r.hole_diameter, 0.15) - pytest.approx(r.x_coord, 6.647) - pytest.approx(r.y_coord, 12.9) - assert r.rect_x == 0.0 - assert str(r) == "<IPC-D-356 +5VDC Test Record: through-hole>" - - record_string = ( - "327+3.3VDC R40 -1 PA01X 032100Y 007124X0236Y0315R180 S0" - ) - r = IPC356_TestRecord.from_line(record_string, FileSettings(units="inch")) - assert r.feature_type == "smt" - assert r.net_name == "+3.3VDC" - assert r.id == "R40" - assert r.pin == "1" - assert r.plated - assert r.access == "top" - pytest.approx(r.x_coord, 3.21) - pytest.approx(r.y_coord, 0.7124) - pytest.approx(r.rect_x, 0.0236) - pytest.approx(r.rect_y, 0.0315) - assert r.rect_rotation == 180 - assert r.soldermask_info == "none" - r = IPC356_TestRecord.from_line(record_string, FileSettings(units="metric")) - pytest.approx(r.x_coord, 32.1) - pytest.approx(r.y_coord, 7.124) - pytest.approx(r.rect_x, 0.236) - pytest.approx(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 r.feature_type == "through-hole" - assert r.id == "J4" - assert r.pin == "M2" - pytest.approx(r.hole_diameter, 0.033) - assert r.plated - assert r.access == "both" - pytest.approx(r.x_coord, 1.2447) - pytest.approx(r.y_coord, 0.8030) - pytest.approx(r.rect_x, 0.0) - assert r.soldermask_info == "primary side" +from .utils import * +from ..utils import Inch, MM + + +REFERENCE_FILES = [ + # TODO add more test files from github + 'allegro-2/MinnowMax_RevA1_IPC356A.ipc', + 'allegro/08_057494d-ipc356.ipc', + 'ipc-d-356.ipc', + ] + + +@filter_syntax_warnings +@pytest.mark.parametrize('reference', REFERENCE_FILES, indirect=True) +def test_read(reference): + netlist = Netlist.open(reference) + assert netlist + assert netlist.test_records + +@filter_syntax_warnings +@pytest.mark.parametrize('reference', REFERENCE_FILES, indirect=True) +def test_idempotence(reference, tmpfile): + tmp_1 = tmpfile('First generation output', '.ipc') + tmp_2 = tmpfile('Second generation output', '.ipc') + + Netlist.open(reference).save(tmp_1) + Netlist.open(tmp_1).save(tmp_2) + + assert tmp_1.read_text() == tmp_2.read_text() + +@filter_syntax_warnings +@pytest.mark.parametrize('reference', REFERENCE_FILES, indirect=True) +def test_bells_and_whistles(reference): + netlist = Netlist.open(reference) + netlist.net_names() + netlist.vias() + netlist.reference_designators() + netlist.records_by_reference('C1') + netlist.records_by_net_name('n001') + netlist.conductors_by_net_name('n001') + netlist.conductors_by_layer(0) + +@filter_syntax_warnings +@pytest.mark.parametrize('reference', REFERENCE_FILES, indirect=True) +@pytest.mark.parametrize('other', REFERENCE_FILES, indirect=True) +def test_merge(reference, other): + other = reference_path(other) + a = Netlist.open(reference) + b = Netlist.open(other) + a.merge(b, our_prefix='A') + # FIXME asserts - record_string = "317SCL COMMUNICATION-1 D 40PA00X 34000Y 20000X 600Y1200R270 " - r = IPC356_TestRecord.from_line(record_string, FileSettings(units="inch")) - assert r.feature_type == "through-hole" - assert r.net_name == "SCL" - assert r.id == "COMMUNICATION" - assert r.pin == "1" - pytest.approx(r.hole_diameter, 0.004) - assert r.plated - pytest.approx(r.x_coord, 3.4) - pytest.approx(r.y_coord, 2.0) diff --git a/gerbonara/gerber/tests/test_pcb.py b/gerbonara/gerber/tests/test_pcb.py deleted file mode 100644 index 5f513f3..0000000 --- a/gerbonara/gerber/tests/test_pcb.py +++ /dev/null @@ -1,7 +0,0 @@ -import os -from ..pcb import PCB - - -def test_from_directory(): - test_pcb = PCB.from_directory(os.path.join(os.path.dirname(__file__), 'resources/eagle_files')) - assert len(test_pcb.layers) == 11 # Checks all the available layer files have been read or not. diff --git a/gerbonara/gerber/tests/test_rs274x_backend.py b/gerbonara/gerber/tests/test_rs274x_backend.py deleted file mode 100644 index ac39c8f..0000000 --- a/gerbonara/gerber/tests/test_rs274x_backend.py +++ /dev/null @@ -1,68 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Author: Garret Fick <garret@ficksworkshop.com> - -import os - -from ..render.rs274x_backend import Rs274xContext -from ..rs274x import read - - -def test_render_two_boxes(): - """Umaco exapmle of two boxes""" - _test_render( - "resources/example_two_square_boxes.gbr", "golden/example_two_square_boxes.gbr" - ) - -def _resolve_path(path): - return os.path.join(os.path.dirname(__file__), path) - - -def _test_render(gerber_path, png_expected_path, create_output_path=None): - """Render the gerber file and compare to the expected PNG output. - - Parameters - ---------- - gerber_path : string - Path to Gerber file to open - png_expected_path : string - Path to the PNG file to compare to - create_output : string|None - If not None, write the generated PNG to the specified path. - This is primarily to help with - """ - - gerber_path = _resolve_path(gerber_path) - png_expected_path = _resolve_path(png_expected_path) - if create_output_path: - create_output_path = _resolve_path(create_output_path) - - gerber = read(gerber_path) - - # Create GBR output from the input file - ctx = Rs274xContext(gerber.settings) - gerber.render(ctx) - - actual_contents = ctx.dump() - - # If we want to write the file bytes, do it now. This happens - if create_output_path: - with open(create_output_path, "wb") as out_file: - out_file.write(actual_contents.getvalue()) - # Creating the output is dangerous - it could overwrite the expected result. - # So if we are creating the output, we make the test fail on purpose so you - # won't forget to disable this - assert not True, ( - "Test created the output %s. This needs to be disabled to make sure the test behaves correctly" - % (create_output_path,) - ) - - # Read the expected PNG file - - with open(png_expected_path, "r") as expected_file: - expected_contents = expected_file.read() - - assert expected_contents == actual_contents.getvalue() - - return gerber |