summaryrefslogtreecommitdiff
path: root/gerber/tests/test_layers.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2019-11-26 00:37:41 -0300
committerGitHub <noreply@github.com>2019-11-26 00:37:41 -0300
commitef589a064015de3a1ce6487dbb56b99332673e9d (patch)
tree5dd7ec0c1a86cff0f9459b90f0d2aeca768182c0 /gerber/tests/test_layers.py
parent404384cf912fa082c120ba5be81973ea097958fc (diff)
downloadgerbonara-ef589a064015de3a1ce6487dbb56b99332673e9d.tar.gz
gerbonara-ef589a064015de3a1ce6487dbb56b99332673e9d.tar.bz2
gerbonara-ef589a064015de3a1ce6487dbb56b99332673e9d.zip
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.
Diffstat (limited to 'gerber/tests/test_layers.py')
-rw-r--r--gerber/tests/test_layers.py129
1 files changed, 71 insertions, 58 deletions
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