From 6f876edd09d9b81649691e529f85653f14b8fd1c Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 22 Dec 2015 02:45:48 -0500 Subject: Add PCB interface this incorporates some of @chintal's layers.py changes PCB.from_directory() simplifies loading of multiple gerbers the PCB() class should be pretty helpful going forward... the context classes could use some cleaning up, although I'd like to wait until the freecad stuff gets merged, that way we can try to refactor the context base to support more use cases --- gerber/tests/test_layers.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gerber/tests/test_layers.py (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py new file mode 100644 index 0000000..c77084d --- /dev/null +++ b/gerber/tests/test_layers.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from .tests import * +from ..layers import guess_layer_class, hints + + +def test_guess_layer_class(): + """ Test layer type inferred correctly from filename + """ + + # Add any specific test cases here (filename, layer_class) + test_vectors = [(None, 'unknown'), ('NCDRILL.TXT', 'unknown'), + ('example_board.gtl', 'top'), + ('exampmle_board.sst', 'topsilk'), + ('ipc-d-356.ipc', 'ipc_netlist'),] + + for hint in hints: + for ext in hint.ext: + assert_equal(hint.layer, guess_layer_class('board.{}'.format(ext))) + for name in hint.name: + assert_equal(hint.layer, guess_layer_class('{}.pho'.format(name))) + + for filename, layer_class in test_vectors: + assert_equal(layer_class, guess_layer_class(filename)) + + +def test_sort_layers(): + """ Test layer ordering + """ + pass -- cgit From 5476da8aa3f4ee424f56f4f2491e7af1c4b7b758 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Fix a bunch of rendering bugs. - 'clear' polarity primitives no longer erase background - Added aperture macro support for polygons - Added aperture macro rendring support - Renderer now creates a new surface for each layer and merges them instead of working directly on a single surface - Updated examples accordingly --- gerber/tests/test_layers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index c77084d..3f2bcfc 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -15,7 +15,7 @@ def test_guess_layer_class(): test_vectors = [(None, 'unknown'), ('NCDRILL.TXT', 'unknown'), ('example_board.gtl', 'top'), ('exampmle_board.sst', 'topsilk'), - ('ipc-d-356.ipc', 'ipc_netlist'),] + ('ipc-d-356.ipc', 'ipc_netlist'), ] for hint in hints: for ext in hint.ext: -- cgit From 5df38c014fd09792995b2b12b1982c535c962c9a Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 28 Jan 2016 12:19:03 -0500 Subject: Cleanup, rendering fixes. fixed rendering of tented vias fixed rendering of semi-transparent layers fixed file type detection issues added some examples --- gerber/tests/test_layers.py | 75 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 3f2bcfc..7e36dc2 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -1,11 +1,33 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -# Author: Hamilton Kibbe +# copyright 2016 Hamilton Kibbe +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os from .tests import * -from ..layers import guess_layer_class, hints +from ..layers import * +from ..common import read +NCDRILL_FILE = os.path.join(os.path.dirname(__file__), + 'resources/ncdrill.DRD') +NETLIST_FILE = os.path.join(os.path.dirname(__file__), + 'resources/ipc-d-356.ipc') +COPPER_FILE = os.path.join(os.path.dirname(__file__), + 'resources/top_copper.GTL') def test_guess_layer_class(): """ Test layer type inferred correctly from filename @@ -30,4 +52,51 @@ def test_guess_layer_class(): def test_sort_layers(): """ Test layer ordering """ - pass + layers = [ + PCBLayer(layer_class='drawing'), + PCBLayer(layer_class='drill'), + PCBLayer(layer_class='bottompaste'), + PCBLayer(layer_class='bottomsilk'), + PCBLayer(layer_class='bottommask'), + PCBLayer(layer_class='bottom'), + PCBLayer(layer_class='internal'), + PCBLayer(layer_class='top'), + PCBLayer(layer_class='topmask'), + PCBLayer(layer_class='topsilk'), + PCBLayer(layer_class='toppaste'), + PCBLayer(layer_class='outline'), + ] + + layer_order = ['outline', 'toppaste', 'topsilk', 'topmask', 'top', + 'internal', 'bottom', 'bottommask', 'bottomsilk', + 'bottompaste', 'drill', 'drawing'] + bottom_order = list(reversed(layer_order[:10])) + layer_order[10:] + assert_equal([l.layer_class for l in sort_layers(layers)], layer_order) + assert_equal([l.layer_class for l in sort_layers(layers, from_top=False)], + bottom_order) + + +def test_PCBLayer_from_file(): + layer = PCBLayer.from_cam(read(COPPER_FILE)) + assert_true(isinstance(layer, PCBLayer)) + layer = PCBLayer.from_cam(read(NCDRILL_FILE)) + assert_true(isinstance(layer, DrillLayer)) + layer = PCBLayer.from_cam(read(NETLIST_FILE)) + assert_true(isinstance(layer, PCBLayer)) + assert_equal(layer.layer_class, 'ipc_netlist') + + +def test_PCBLayer_bounds(): + source = read(COPPER_FILE) + layer = PCBLayer.from_cam(source) + assert_equal(source.bounds, layer.bounds) + + +def test_DrillLayer_from_cam(): + no_exceptions = True + try: + layer = DrillLayer.from_cam(read(NCDRILL_FILE)) + assert_true(isinstance(layer, DrillLayer)) + except: + no_exceptions = False + assert_true(no_exceptions) -- cgit From ffeaf788f090b10307247775b43dd7c0b0fd7342 Mon Sep 17 00:00:00 2001 From: ju5t Date: Thu, 1 Dec 2016 21:08:17 +0100 Subject: (#61) Add regex option to discover layer classes --- gerber/tests/test_layers.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 7e36dc2..6cafecf 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -48,6 +48,27 @@ def test_guess_layer_class(): for filename, layer_class in test_vectors: assert_equal(layer_class, guess_layer_class(filename)) +def test_guess_layer_class_regex(): + """ Test regular expressions for layer matching + """ + + # Add any specific test case (filename, layer_class) + test_vectors = [('test - top copper.gbr', 'top'), + ('test - copper top.gbr', 'top'), ] + + # Add custom regular expressions + layer_hints = [ + Hint(layer='top', + ext=[], + name=[], + regex=r'(.*)(\scopper top|\stop copper)$' + ), + ] + hints.extend(layer_hints) + + for filename, layer_class in test_vectors: + assert_equal(layer_class, guess_layer_class(filename)) + def test_sort_layers(): """ Test layer ordering -- cgit From 9ae238bf7ab4bc74d101605a9dbaddc098b9348d Mon Sep 17 00:00:00 2001 From: ju5t Date: Wed, 1 Nov 2017 16:23:22 +0100 Subject: Check gerber content for layer hints --- gerber/tests/test_layers.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 6cafecf..597c0d3 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -61,7 +61,8 @@ def test_guess_layer_class_regex(): Hint(layer='top', ext=[], name=[], - regex=r'(.*)(\scopper top|\stop copper)$' + regex=r'(.*)(\scopper top|\stop copper)$', + content=[] ), ] hints.extend(layer_hints) @@ -70,6 +71,27 @@ def test_guess_layer_class_regex(): assert_equal(layer_class, guess_layer_class(filename)) +def test_guess_layer_class_by_content(): + """ Test layer class by checking content + """ + + expected_layer_class = 'bottom' + filename = os.path.join(os.path.dirname(__file__), + 'resources/example_guess_by_content.g0') + + layer_hints = [ + Hint(layer='bottom', + ext=[], + name=[], + regex='', + content=['G04 Layer name: Bottom'] + ) + ] + hints.extend(layer_hints) + + assert_equal(expected_layer_class, guess_layer_class_by_content(filename)) + + def test_sort_layers(): """ Test layer ordering """ -- cgit From 8dd8a87fc0fddadd590c926afe6928958d78839a Mon Sep 17 00:00:00 2001 From: ju5t Date: Tue, 26 Jun 2018 22:17:45 +0200 Subject: Match full filename instead of the base name Regular expressions only matched the base name. This matches the entire filename which allows for more advanced regular expressions. --- gerber/tests/test_layers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 597c0d3..3a21a2c 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -61,7 +61,7 @@ def test_guess_layer_class_regex(): Hint(layer='top', ext=[], name=[], - regex=r'(.*)(\scopper top|\stop copper)$', + regex=r'(.*)(\scopper top|\stop copper).gbr', content=[] ), ] -- cgit From ef589a064015de3a1ce6487dbb56b99332673e9d Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Tue, 26 Nov 2019 00:37:41 -0300 Subject: Migrate to pytest (#111) * Migrate to pytest All tests were update to use pytest. Tests were alse black formatted. Eventually all code will be black formatted but need to merge some PRs first. --- gerber/tests/test_layers.py | 129 ++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 58 deletions(-) (limited to 'gerber/tests/test_layers.py') diff --git a/gerber/tests/test_layers.py b/gerber/tests/test_layers.py index 3a21a2c..2178787 100644 --- a/gerber/tests/test_layers.py +++ b/gerber/tests/test_layers.py @@ -18,128 +18,141 @@ import os -from .tests import * from ..layers import * from ..common import read -NCDRILL_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ncdrill.DRD') -NETLIST_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ipc-d-356.ipc') -COPPER_FILE = os.path.join(os.path.dirname(__file__), - 'resources/top_copper.GTL') +NCDRILL_FILE = os.path.join(os.path.dirname(__file__), "resources/ncdrill.DRD") +NETLIST_FILE = os.path.join(os.path.dirname(__file__), "resources/ipc-d-356.ipc") +COPPER_FILE = os.path.join(os.path.dirname(__file__), "resources/top_copper.GTL") + def test_guess_layer_class(): """ Test layer type inferred correctly from filename """ # Add any specific test cases here (filename, layer_class) - test_vectors = [(None, 'unknown'), ('NCDRILL.TXT', 'unknown'), - ('example_board.gtl', 'top'), - ('exampmle_board.sst', 'topsilk'), - ('ipc-d-356.ipc', 'ipc_netlist'), ] + test_vectors = [ + (None, "unknown"), + ("NCDRILL.TXT", "unknown"), + ("example_board.gtl", "top"), + ("exampmle_board.sst", "topsilk"), + ("ipc-d-356.ipc", "ipc_netlist"), + ] for hint in hints: for ext in hint.ext: - assert_equal(hint.layer, guess_layer_class('board.{}'.format(ext))) + assert hint.layer == guess_layer_class("board.{}".format(ext)) for name in hint.name: - assert_equal(hint.layer, guess_layer_class('{}.pho'.format(name))) + assert hint.layer == guess_layer_class("{}.pho".format(name)) for filename, layer_class in test_vectors: - assert_equal(layer_class, guess_layer_class(filename)) + assert layer_class == guess_layer_class(filename) + def test_guess_layer_class_regex(): """ Test regular expressions for layer matching """ # Add any specific test case (filename, layer_class) - test_vectors = [('test - top copper.gbr', 'top'), - ('test - copper top.gbr', 'top'), ] + test_vectors = [("test - top copper.gbr", "top"), ("test - copper top.gbr", "top")] # Add custom regular expressions layer_hints = [ - Hint(layer='top', - ext=[], - name=[], - regex=r'(.*)(\scopper top|\stop copper).gbr', - content=[] - ), + Hint( + layer="top", + ext=[], + name=[], + regex=r"(.*)(\scopper top|\stop copper).gbr", + content=[], + ) ] hints.extend(layer_hints) for filename, layer_class in test_vectors: - assert_equal(layer_class, guess_layer_class(filename)) + assert layer_class == guess_layer_class(filename) def test_guess_layer_class_by_content(): """ Test layer class by checking content """ - expected_layer_class = 'bottom' - filename = os.path.join(os.path.dirname(__file__), - 'resources/example_guess_by_content.g0') + expected_layer_class = "bottom" + filename = os.path.join( + os.path.dirname(__file__), "resources/example_guess_by_content.g0" + ) layer_hints = [ - Hint(layer='bottom', - ext=[], - name=[], - regex='', - content=['G04 Layer name: Bottom'] - ) + Hint( + layer="bottom", + ext=[], + name=[], + regex="", + content=["G04 Layer name: Bottom"], + ) ] hints.extend(layer_hints) - assert_equal(expected_layer_class, guess_layer_class_by_content(filename)) + assert expected_layer_class == guess_layer_class_by_content(filename) def test_sort_layers(): """ Test layer ordering """ layers = [ - PCBLayer(layer_class='drawing'), - PCBLayer(layer_class='drill'), - PCBLayer(layer_class='bottompaste'), - PCBLayer(layer_class='bottomsilk'), - PCBLayer(layer_class='bottommask'), - PCBLayer(layer_class='bottom'), - PCBLayer(layer_class='internal'), - PCBLayer(layer_class='top'), - PCBLayer(layer_class='topmask'), - PCBLayer(layer_class='topsilk'), - PCBLayer(layer_class='toppaste'), - PCBLayer(layer_class='outline'), + PCBLayer(layer_class="drawing"), + PCBLayer(layer_class="drill"), + PCBLayer(layer_class="bottompaste"), + PCBLayer(layer_class="bottomsilk"), + PCBLayer(layer_class="bottommask"), + PCBLayer(layer_class="bottom"), + PCBLayer(layer_class="internal"), + PCBLayer(layer_class="top"), + PCBLayer(layer_class="topmask"), + PCBLayer(layer_class="topsilk"), + PCBLayer(layer_class="toppaste"), + PCBLayer(layer_class="outline"), ] - layer_order = ['outline', 'toppaste', 'topsilk', 'topmask', 'top', - 'internal', 'bottom', 'bottommask', 'bottomsilk', - 'bottompaste', 'drill', 'drawing'] + layer_order = [ + "outline", + "toppaste", + "topsilk", + "topmask", + "top", + "internal", + "bottom", + "bottommask", + "bottomsilk", + "bottompaste", + "drill", + "drawing", + ] bottom_order = list(reversed(layer_order[:10])) + layer_order[10:] - assert_equal([l.layer_class for l in sort_layers(layers)], layer_order) - assert_equal([l.layer_class for l in sort_layers(layers, from_top=False)], - bottom_order) + assert [l.layer_class for l in sort_layers(layers)] == layer_order + assert [l.layer_class for l in sort_layers(layers, from_top=False)] == bottom_order def test_PCBLayer_from_file(): layer = PCBLayer.from_cam(read(COPPER_FILE)) - assert_true(isinstance(layer, PCBLayer)) + assert isinstance(layer, PCBLayer) layer = PCBLayer.from_cam(read(NCDRILL_FILE)) - assert_true(isinstance(layer, DrillLayer)) + assert isinstance(layer, DrillLayer) layer = PCBLayer.from_cam(read(NETLIST_FILE)) - assert_true(isinstance(layer, PCBLayer)) - assert_equal(layer.layer_class, 'ipc_netlist') + assert isinstance(layer, PCBLayer) + assert layer.layer_class == "ipc_netlist" def test_PCBLayer_bounds(): source = read(COPPER_FILE) layer = PCBLayer.from_cam(source) - assert_equal(source.bounds, layer.bounds) + assert source.bounds == layer.bounds def test_DrillLayer_from_cam(): no_exceptions = True try: layer = DrillLayer.from_cam(read(NCDRILL_FILE)) - assert_true(isinstance(layer, DrillLayer)) + assert isinstance(layer, DrillLayer) except: no_exceptions = False - assert_true(no_exceptions) + assert no_exceptions -- cgit