diff options
author | Chintalagiri Shashank <shashank.chintalagiri@gmail.com> | 2019-11-27 15:11:27 +0530 |
---|---|---|
committer | Chintalagiri Shashank <shashank.chintalagiri@gmail.com> | 2019-11-27 15:11:27 +0530 |
commit | 5288a8314b535d455e8635ee9a3a537cd795845b (patch) | |
tree | 4233452d40a23ab99d0aab5f977e63df632d3c70 | |
parent | 25b82c988578482fbb57f80d3d30bdf985a9a885 (diff) | |
parent | 0024c0b045a29621845f4f1b5ee1283e32e38887 (diff) | |
download | gerbonara-5288a8314b535d455e8635ee9a3a537cd795845b.tar.gz gerbonara-5288a8314b535d455e8635ee9a3a537cd795845b.tar.bz2 gerbonara-5288a8314b535d455e8635ee9a3a537cd795845b.zip |
Manual merge resolution
-rw-r--r-- | .coveragerc | 8 | ||||
-rw-r--r-- | .github/workflows/pcb-tools.yml | 46 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | gerber/__main__.py | 1 | ||||
-rw-r--r-- | gerber/pcb.py | 6 | ||||
-rw-r--r-- | gerber/render/theme.py | 32 | ||||
-rw-r--r-- | gerber/tests/test_am_statements.py | 412 | ||||
-rw-r--r-- | gerber/tests/test_cairo_backend.py | 140 | ||||
-rw-r--r-- | gerber/tests/test_cam.py | 142 | ||||
-rw-r--r-- | gerber/tests/test_common.py | 23 | ||||
-rw-r--r-- | gerber/tests/test_excellon.py | 260 | ||||
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 616 | ||||
-rw-r--r-- | gerber/tests/test_gerber_statements.py | 835 | ||||
-rw-r--r-- | gerber/tests/test_ipc356.py | 220 | ||||
-rw-r--r-- | gerber/tests/test_layers.py | 129 | ||||
-rw-r--r-- | gerber/tests/test_primitives.py | 1304 | ||||
-rw-r--r-- | gerber/tests/test_rs274x.py | 30 | ||||
-rw-r--r-- | gerber/tests/test_rs274x_backend.py | 105 | ||||
-rw-r--r-- | gerber/tests/test_utils.py | 168 | ||||
-rw-r--r-- | gerber/tests/tests.py | 25 | ||||
-rw-r--r-- | requirements-dev.txt | 4 |
23 files changed, 2425 insertions, 2104 deletions
diff --git a/.coveragerc b/.coveragerc index 8b140ff..3399dbe 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,8 @@ +[run] +branch = True +source = gerber + [report] +ignore_errors = True omit = - */python?.?/* - */site-packages/nose/*
\ No newline at end of file + gerber/tests/* diff --git a/.github/workflows/pcb-tools.yml b/.github/workflows/pcb-tools.yml index 85038a7..59abe6c 100644 --- a/.github/workflows/pcb-tools.yml +++ b/.github/workflows/pcb-tools.yml @@ -1,6 +1,6 @@ name: pcb-tools -on: [push, pull_request] +on: [push] jobs: test: @@ -11,16 +11,34 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - run: | - pip install pytest - pytest + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install -r requirements-dev.txt + - name: Test with pytest + run: | + pytest + coverage: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.8 + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install dependencies + run: | + pip install -r requirements-dev.txt + - name: Run coverage + run: | + make test-coverage + - uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + flags: unittest @@ -48,3 +48,4 @@ Thumbs.db # Virtual environment venv +coverage.xml @@ -1,6 +1,6 @@ PYTHON ?= python -NOSETESTS ?= nosetests +PYTEST ?= pytest DOC_ROOT = doc EXAMPLES = examples @@ -8,17 +8,19 @@ EXAMPLES = examples .PHONY: clean clean: doc-clean find . -name '*.pyc' -delete - rm -rf coverage .coverage rm -rf *.egg-info + rm -f .coverage + rm -f coverage.xml .PHONY: test test: - $(NOSETESTS) -s -v gerber + $(PYTEST) .PHONY: test-coverage test-coverage: - rm -rf coverage .coverage - $(NOSETESTS) -s -v --with-coverage --cover-package=gerber + rm -f .coverage + rm -f coverage.xml + $(PYTEST) --cov=./ --cov-report=xml .PHONY: install install: @@ -1,8 +1,8 @@ pcb-tools ============ -[![Travis CI Build Status](https://travis-ci.org/curtacircuitos/pcb-tools.svg?branch=master)](https://travis-ci.org/curtacircuitos/pcb-tools) -[![Coverage Status](https://coveralls.io/repos/curtacircuitos/pcb-tools/badge.png?branch=master)](https://coveralls.io/r/curtacircuitos/pcb-tools?branch=master) -[![Documentation Status](https://readthedocs.org/projects/pcb-tools/badge/?version=latest)](https://readthedocs.org/projects/pcb-tools/?badge=latest) +[![CI](https://github.com/curtacircuitos/pcb-tools/workflows/pcb-tools/badge.svg)](https://github.com/curtacircuitos/pcb-tools/actions) +[![Coverage](https://codecov.io/gh/curtacircuitos/pcb-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/curtacircuitos/pcb-tools) +[![Docs](https://readthedocs.org/projects/pcb-tools/badge/?version=latest)](https://readthedocs.org/projects/pcb-tools/?badge=latest) Tools to handle Gerber and Excellon files in Python. @@ -55,6 +55,6 @@ Dependencies for developing and testing pcb-tools are listed in requirements-dev (venv)$ pip install -r requirements-dev.txt (venv)$ pip install -e . -We use nose to run pcb-tools's suite of unittests and doctests. +We use [pytest](https://docs.pytest.org/en/latest/) to run pcb-tools's suite of unittests and doctests. - (venv)$ nosetests + (venv)$ pytest diff --git a/gerber/__main__.py b/gerber/__main__.py index 202c00b..988adff 100644 --- a/gerber/__main__.py +++ b/gerber/__main__.py @@ -119,3 +119,4 @@ def main(): if __name__ == '__main__': main() + diff --git a/gerber/pcb.py b/gerber/pcb.py index ba15161..56deaa3 100644 --- a/gerber/pcb.py +++ b/gerber/pcb.py @@ -95,6 +95,12 @@ class PCB(object): ('top', 'bottom', 'internal')])) @property + def outline_layer(self): + for layer in self.layers: + if layer.layer_class == 'outline': + return layer + + @property def layer_count(self): """ Number of *COPPER* layers """ diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 2887216..2f558a1 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -23,6 +23,7 @@ COLORS = { 'white': (1.0, 1.0, 1.0), 'red': (1.0, 0.0, 0.0), 'green': (0.0, 1.0, 0.0), + 'yellow': (1.0, 1.0, 0), 'blue': (0.0, 0.0, 1.0), 'fr-4': (0.290, 0.345, 0.0), 'green soldermask': (0.0, 0.412, 0.278), @@ -35,6 +36,18 @@ COLORS = { } +SPECTRUM = [ + (0.804, 0.216, 0), + (0.78, 0.776, 0.251), + (0.545, 0.451, 0.333), + (0.545, 0.137, 0.137), + (0.329, 0.545, 0.329), + (0.133, 0.545, 0.133), + (0, 0.525, 0.545), + (0.227, 0.373, 0.804), +] + + class Theme(object): def __init__(self, name=None, **kwargs): @@ -48,10 +61,22 @@ class Theme(object): self.bottom = kwargs.get('bottom', RenderSettings(COLORS['hasl copper'], mirror=True)) self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) self.ipc_netlist = kwargs.get('ipc_netlist', RenderSettings(COLORS['red'])) + self._internal = kwargs.get('internal', [RenderSettings(x) for x in SPECTRUM]) + self._internal_gen = None def __getitem__(self, key): return getattr(self, key) + @property + def internal(self): + if not self._internal_gen: + self._internal_gen = self._internal_gen_func() + return next(self._internal_gen) + + def _internal_gen_func(self): + for setting in self._internal: + yield setting + def get(self, key, noneval=None): val = getattr(self, key, None) return val if val is not None else noneval @@ -77,4 +102,11 @@ THEMES = { top=RenderSettings(COLORS['red'], alpha=0.5), bottom=RenderSettings(COLORS['blue'], alpha=0.5), drill=RenderSettings((0.3, 0.3, 0.3))), + + 'Transparent Multilayer': Theme(name='Transparent Multilayer', + background=RenderSettings((0, 0, 0)), + top=RenderSettings(SPECTRUM[0], alpha=0.8), + bottom=RenderSettings(SPECTRUM[-1], alpha=0.8), + drill=RenderSettings((0.3, 0.3, 0.3)), + internal=[RenderSettings(x, alpha=0.5) for x in SPECTRUM[1:-1]]), } diff --git a/gerber/tests/test_am_statements.py b/gerber/tests/test_am_statements.py index c97556a..0d100b5 100644 --- a/gerber/tests/test_am_statements.py +++ b/gerber/tests/test_am_statements.py @@ -3,385 +3,393 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> -from .tests import * +import pytest + from ..am_statements import * from ..am_statements import inch, metric def test_AMPrimitive_ctor(): - for exposure in ('on', 'off', 'ON', 'OFF'): + for exposure in ("on", "off", "ON", "OFF"): for code in (0, 1, 2, 4, 5, 6, 7, 20, 21, 22): p = AMPrimitive(code, exposure) - assert_equal(p.code, code) - assert_equal(p.exposure, exposure.lower()) + assert p.code == code + assert p.exposure == exposure.lower() def test_AMPrimitive_validation(): - assert_raises(TypeError, AMPrimitive, '1', 'off') - assert_raises(ValueError, AMPrimitive, 0, 'exposed') - assert_raises(ValueError, AMPrimitive, 3, 'off') + pytest.raises(TypeError, AMPrimitive, "1", "off") + pytest.raises(ValueError, AMPrimitive, 0, "exposed") + pytest.raises(ValueError, AMPrimitive, 3, "off") def test_AMPrimitive_conversion(): - p = AMPrimitive(4, 'on') - assert_raises(NotImplementedError, p.to_inch) - assert_raises(NotImplementedError, p.to_metric) + p = AMPrimitive(4, "on") + pytest.raises(NotImplementedError, p.to_inch) + pytest.raises(NotImplementedError, p.to_metric) def test_AMCommentPrimitive_ctor(): - c = AMCommentPrimitive(0, ' This is a comment *') - assert_equal(c.code, 0) - assert_equal(c.comment, 'This is a comment') + c = AMCommentPrimitive(0, " This is a comment *") + assert c.code == 0 + assert c.comment == "This is a comment" def test_AMCommentPrimitive_validation(): - assert_raises(ValueError, AMCommentPrimitive, 1, 'This is a comment') + pytest.raises(ValueError, AMCommentPrimitive, 1, "This is a comment") def test_AMCommentPrimitive_factory(): - c = AMCommentPrimitive.from_gerber('0 Rectangle with rounded corners. *') - assert_equal(c.code, 0) - assert_equal(c.comment, 'Rectangle with rounded corners.') + c = AMCommentPrimitive.from_gerber("0 Rectangle with rounded corners. *") + assert c.code == 0 + assert c.comment == "Rectangle with rounded corners." def test_AMCommentPrimitive_dump(): - c = AMCommentPrimitive(0, 'Rectangle with rounded corners.') - assert_equal(c.to_gerber(), '0 Rectangle with rounded corners. *') + c = AMCommentPrimitive(0, "Rectangle with rounded corners.") + assert c.to_gerber() == "0 Rectangle with rounded corners. *" def test_AMCommentPrimitive_conversion(): - c = AMCommentPrimitive(0, 'Rectangle with rounded corners.') + c = AMCommentPrimitive(0, "Rectangle with rounded corners.") ci = c cm = c ci.to_inch() cm.to_metric() - assert_equal(c, ci) - assert_equal(c, cm) + assert c == ci + assert c == cm def test_AMCommentPrimitive_string(): - c = AMCommentPrimitive(0, 'Test Comment') - assert_equal(str(c), '<Aperture Macro Comment: Test Comment>') + c = AMCommentPrimitive(0, "Test Comment") + assert str(c) == "<Aperture Macro Comment: Test Comment>" def test_AMCirclePrimitive_ctor(): - test_cases = ((1, 'on', 0, (0, 0)), - (1, 'off', 1, (0, 1)), - (1, 'on', 2.5, (0, 2)), - (1, 'off', 5.0, (3, 3))) + test_cases = ( + (1, "on", 0, (0, 0)), + (1, "off", 1, (0, 1)), + (1, "on", 2.5, (0, 2)), + (1, "off", 5.0, (3, 3)), + ) for code, exposure, diameter, position in test_cases: c = AMCirclePrimitive(code, exposure, diameter, position) - assert_equal(c.code, code) - assert_equal(c.exposure, exposure) - assert_equal(c.diameter, diameter) - assert_equal(c.position, position) + assert c.code == code + assert c.exposure == exposure + assert c.diameter == diameter + assert c.position == position def test_AMCirclePrimitive_validation(): - assert_raises(ValueError, AMCirclePrimitive, 2, 'on', 0, (0, 0)) + pytest.raises(ValueError, AMCirclePrimitive, 2, "on", 0, (0, 0)) def test_AMCirclePrimitive_factory(): - c = AMCirclePrimitive.from_gerber('1,0,5,0,0*') - assert_equal(c.code, 1) - assert_equal(c.exposure, 'off') - assert_equal(c.diameter, 5) - assert_equal(c.position, (0, 0)) + c = AMCirclePrimitive.from_gerber("1,0,5,0,0*") + assert c.code == 1 + assert c.exposure == "off" + assert c.diameter == 5 + assert c.position == (0, 0) def test_AMCirclePrimitive_dump(): - c = AMCirclePrimitive(1, 'off', 5, (0, 0)) - assert_equal(c.to_gerber(), '1,0,5,0,0*') - c = AMCirclePrimitive(1, 'on', 5, (0, 0)) - assert_equal(c.to_gerber(), '1,1,5,0,0*') + c = AMCirclePrimitive(1, "off", 5, (0, 0)) + assert c.to_gerber() == "1,0,5,0,0*" + c = AMCirclePrimitive(1, "on", 5, (0, 0)) + assert c.to_gerber() == "1,1,5,0,0*" def test_AMCirclePrimitive_conversion(): - c = AMCirclePrimitive(1, 'off', 25.4, (25.4, 0)) + c = AMCirclePrimitive(1, "off", 25.4, (25.4, 0)) c.to_inch() - assert_equal(c.diameter, 1) - assert_equal(c.position, (1, 0)) + assert c.diameter == 1 + assert c.position == (1, 0) - c = AMCirclePrimitive(1, 'off', 1, (1, 0)) + c = AMCirclePrimitive(1, "off", 1, (1, 0)) c.to_metric() - assert_equal(c.diameter, 25.4) - assert_equal(c.position, (25.4, 0)) + assert c.diameter == 25.4 + assert c.position == (25.4, 0) def test_AMVectorLinePrimitive_validation(): - assert_raises(ValueError, AMVectorLinePrimitive, - 3, 'on', 0.1, (0, 0), (3.3, 5.4), 0) + pytest.raises( + ValueError, AMVectorLinePrimitive, 3, "on", 0.1, (0, 0), (3.3, 5.4), 0 + ) def test_AMVectorLinePrimitive_factory(): - l = AMVectorLinePrimitive.from_gerber('20,1,0.9,0,0.45,12,0.45,0*') - assert_equal(l.code, 20) - assert_equal(l.exposure, 'on') - assert_equal(l.width, 0.9) - assert_equal(l.start, (0, 0.45)) - assert_equal(l.end, (12, 0.45)) - assert_equal(l.rotation, 0) + l = AMVectorLinePrimitive.from_gerber("20,1,0.9,0,0.45,12,0.45,0*") + assert l.code == 20 + assert l.exposure == "on" + assert l.width == 0.9 + assert l.start == (0, 0.45) + assert l.end == (12, 0.45) + assert l.rotation == 0 def test_AMVectorLinePrimitive_dump(): - l = AMVectorLinePrimitive.from_gerber('20,1,0.9,0,0.45,12,0.45,0*') - assert_equal(l.to_gerber(), '20,1,0.9,0.0,0.45,12.0,0.45,0.0*') + l = AMVectorLinePrimitive.from_gerber("20,1,0.9,0,0.45,12,0.45,0*") + assert l.to_gerber() == "20,1,0.9,0.0,0.45,12.0,0.45,0.0*" def test_AMVectorLinePrimtive_conversion(): - l = AMVectorLinePrimitive(20, 'on', 25.4, (0, 0), (25.4, 25.4), 0) + l = AMVectorLinePrimitive(20, "on", 25.4, (0, 0), (25.4, 25.4), 0) l.to_inch() - assert_equal(l.width, 1) - assert_equal(l.start, (0, 0)) - assert_equal(l.end, (1, 1)) + assert l.width == 1 + assert l.start == (0, 0) + assert l.end == (1, 1) - l = AMVectorLinePrimitive(20, 'on', 1, (0, 0), (1, 1), 0) + l = AMVectorLinePrimitive(20, "on", 1, (0, 0), (1, 1), 0) l.to_metric() - assert_equal(l.width, 25.4) - assert_equal(l.start, (0, 0)) - assert_equal(l.end, (25.4, 25.4)) + assert l.width == 25.4 + assert l.start == (0, 0) + assert l.end == (25.4, 25.4) def test_AMOutlinePrimitive_validation(): - assert_raises(ValueError, AMOutlinePrimitive, 7, 'on', - (0, 0), [(3.3, 5.4), (4.0, 5.4), (0, 0)], 0) - assert_raises(ValueError, AMOutlinePrimitive, 4, 'on', - (0, 0), [(3.3, 5.4), (4.0, 5.4), (0, 1)], 0) + pytest.raises( + ValueError, + AMOutlinePrimitive, + 7, + "on", + (0, 0), + [(3.3, 5.4), (4.0, 5.4), (0, 0)], + 0, + ) + pytest.raises( + ValueError, + AMOutlinePrimitive, + 4, + "on", + (0, 0), + [(3.3, 5.4), (4.0, 5.4), (0, 1)], + 0, + ) def test_AMOutlinePrimitive_factory(): - o = AMOutlinePrimitive.from_gerber('4,1,3,0,0,3,3,3,0,0,0,0*') - assert_equal(o.code, 4) - assert_equal(o.exposure, 'on') - assert_equal(o.start_point, (0, 0)) - assert_equal(o.points, [(3, 3), (3, 0), (0, 0)]) - assert_equal(o.rotation, 0) + o = AMOutlinePrimitive.from_gerber("4,1,3,0,0,3,3,3,0,0,0,0*") + assert o.code == 4 + assert o.exposure == "on" + assert o.start_point == (0, 0) + assert o.points == [(3, 3), (3, 0), (0, 0)] + assert o.rotation == 0 def test_AMOUtlinePrimitive_dump(): - o = AMOutlinePrimitive(4, 'on', (0, 0), [(3, 3), (3, 0), (0, 0)], 0) + o = AMOutlinePrimitive(4, "on", (0, 0), [(3, 3), (3, 0), (0, 0)], 0) # New lines don't matter for Gerber, but we insert them to make it easier to remove # For test purposes we can ignore them - assert_equal(o.to_gerber().replace('\n', ''), '4,1,3,0,0,3,3,3,0,0,0,0*') - - + assert o.to_gerber().replace("\n", "") == "4,1,3,0,0,3,3,3,0,0,0,0*" def test_AMOutlinePrimitive_conversion(): - o = AMOutlinePrimitive( - 4, 'on', (0, 0), [(25.4, 25.4), (25.4, 0), (0, 0)], 0) + o = AMOutlinePrimitive(4, "on", (0, 0), [(25.4, 25.4), (25.4, 0), (0, 0)], 0) o.to_inch() - assert_equal(o.start_point, (0, 0)) - assert_equal(o.points, ((1., 1.), (1., 0.), (0., 0.))) + assert o.start_point == (0, 0) + assert o.points == ((1.0, 1.0), (1.0, 0.0), (0.0, 0.0)) - o = AMOutlinePrimitive(4, 'on', (0, 0), [(1, 1), (1, 0), (0, 0)], 0) + o = AMOutlinePrimitive(4, "on", (0, 0), [(1, 1), (1, 0), (0, 0)], 0) o.to_metric() - assert_equal(o.start_point, (0, 0)) - assert_equal(o.points, ((25.4, 25.4), (25.4, 0), (0, 0))) + assert o.start_point == (0, 0) + assert o.points == ((25.4, 25.4), (25.4, 0), (0, 0)) def test_AMPolygonPrimitive_validation(): - assert_raises(ValueError, AMPolygonPrimitive, 6, 'on', 3, (3.3, 5.4), 3, 0) - assert_raises(ValueError, AMPolygonPrimitive, 5, 'on', 2, (3.3, 5.4), 3, 0) - assert_raises(ValueError, AMPolygonPrimitive, 5, 'on', 13, (3.3, 5.4), 3, 0) + pytest.raises(ValueError, AMPolygonPrimitive, 6, "on", 3, (3.3, 5.4), 3, 0) + pytest.raises(ValueError, AMPolygonPrimitive, 5, "on", 2, (3.3, 5.4), 3, 0) + pytest.raises(ValueError, AMPolygonPrimitive, 5, "on", 13, (3.3, 5.4), 3, 0) def test_AMPolygonPrimitive_factory(): - p = AMPolygonPrimitive.from_gerber('5,1,3,3.3,5.4,3,0') - assert_equal(p.code, 5) - assert_equal(p.exposure, 'on') - assert_equal(p.vertices, 3) - assert_equal(p.position, (3.3, 5.4)) - assert_equal(p.diameter, 3) - assert_equal(p.rotation, 0) + p = AMPolygonPrimitive.from_gerber("5,1,3,3.3,5.4,3,0") + assert p.code == 5 + assert p.exposure == "on" + assert p.vertices == 3 + assert p.position == (3.3, 5.4) + assert p.diameter == 3 + assert p.rotation == 0 def test_AMPolygonPrimitive_dump(): - p = AMPolygonPrimitive(5, 'on', 3, (3.3, 5.4), 3, 0) - assert_equal(p.to_gerber(), '5,1,3,3.3,5.4,3,0*') + p = AMPolygonPrimitive(5, "on", 3, (3.3, 5.4), 3, 0) + assert p.to_gerber() == "5,1,3,3.3,5.4,3,0*" def test_AMPolygonPrimitive_conversion(): - p = AMPolygonPrimitive(5, 'off', 3, (25.4, 0), 25.4, 0) + p = AMPolygonPrimitive(5, "off", 3, (25.4, 0), 25.4, 0) p.to_inch() - assert_equal(p.diameter, 1) - assert_equal(p.position, (1, 0)) + assert p.diameter == 1 + assert p.position == (1, 0) - p = AMPolygonPrimitive(5, 'off', 3, (1, 0), 1, 0) + p = AMPolygonPrimitive(5, "off", 3, (1, 0), 1, 0) p.to_metric() - assert_equal(p.diameter, 25.4) - assert_equal(p.position, (25.4, 0)) + assert p.diameter == 25.4 + assert p.position == (25.4, 0) def test_AMMoirePrimitive_validation(): - assert_raises(ValueError, AMMoirePrimitive, 7, - (0, 0), 5.1, 0.2, 0.4, 6, 0.1, 6.1, 0) + pytest.raises( + ValueError, AMMoirePrimitive, 7, (0, 0), 5.1, 0.2, 0.4, 6, 0.1, 6.1, 0 + ) def test_AMMoirePrimitive_factory(): - m = AMMoirePrimitive.from_gerber('6,0,0,5,0.5,0.5,2,0.1,6,0*') - assert_equal(m.code, 6) - assert_equal(m.position, (0, 0)) - assert_equal(m.diameter, 5) - assert_equal(m.ring_thickness, 0.5) - assert_equal(m.gap, 0.5) - assert_equal(m.max_rings, 2) - assert_equal(m.crosshair_thickness, 0.1) - assert_equal(m.crosshair_length, 6) - assert_equal(m.rotation, 0) + m = AMMoirePrimitive.from_gerber("6,0,0,5,0.5,0.5,2,0.1,6,0*") + assert m.code == 6 + assert m.position == (0, 0) + assert m.diameter == 5 + assert m.ring_thickness == 0.5 + assert m.gap == 0.5 + assert m.max_rings == 2 + assert m.crosshair_thickness == 0.1 + assert m.crosshair_length == 6 + assert m.rotation == 0 def test_AMMoirePrimitive_dump(): - m = AMMoirePrimitive.from_gerber('6,0,0,5,0.5,0.5,2,0.1,6,0*') - assert_equal(m.to_gerber(), '6,0,0,5.0,0.5,0.5,2,0.1,6.0,0.0*') + m = AMMoirePrimitive.from_gerber("6,0,0,5,0.5,0.5,2,0.1,6,0*") + assert m.to_gerber() == "6,0,0,5.0,0.5,0.5,2,0.1,6.0,0.0*" def test_AMMoirePrimitive_conversion(): m = AMMoirePrimitive(6, (25.4, 25.4), 25.4, 25.4, 25.4, 6, 25.4, 25.4, 0) m.to_inch() - assert_equal(m.position, (1., 1.)) - assert_equal(m.diameter, 1.) - assert_equal(m.ring_thickness, 1.) - assert_equal(m.gap, 1.) - assert_equal(m.crosshair_thickness, 1.) - assert_equal(m.crosshair_length, 1.) + assert m.position == (1.0, 1.0) + assert m.diameter == 1.0 + assert m.ring_thickness == 1.0 + assert m.gap == 1.0 + assert m.crosshair_thickness == 1.0 + assert m.crosshair_length == 1.0 m = AMMoirePrimitive(6, (1, 1), 1, 1, 1, 6, 1, 1, 0) m.to_metric() - assert_equal(m.position, (25.4, 25.4)) - assert_equal(m.diameter, 25.4) - assert_equal(m.ring_thickness, 25.4) - assert_equal(m.gap, 25.4) - assert_equal(m.crosshair_thickness, 25.4) - assert_equal(m.crosshair_length, 25.4) + assert m.position == (25.4, 25.4) + assert m.diameter == 25.4 + assert m.ring_thickness == 25.4 + assert m.gap == 25.4 + assert m.crosshair_thickness == 25.4 + assert m.crosshair_length == 25.4 def test_AMThermalPrimitive_validation(): - assert_raises(ValueError, AMThermalPrimitive, 8, (0.0, 0.0), 7, 5, 0.2, 0.0) - assert_raises(TypeError, AMThermalPrimitive, 7, (0.0, '0'), 7, 5, 0.2, 0.0) - - + pytest.raises(ValueError, AMThermalPrimitive, 8, (0.0, 0.0), 7, 5, 0.2, 0.0) + pytest.raises(TypeError, AMThermalPrimitive, 7, (0.0, "0"), 7, 5, 0.2, 0.0) def test_AMThermalPrimitive_factory(): - t = AMThermalPrimitive.from_gerber('7,0,0,7,6,0.2,45*') - assert_equal(t.code, 7) - assert_equal(t.position, (0, 0)) - assert_equal(t.outer_diameter, 7) - assert_equal(t.inner_diameter, 6) - assert_equal(t.gap, 0.2) - assert_equal(t.rotation, 45) - - + t = AMThermalPrimitive.from_gerber("7,0,0,7,6,0.2,45*") + assert t.code == 7 + assert t.position == (0, 0) + assert t.outer_diameter == 7 + assert t.inner_diameter == 6 + assert t.gap == 0.2 + assert t.rotation == 45 def test_AMThermalPrimitive_dump(): - t = AMThermalPrimitive.from_gerber('7,0,0,7,6,0.2,30*') - assert_equal(t.to_gerber(), '7,0,0,7.0,6.0,0.2,30.0*') - - + t = AMThermalPrimitive.from_gerber("7,0,0,7,6,0.2,30*") + assert t.to_gerber() == "7,0,0,7.0,6.0,0.2,30.0*" def test_AMThermalPrimitive_conversion(): t = AMThermalPrimitive(7, (25.4, 25.4), 25.4, 25.4, 25.4, 0.0) t.to_inch() - assert_equal(t.position, (1., 1.)) - assert_equal(t.outer_diameter, 1.) - assert_equal(t.inner_diameter, 1.) - assert_equal(t.gap, 1.) + assert t.position == (1.0, 1.0) + assert t.outer_diameter == 1.0 + assert t.inner_diameter == 1.0 + assert t.gap == 1.0 t = AMThermalPrimitive(7, (1, 1), 1, 1, 1, 0) t.to_metric() - assert_equal(t.position, (25.4, 25.4)) - assert_equal(t.outer_diameter, 25.4) - assert_equal(t.inner_diameter, 25.4) - assert_equal(t.gap, 25.4) + assert t.position == (25.4, 25.4) + assert t.outer_diameter == 25.4 + assert t.inner_diameter == 25.4 + assert t.gap == 25.4 def test_AMCenterLinePrimitive_validation(): - assert_raises(ValueError, AMCenterLinePrimitive, - 22, 1, 0.2, 0.5, (0, 0), 0) + pytest.raises(ValueError, AMCenterLinePrimitive, 22, 1, 0.2, 0.5, (0, 0), 0) def test_AMCenterLinePrimtive_factory(): - l = AMCenterLinePrimitive.from_gerber('21,1,6.8,1.2,3.4,0.6,0*') - assert_equal(l.code, 21) - assert_equal(l.exposure, 'on') - assert_equal(l.width, 6.8) - assert_equal(l.height, 1.2) - assert_equal(l.center, (3.4, 0.6)) - assert_equal(l.rotation, 0) + l = AMCenterLinePrimitive.from_gerber("21,1,6.8,1.2,3.4,0.6,0*") + assert l.code == 21 + assert l.exposure == "on" + assert l.width == 6.8 + assert l.height == 1.2 + assert l.center == (3.4, 0.6) + assert l.rotation == 0 def test_AMCenterLinePrimitive_dump(): - l = AMCenterLinePrimitive.from_gerber('21,1,6.8,1.2,3.4,0.6,0*') - assert_equal(l.to_gerber(), '21,1,6.8,1.2,3.4,0.6,0.0*') + l = AMCenterLinePrimitive.from_gerber("21,1,6.8,1.2,3.4,0.6,0*") + assert l.to_gerber() == "21,1,6.8,1.2,3.4,0.6,0.0*" def test_AMCenterLinePrimitive_conversion(): - l = AMCenterLinePrimitive(21, 'on', 25.4, 25.4, (25.4, 25.4), 0) + l = AMCenterLinePrimitive(21, "on", 25.4, 25.4, (25.4, 25.4), 0) l.to_inch() - assert_equal(l.width, 1.) - assert_equal(l.height, 1.) - assert_equal(l.center, (1., 1.)) + assert l.width == 1.0 + assert l.height == 1.0 + assert l.center == (1.0, 1.0) - l = AMCenterLinePrimitive(21, 'on', 1, 1, (1, 1), 0) + l = AMCenterLinePrimitive(21, "on", 1, 1, (1, 1), 0) l.to_metric() - assert_equal(l.width, 25.4) - assert_equal(l.height, 25.4) - assert_equal(l.center, (25.4, 25.4)) + assert l.width == 25.4 + assert l.height == 25.4 + assert l.center == (25.4, 25.4) def test_AMLowerLeftLinePrimitive_validation(): - assert_raises(ValueError, AMLowerLeftLinePrimitive, - 23, 1, 0.2, 0.5, (0, 0), 0) + pytest.raises(ValueError, AMLowerLeftLinePrimitive, 23, 1, 0.2, 0.5, (0, 0), 0) def test_AMLowerLeftLinePrimtive_factory(): - l = AMLowerLeftLinePrimitive.from_gerber('22,1,6.8,1.2,3.4,0.6,0*') - assert_equal(l.code, 22) - assert_equal(l.exposure, 'on') - assert_equal(l.width, 6.8) - assert_equal(l.height, 1.2) - assert_equal(l.lower_left, (3.4, 0.6)) - assert_equal(l.rotation, 0) + l = AMLowerLeftLinePrimitive.from_gerber("22,1,6.8,1.2,3.4,0.6,0*") + assert l.code == 22 + assert l.exposure == "on" + assert l.width == 6.8 + assert l.height == 1.2 + assert l.lower_left == (3.4, 0.6) + assert l.rotation == 0 def test_AMLowerLeftLinePrimitive_dump(): - l = AMLowerLeftLinePrimitive.from_gerber('22,1,6.8,1.2,3.4,0.6,0*') - assert_equal(l.to_gerber(), '22,1,6.8,1.2,3.4,0.6,0.0*') + l = AMLowerLeftLinePrimitive.from_gerber("22,1,6.8,1.2,3.4,0.6,0*") + assert l.to_gerber() == "22,1,6.8,1.2,3.4,0.6,0.0*" def test_AMLowerLeftLinePrimitive_conversion(): - l = AMLowerLeftLinePrimitive(22, 'on', 25.4, 25.4, (25.4, 25.4), 0) + l = AMLowerLeftLinePrimitive(22, "on", 25.4, 25.4, (25.4, 25.4), 0) l.to_inch() - assert_equal(l.width, 1.) - assert_equal(l.height, 1.) - assert_equal(l.lower_left, (1., 1.)) + assert l.width == 1.0 + assert l.height == 1.0 + assert l.lower_left == (1.0, 1.0) - l = AMLowerLeftLinePrimitive(22, 'on', 1, 1, (1, 1), 0) + l = AMLowerLeftLinePrimitive(22, "on", 1, 1, (1, 1), 0) l.to_metric() - assert_equal(l.width, 25.4) - assert_equal(l.height, 25.4) - assert_equal(l.lower_left, (25.4, 25.4)) + assert l.width == 25.4 + assert l.height == 25.4 + assert l.lower_left == (25.4, 25.4) def test_AMUnsupportPrimitive(): - u = AMUnsupportPrimitive.from_gerber('Test') - assert_equal(u.primitive, 'Test') - u = AMUnsupportPrimitive('Test') - assert_equal(u.to_gerber(), 'Test') + u = AMUnsupportPrimitive.from_gerber("Test") + assert u.primitive == "Test" + u = AMUnsupportPrimitive("Test") + assert u.to_gerber() == "Test" def test_AMUnsupportPrimitive_smoketest(): - u = AMUnsupportPrimitive.from_gerber('Test') + u = AMUnsupportPrimitive.from_gerber("Test") u.to_inch() u.to_metric() def test_inch(): - assert_equal(inch(25.4), 1) + assert inch(25.4) == 1 def test_metric(): - assert_equal(metric(1), 25.4) + assert metric(1) == 25.4 diff --git a/gerber/tests/test_cairo_backend.py b/gerber/tests/test_cairo_backend.py index d5ce4ed..51007a9 100644 --- a/gerber/tests/test_cairo_backend.py +++ b/gerber/tests/test_cairo_backend.py @@ -8,63 +8,87 @@ import tempfile from ..render.cairo_backend import GerberCairoContext from ..rs274x import read -from .tests import * -from nose.tools import assert_tuple_equal + def _DISABLED_test_render_two_boxes(): """Umaco exapmle of two boxes""" - _test_render('resources/example_two_square_boxes.gbr', 'golden/example_two_square_boxes.png') + _test_render( + "resources/example_two_square_boxes.gbr", "golden/example_two_square_boxes.png" + ) def _DISABLED_test_render_single_quadrant(): """Umaco exapmle of a single quadrant arc""" - _test_render('resources/example_single_quadrant.gbr', 'golden/example_single_quadrant.png') + _test_render( + "resources/example_single_quadrant.gbr", "golden/example_single_quadrant.png" + ) -def _DISABLED_test_render_simple_contour(): +def _DISABLED_test_render_simple_contour(): """Umaco exapmle of a simple arrow-shaped contour""" - gerber = _test_render('resources/example_simple_contour.gbr', 'golden/example_simple_contour.png') + gerber = _test_render( + "resources/example_simple_contour.gbr", "golden/example_simple_contour.png" + ) # Check the resulting dimensions - assert_tuple_equal(((2.0, 11.0), (1.0, 9.0)), gerber.bounding_box) + assert ((2.0, 11.0), (1.0, 9.0)) == gerber.bounding_box def _DISABLED_test_render_single_contour_1(): """Umaco example of a single contour The resulting image for this test is used by other tests because they must generate the same output.""" - _test_render('resources/example_single_contour_1.gbr', 'golden/example_single_contour.png') + _test_render( + "resources/example_single_contour_1.gbr", "golden/example_single_contour.png" + ) def _DISABLED_test_render_single_contour_2(): """Umaco exapmle of a single contour, alternate contour end order The resulting image for this test is used by other tests because they must generate the same output.""" - _test_render('resources/example_single_contour_2.gbr', 'golden/example_single_contour.png') + _test_render( + "resources/example_single_contour_2.gbr", "golden/example_single_contour.png" + ) def _DISABLED_test_render_single_contour_3(): """Umaco exapmle of a single contour with extra line""" - _test_render('resources/example_single_contour_3.gbr', 'golden/example_single_contour_3.png') + _test_render( + "resources/example_single_contour_3.gbr", "golden/example_single_contour_3.png" + ) -def _DISABLED_test_render_not_overlapping_contour(): +def _DISABLED_test_render_not_overlapping_contour(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_not_overlapping_contour.gbr', 'golden/example_not_overlapping_contour.png') + _test_render( + "resources/example_not_overlapping_contour.gbr", + "golden/example_not_overlapping_contour.png", + ) + -def _DISABLED_test_render_not_overlapping_touching(): +def _DISABLED_test_render_not_overlapping_touching(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_not_overlapping_touching.gbr', 'golden/example_not_overlapping_touching.png') + _test_render( + "resources/example_not_overlapping_touching.gbr", + "golden/example_not_overlapping_touching.png", + ) def test_render_overlapping_touching(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_overlapping_touching.gbr', 'golden/example_overlapping_touching.png') + _test_render( + "resources/example_overlapping_touching.gbr", + "golden/example_overlapping_touching.png", + ) def test_render_overlapping_contour(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_overlapping_contour.gbr', 'golden/example_overlapping_contour.png') + _test_render( + "resources/example_overlapping_contour.gbr", + "golden/example_overlapping_contour.png", + ) def _DISABLED_test_render_level_holes(): @@ -72,82 +96,107 @@ def _DISABLED_test_render_level_holes(): # TODO This is clearly rendering wrong. I'm temporarily checking this in because there are more # rendering fixes in the related repository that may resolve these. - _test_render('resources/example_level_holes.gbr', 'golden/example_overlapping_contour.png') + _test_render( + "resources/example_level_holes.gbr", "golden/example_overlapping_contour.png" + ) def _DISABLED_test_render_cutin(): """Umaco example of using a cutin""" # TODO This is clearly rendering wrong. - _test_render('resources/example_cutin.gbr', 'golden/example_cutin.png', '/Users/ham/Desktop/cutin.png') + _test_render( + "resources/example_cutin.gbr", + "golden/example_cutin.png", + "/Users/ham/Desktop/cutin.png", + ) -def _DISABLED_test_render_fully_coincident(): +def _DISABLED_test_render_fully_coincident(): """Umaco example of coincident lines rendering two contours""" - _test_render('resources/example_fully_coincident.gbr', 'golden/example_fully_coincident.png') + _test_render( + "resources/example_fully_coincident.gbr", "golden/example_fully_coincident.png" + ) -def _DISABLED_test_render_coincident_hole(): +def _DISABLED_test_render_coincident_hole(): """Umaco example of coincident lines rendering a hole in the contour""" - _test_render('resources/example_coincident_hole.gbr', 'golden/example_coincident_hole.png') + _test_render( + "resources/example_coincident_hole.gbr", "golden/example_coincident_hole.png" + ) def test_render_cutin_multiple(): """Umaco example of a region with multiple cutins""" - _test_render('resources/example_cutin_multiple.gbr', 'golden/example_cutin_multiple.png') + _test_render( + "resources/example_cutin_multiple.gbr", "golden/example_cutin_multiple.png" + ) def _DISABLED_test_flash_circle(): """Umaco example a simple circular flash with and without a hole""" - _test_render('resources/example_flash_circle.gbr', 'golden/example_flash_circle.png', - '/Users/ham/Desktop/flashcircle.png') + _test_render( + "resources/example_flash_circle.gbr", + "golden/example_flash_circle.png", + "/Users/ham/Desktop/flashcircle.png", + ) def _DISABLED_test_flash_rectangle(): """Umaco example a simple rectangular flash with and without a hole""" - _test_render('resources/example_flash_rectangle.gbr', 'golden/example_flash_rectangle.png') + _test_render( + "resources/example_flash_rectangle.gbr", "golden/example_flash_rectangle.png" + ) def _DISABLED_test_flash_obround(): """Umaco example a simple obround flash with and without a hole""" - _test_render('resources/example_flash_obround.gbr', 'golden/example_flash_obround.png') + _test_render( + "resources/example_flash_obround.gbr", "golden/example_flash_obround.png" + ) def _DISABLED_test_flash_polygon(): """Umaco example a simple polygon flash with and without a hole""" - _test_render('resources/example_flash_polygon.gbr', 'golden/example_flash_polygon.png') + _test_render( + "resources/example_flash_polygon.gbr", "golden/example_flash_polygon.png" + ) def _DISABLED_test_holes_dont_clear(): """Umaco example that an aperture with a hole does not clear the area""" - _test_render('resources/example_holes_dont_clear.gbr', 'golden/example_holes_dont_clear.png') + _test_render( + "resources/example_holes_dont_clear.gbr", "golden/example_holes_dont_clear.png" + ) def _DISABLED_test_render_am_exposure_modifier(): """Umaco example that an aperture macro with a hole does not clear the area""" - _test_render('resources/example_am_exposure_modifier.gbr', 'golden/example_am_exposure_modifier.png') + _test_render( + "resources/example_am_exposure_modifier.gbr", + "golden/example_am_exposure_modifier.png", + ) def test_render_svg_simple_contour(): """Example of rendering to an SVG file""" - _test_simple_render_svg('resources/example_simple_contour.gbr') + _test_simple_render_svg("resources/example_simple_contour.gbr") def _resolve_path(path): - return os.path.join(os.path.dirname(__file__), - path) + return os.path.join(os.path.dirname(__file__), path) -def _test_render(gerber_path, png_expected_path, create_output_path = None): +def _test_render(gerber_path, png_expected_path, create_output_path=None): """Render the gerber file and compare to the expected PNG output. Parameters @@ -176,21 +225,24 @@ def _test_render(gerber_path, png_expected_path, create_output_path = None): # 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: + with open(create_output_path, "wb") as out_file: out_file.write(actual_bytes) # 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_false(True, 'Test created the output %s. This needs to be disabled to make sure the test behaves correctly' % (create_output_path,)) + 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, 'rb') as expected_file: + with open(png_expected_path, "rb") as expected_file: expected_bytes = expected_file.read() # Don't directly use assert_equal otherwise any failure pollutes the test results - equal = (expected_bytes == actual_bytes) - assert_true(equal) + equal = expected_bytes == actual_bytes + assert equal return gerber @@ -214,14 +266,14 @@ def _test_simple_render_svg(gerber_path): gerber.render(ctx) temp_dir = tempfile.mkdtemp() - svg_temp_path = os.path.join(temp_dir, 'output.svg') + svg_temp_path = os.path.join(temp_dir, "output.svg") - assert_false(os.path.exists(svg_temp_path)) + assert not os.path.exists(svg_temp_path) ctx.dump(svg_temp_path) - assert_true(os.path.exists(svg_temp_path)) + assert os.path.exists(svg_temp_path) - with open(svg_temp_path, 'r') as expected_file: + with open(svg_temp_path, "r") as expected_file: expected_bytes = expected_file.read() - assert_equal(expected_bytes[:38], '<?xml version="1.0" encoding="UTF-8"?>') + assert expected_bytes[:38] == '<?xml version="1.0" encoding="UTF-8"?>' shutil.rmtree(temp_dir) diff --git a/gerber/tests/test_cam.py b/gerber/tests/test_cam.py index ba5e99d..8a71a32 100644 --- a/gerber/tests/test_cam.py +++ b/gerber/tests/test_cam.py @@ -3,56 +3,57 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> +import pytest + from ..cam import CamFile, FileSettings -from .tests import * def test_filesettings_defaults(): """ Test FileSettings default values """ fs = FileSettings() - assert_equal(fs.format, (2, 5)) - assert_equal(fs.notation, 'absolute') - assert_equal(fs.zero_suppression, 'trailing') - assert_equal(fs.units, 'inch') + assert fs.format == (2, 5) + assert fs.notation == "absolute" + assert fs.zero_suppression == "trailing" + assert fs.units == "inch" def test_filesettings_dict(): """ Test FileSettings Dict """ fs = FileSettings() - assert_equal(fs['format'], (2, 5)) - assert_equal(fs['notation'], 'absolute') - assert_equal(fs['zero_suppression'], 'trailing') - assert_equal(fs['units'], 'inch') + assert fs["format"] == (2, 5) + assert fs["notation"] == "absolute" + assert fs["zero_suppression"] == "trailing" + assert fs["units"] == "inch" def test_filesettings_assign(): """ Test FileSettings attribute assignment """ fs = FileSettings() - fs.units = 'test1' - fs.notation = 'test2' - fs.zero_suppression = 'test3' - fs.format = 'test4' - assert_equal(fs.units, 'test1') - assert_equal(fs.notation, 'test2') - assert_equal(fs.zero_suppression, 'test3') - assert_equal(fs.format, 'test4') + fs.units = "test1" + fs.notation = "test2" + fs.zero_suppression = "test3" + fs.format = "test4" + assert fs.units == "test1" + assert fs.notation == "test2" + assert fs.zero_suppression == "test3" + assert fs.format == "test4" def test_filesettings_dict_assign(): """ Test FileSettings dict-style attribute assignment """ fs = FileSettings() - fs['units'] = 'metric' - fs['notation'] = 'incremental' - fs['zero_suppression'] = 'leading' - fs['format'] = (1, 2) - assert_equal(fs.units, 'metric') - assert_equal(fs.notation, 'incremental') - assert_equal(fs.zero_suppression, 'leading') - assert_equal(fs.format, (1, 2)) + fs["units"] = "metric" + fs["notation"] = "incremental" + fs["zero_suppression"] = "leading" + fs["format"] = (1, 2) + assert fs.units == "metric" + assert fs.notation == "incremental" + assert fs.zero_suppression == "leading" + assert fs.format == (1, 2) def test_camfile_init(): @@ -65,7 +66,7 @@ def test_camfile_settings(): """ Test CamFile Default Settings """ cf = CamFile() - assert_equal(cf.settings, FileSettings()) + assert cf.settings == FileSettings() def test_bounds_override_smoketest(): @@ -77,73 +78,74 @@ def test_zeros(): """ Test zero/zero_suppression interaction """ fs = FileSettings() - assert_equal(fs.zero_suppression, 'trailing') - assert_equal(fs.zeros, 'leading') + assert fs.zero_suppression == "trailing" + assert fs.zeros == "leading" - fs['zero_suppression'] = 'leading' - assert_equal(fs.zero_suppression, 'leading') - assert_equal(fs.zeros, 'trailing') + fs["zero_suppression"] = "leading" + assert fs.zero_suppression == "leading" + assert fs.zeros == "trailing" - fs.zero_suppression = 'trailing' - assert_equal(fs.zero_suppression, 'trailing') - assert_equal(fs.zeros, 'leading') + fs.zero_suppression = "trailing" + assert fs.zero_suppression == "trailing" + assert fs.zeros == "leading" - fs['zeros'] = 'trailing' - assert_equal(fs.zeros, 'trailing') - assert_equal(fs.zero_suppression, 'leading') + fs["zeros"] = "trailing" + assert fs.zeros == "trailing" + assert fs.zero_suppression == "leading" - fs.zeros = 'leading' - assert_equal(fs.zeros, 'leading') - assert_equal(fs.zero_suppression, 'trailing') + fs.zeros = "leading" + assert fs.zeros == "leading" + assert fs.zero_suppression == "trailing" - fs = FileSettings(zeros='leading') - assert_equal(fs.zeros, 'leading') - assert_equal(fs.zero_suppression, 'trailing') + fs = FileSettings(zeros="leading") + assert fs.zeros == "leading" + assert fs.zero_suppression == "trailing" - fs = FileSettings(zero_suppression='leading') - assert_equal(fs.zeros, 'trailing') - assert_equal(fs.zero_suppression, 'leading') + fs = FileSettings(zero_suppression="leading") + assert fs.zeros == "trailing" + assert fs.zero_suppression == "leading" - fs = FileSettings(zeros='leading', zero_suppression='trailing') - assert_equal(fs.zeros, 'leading') - assert_equal(fs.zero_suppression, 'trailing') + fs = FileSettings(zeros="leading", zero_suppression="trailing") + assert fs.zeros == "leading" + assert fs.zero_suppression == "trailing" - fs = FileSettings(zeros='trailing', zero_suppression='leading') - assert_equal(fs.zeros, 'trailing') - assert_equal(fs.zero_suppression, 'leading') + fs = FileSettings(zeros="trailing", zero_suppression="leading") + assert fs.zeros == "trailing" + assert fs.zero_suppression == "leading" def test_filesettings_validation(): """ Test FileSettings constructor argument validation """ # absolute-ish is not a valid notation - assert_raises(ValueError, FileSettings, 'absolute-ish', - 'inch', None, (2, 5), None) + pytest.raises(ValueError, FileSettings, "absolute-ish", "inch", None, (2, 5), None) # degrees kelvin isn't a valid unit for a CAM file - assert_raises(ValueError, FileSettings, 'absolute', - 'degrees kelvin', None, (2, 5), None) + pytest.raises( + ValueError, FileSettings, "absolute", "degrees kelvin", None, (2, 5), None + ) - assert_raises(ValueError, FileSettings, 'absolute', - 'inch', 'leading', (2, 5), 'leading') + pytest.raises( + ValueError, FileSettings, "absolute", "inch", "leading", (2, 5), "leading" + ) # Technnically this should be an error, but Eangle files often do this incorrectly so we # allow it - #assert_raises(ValueError, FileSettings, 'absolute', + # pytest.raises(ValueError, FileSettings, 'absolute', # 'inch', 'following', (2, 5), None) - assert_raises(ValueError, FileSettings, 'absolute', - 'inch', None, (2, 5), 'following') - assert_raises(ValueError, FileSettings, 'absolute', - 'inch', None, (2, 5, 6), None) + pytest.raises( + ValueError, FileSettings, "absolute", "inch", None, (2, 5), "following" + ) + pytest.raises(ValueError, FileSettings, "absolute", "inch", None, (2, 5, 6), None) def test_key_validation(): fs = FileSettings() - assert_raises(KeyError, fs.__getitem__, 'octopus') - assert_raises(KeyError, fs.__setitem__, 'octopus', 'do not care') - assert_raises(ValueError, fs.__setitem__, 'notation', 'absolute-ish') - assert_raises(ValueError, fs.__setitem__, 'units', 'degrees kelvin') - assert_raises(ValueError, fs.__setitem__, 'zero_suppression', 'following') - assert_raises(ValueError, fs.__setitem__, 'zeros', 'following') - assert_raises(ValueError, fs.__setitem__, 'format', (2, 5, 6)) + pytest.raises(KeyError, fs.__getitem__, "octopus") + pytest.raises(KeyError, fs.__setitem__, "octopus", "do not care") + pytest.raises(ValueError, fs.__setitem__, "notation", "absolute-ish") + pytest.raises(ValueError, fs.__setitem__, "units", "degrees kelvin") + pytest.raises(ValueError, fs.__setitem__, "zero_suppression", "following") + pytest.raises(ValueError, fs.__setitem__, "zeros", "following") + pytest.raises(ValueError, fs.__setitem__, "format", (2, 5, 6)) diff --git a/gerber/tests/test_common.py b/gerber/tests/test_common.py index 0224c48..a6b1264 100644 --- a/gerber/tests/test_common.py +++ b/gerber/tests/test_common.py @@ -6,15 +6,12 @@ from ..exceptions import ParseError from ..common import read, loads from ..excellon import ExcellonFile from ..rs274x import GerberFile -from .tests import * - import os +import pytest -NCDRILL_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ncdrill.DRD') -TOP_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") +TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), "resources/top_copper.GTL") def test_file_type_detection(): @@ -22,20 +19,20 @@ def test_file_type_detection(): """ ncdrill = read(NCDRILL_FILE) top_copper = read(TOP_COPPER_FILE) - assert_true(isinstance(ncdrill, ExcellonFile)) - assert_true(isinstance(top_copper, GerberFile)) + assert isinstance(ncdrill, ExcellonFile) + assert isinstance(top_copper, GerberFile) def test_load_from_string(): - with open(NCDRILL_FILE, 'rU') as f: + with open(NCDRILL_FILE, "rU") as f: ncdrill = loads(f.read()) - with open(TOP_COPPER_FILE, 'rU') as f: + with open(TOP_COPPER_FILE, "rU") as f: top_copper = loads(f.read()) - assert_true(isinstance(ncdrill, ExcellonFile)) - assert_true(isinstance(top_copper, GerberFile)) + assert isinstance(ncdrill, ExcellonFile) + assert isinstance(top_copper, GerberFile) def test_file_type_validation(): """ Test file format validation """ - assert_raises(ParseError, read, __file__) + pytest.raises(ParseError, read, __file__) diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index d17791c..d6e83cc 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -3,16 +3,15 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> import os +import pytest from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from ..excellon import DrillHit, DrillSlot from ..excellon_statements import ExcellonTool, RouteModeStmt -from .tests import * -NCDRILL_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ncdrill.DRD') +NCDRILL_FILE = os.path.join(os.path.dirname(__file__), "resources/ncdrill.DRD") def test_format_detection(): @@ -21,320 +20,327 @@ def test_format_detection(): with open(NCDRILL_FILE, "rU") as f: data = f.read() settings = detect_excellon_format(data) - assert_equal(settings['format'], (2, 4)) - assert_equal(settings['zeros'], 'trailing') + assert settings["format"] == (2, 4) + assert settings["zeros"] == "trailing" settings = detect_excellon_format(filename=NCDRILL_FILE) - assert_equal(settings['format'], (2, 4)) - assert_equal(settings['zeros'], 'trailing') + assert settings["format"] == (2, 4) + assert settings["zeros"] == "trailing" def test_read(): ncdrill = read(NCDRILL_FILE) - assert(isinstance(ncdrill, ExcellonFile)) + assert isinstance(ncdrill, ExcellonFile) def test_write(): ncdrill = read(NCDRILL_FILE) - ncdrill.write('test.ncd') + ncdrill.write("test.ncd") with open(NCDRILL_FILE, "rU") as src: srclines = src.readlines() - with open('test.ncd', "rU") as res: + with open("test.ncd", "rU") as res: for idx, line in enumerate(res): - assert_equal(line.strip(), srclines[idx].strip()) - os.remove('test.ncd') + assert line.strip() == srclines[idx].strip() + os.remove("test.ncd") def test_read_settings(): ncdrill = read(NCDRILL_FILE) - assert_equal(ncdrill.settings['format'], (2, 4)) - assert_equal(ncdrill.settings['zeros'], 'trailing') + assert ncdrill.settings["format"] == (2, 4) + assert ncdrill.settings["zeros"] == "trailing" def test_bounding_box(): ncdrill = read(NCDRILL_FILE) xbound, ybound = ncdrill.bounding_box - assert_array_almost_equal(xbound, (0.1300, 2.1430)) - assert_array_almost_equal(ybound, (0.3946, 1.7164)) + pytest.approx(xbound, (0.1300, 2.1430)) + pytest.approx(ybound, (0.3946, 1.7164)) def test_report(): ncdrill = read(NCDRILL_FILE) rprt = ncdrill.report() + def test_conversion(): import copy + ncdrill = read(NCDRILL_FILE) - assert_equal(ncdrill.settings.units, 'inch') + assert ncdrill.settings.units == "inch" ncdrill_inch = copy.deepcopy(ncdrill) ncdrill.to_metric() - assert_equal(ncdrill.settings.units, 'metric') + assert ncdrill.settings.units == "metric" for tool in iter(ncdrill_inch.tools.values()): tool.to_metric() for statement in ncdrill_inch.statements: statement.to_metric() - for m_tool, i_tool in zip(iter(ncdrill.tools.values()), - iter(ncdrill_inch.tools.values())): - assert_equal(i_tool, m_tool) + for m_tool, i_tool in zip( + iter(ncdrill.tools.values()), iter(ncdrill_inch.tools.values()) + ): + assert i_tool == m_tool for m, i in zip(ncdrill.primitives, ncdrill_inch.primitives): - assert_equal(m.position, i.position, '%s not equal to %s' % (m, i)) - assert_equal(m.diameter, i.diameter, '%s not equal to %s' % (m, i)) + assert m.position == i.position, "%s not equal to %s" % (m, i) + assert m.diameter == i.diameter, "%s not equal to %s" % (m, i) def test_parser_hole_count(): settings = FileSettings(**detect_excellon_format(NCDRILL_FILE)) p = ExcellonParser(settings) p.parse(NCDRILL_FILE) - assert_equal(p.hole_count, 36) + assert p.hole_count == 36 def test_parser_hole_sizes(): settings = FileSettings(**detect_excellon_format(NCDRILL_FILE)) p = ExcellonParser(settings) p.parse(NCDRILL_FILE) - assert_equal(p.hole_sizes, [0.0236, 0.0354, 0.04, 0.126, 0.128]) + assert p.hole_sizes == [0.0236, 0.0354, 0.04, 0.126, 0.128] def test_parse_whitespace(): p = ExcellonParser(FileSettings()) - assert_equal(p._parse_line(' '), None) + assert p._parse_line(" ") == None def test_parse_comment(): p = ExcellonParser(FileSettings()) - p._parse_line(';A comment') - assert_equal(p.statements[0].comment, 'A comment') + p._parse_line(";A comment") + assert p.statements[0].comment == "A comment" def test_parse_format_comment(): p = ExcellonParser(FileSettings()) - p._parse_line('; FILE_FORMAT=9:9 ') - assert_equal(p.format, (9, 9)) + p._parse_line("; FILE_FORMAT=9:9 ") + assert p.format == (9, 9) def test_parse_header(): p = ExcellonParser(FileSettings()) - p._parse_line('M48 ') - assert_equal(p.state, 'HEADER') - p._parse_line('M95 ') - assert_equal(p.state, 'DRILL') + p._parse_line("M48 ") + assert p.state == "HEADER" + p._parse_line("M95 ") + assert p.state == "DRILL" def test_parse_rout(): p = ExcellonParser(FileSettings()) - p._parse_line('G00X040944Y019842') - assert_equal(p.state, 'ROUT') - p._parse_line('G05 ') - assert_equal(p.state, 'DRILL') + p._parse_line("G00X040944Y019842") + assert p.state == "ROUT" + p._parse_line("G05 ") + assert p.state == "DRILL" def test_parse_version(): p = ExcellonParser(FileSettings()) - p._parse_line('VER,1 ') - assert_equal(p.statements[0].version, 1) - p._parse_line('VER,2 ') - assert_equal(p.statements[1].version, 2) + p._parse_line("VER,1 ") + assert p.statements[0].version == 1 + p._parse_line("VER,2 ") + assert p.statements[1].version == 2 def test_parse_format(): p = ExcellonParser(FileSettings()) - p._parse_line('FMAT,1 ') - assert_equal(p.statements[0].format, 1) - p._parse_line('FMAT,2 ') - assert_equal(p.statements[1].format, 2) + p._parse_line("FMAT,1 ") + assert p.statements[0].format == 1 + p._parse_line("FMAT,2 ") + assert p.statements[1].format == 2 def test_parse_units(): - settings = FileSettings(units='inch', zeros='trailing') + settings = FileSettings(units="inch", zeros="trailing") p = ExcellonParser(settings) - p._parse_line(';METRIC,LZ') - assert_equal(p.units, 'inch') - assert_equal(p.zeros, 'trailing') - p._parse_line('METRIC,LZ') - assert_equal(p.units, 'metric') - assert_equal(p.zeros, 'leading') + p._parse_line(";METRIC,LZ") + assert p.units == "inch" + assert p.zeros == "trailing" + p._parse_line("METRIC,LZ") + assert p.units == "metric" + assert p.zeros == "leading" def test_parse_incremental_mode(): - settings = FileSettings(units='inch', zeros='trailing') + settings = FileSettings(units="inch", zeros="trailing") p = ExcellonParser(settings) - assert_equal(p.notation, 'absolute') - p._parse_line('ICI,ON ') - assert_equal(p.notation, 'incremental') - p._parse_line('ICI,OFF ') - assert_equal(p.notation, 'absolute') + assert p.notation == "absolute" + p._parse_line("ICI,ON ") + assert p.notation == "incremental" + p._parse_line("ICI,OFF ") + assert p.notation == "absolute" def test_parse_absolute_mode(): - settings = FileSettings(units='inch', zeros='trailing') + settings = FileSettings(units="inch", zeros="trailing") p = ExcellonParser(settings) - assert_equal(p.notation, 'absolute') - p._parse_line('ICI,ON ') - assert_equal(p.notation, 'incremental') - p._parse_line('G90 ') - assert_equal(p.notation, 'absolute') + assert p.notation == "absolute" + p._parse_line("ICI,ON ") + assert p.notation == "incremental" + p._parse_line("G90 ") + assert p.notation == "absolute" def test_parse_repeat_hole(): p = ExcellonParser(FileSettings()) p.active_tool = ExcellonTool(FileSettings(), number=8) - p._parse_line('R03X1.5Y1.5') - assert_equal(p.statements[0].count, 3) + p._parse_line("R03X1.5Y1.5") + assert p.statements[0].count == 3 def test_parse_incremental_position(): - p = ExcellonParser(FileSettings(notation='incremental')) - p._parse_line('X01Y01') - p._parse_line('X01Y01') - assert_equal(p.pos, [2., 2.]) + p = ExcellonParser(FileSettings(notation="incremental")) + p._parse_line("X01Y01") + p._parse_line("X01Y01") + assert p.pos == [2.0, 2.0] def test_parse_unknown(): p = ExcellonParser(FileSettings()) - p._parse_line('Not A Valid Statement') - assert_equal(p.statements[0].stmt, 'Not A Valid Statement') + p._parse_line("Not A Valid Statement") + assert p.statements[0].stmt == "Not A Valid Statement" + def test_drill_hit_units_conversion(): """ Test unit conversion for drill hits """ # Inch hit - settings = FileSettings(units='inch') + settings = FileSettings(units="inch") tool = ExcellonTool(settings, diameter=1.0) hit = DrillHit(tool, (1.0, 1.0)) - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.position, (1.0, 1.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.position == (1.0, 1.0) # No Effect hit.to_inch() - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.position, (1.0, 1.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.position == (1.0, 1.0) # Should convert hit.to_metric() - assert_equal(hit.tool.settings.units, 'metric') - assert_equal(hit.tool.diameter, 25.4) - assert_equal(hit.position, (25.4, 25.4)) + assert hit.tool.settings.units == "metric" + assert hit.tool.diameter == 25.4 + assert hit.position == (25.4, 25.4) # No Effect hit.to_metric() - assert_equal(hit.tool.settings.units, 'metric') - assert_equal(hit.tool.diameter, 25.4) - assert_equal(hit.position, (25.4, 25.4)) + assert hit.tool.settings.units == "metric" + assert hit.tool.diameter == 25.4 + assert hit.position == (25.4, 25.4) # Convert back to inch hit.to_inch() - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.position, (1.0, 1.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.position == (1.0, 1.0) + def test_drill_hit_offset(): TEST_VECTORS = [ - ((0.0 ,0.0), (0.0, 1.0), (0.0, 1.0)), + ((0.0, 0.0), (0.0, 1.0), (0.0, 1.0)), ((0.0, 0.0), (1.0, 1.0), (1.0, 1.0)), ((1.0, 1.0), (0.0, -1.0), (1.0, 0.0)), ((1.0, 1.0), (-1.0, -1.0), (0.0, 0.0)), - ] for position, offset, expected in TEST_VECTORS: - settings = FileSettings(units='inch') + settings = FileSettings(units="inch") tool = ExcellonTool(settings, diameter=1.0) hit = DrillHit(tool, position) - assert_equal(hit.position, position) + assert hit.position == position hit.offset(offset[0], offset[1]) - assert_equal(hit.position, expected) + assert hit.position == expected def test_drill_slot_units_conversion(): """ Test unit conversion for drill hits """ # Inch hit - settings = FileSettings(units='inch') + settings = FileSettings(units="inch") tool = ExcellonTool(settings, diameter=1.0) hit = DrillSlot(tool, (1.0, 1.0), (10.0, 10.0), DrillSlot.TYPE_ROUT) - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.start, (1.0, 1.0)) - assert_equal(hit.end, (10.0, 10.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.start == (1.0, 1.0) + assert hit.end == (10.0, 10.0) # No Effect hit.to_inch() - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.start, (1.0, 1.0)) - assert_equal(hit.end, (10.0, 10.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.start == (1.0, 1.0) + assert hit.end == (10.0, 10.0) # Should convert hit.to_metric() - assert_equal(hit.tool.settings.units, 'metric') - assert_equal(hit.tool.diameter, 25.4) - assert_equal(hit.start, (25.4, 25.4)) - assert_equal(hit.end, (254.0, 254.0)) + assert hit.tool.settings.units == "metric" + assert hit.tool.diameter == 25.4 + assert hit.start == (25.4, 25.4) + assert hit.end == (254.0, 254.0) # No Effect hit.to_metric() - assert_equal(hit.tool.settings.units, 'metric') - assert_equal(hit.tool.diameter, 25.4) - assert_equal(hit.start, (25.4, 25.4)) - assert_equal(hit.end, (254.0, 254.0)) + assert hit.tool.settings.units == "metric" + assert hit.tool.diameter == 25.4 + assert hit.start == (25.4, 25.4) + assert hit.end == (254.0, 254.0) # Convert back to inch hit.to_inch() - assert_equal(hit.tool.settings.units, 'inch') - assert_equal(hit.tool.diameter, 1.0) - assert_equal(hit.start, (1.0, 1.0)) - assert_equal(hit.end, (10.0, 10.0)) + assert hit.tool.settings.units == "inch" + assert hit.tool.diameter == 1.0 + assert hit.start == (1.0, 1.0) + assert hit.end == (10.0, 10.0) + def test_drill_slot_offset(): TEST_VECTORS = [ - ((0.0 ,0.0), (1.0, 1.0), (0.0, 0.0), (0.0, 0.0), (1.0, 1.0)), + ((0.0, 0.0), (1.0, 1.0), (0.0, 0.0), (0.0, 0.0), (1.0, 1.0)), ((0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (1.0, 0.0), (2.0, 1.0)), ((0.0, 0.0), (1.0, 1.0), (1.0, 1.0), (1.0, 1.0), (2.0, 2.0)), ((0.0, 0.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0), (0.0, 2.0)), ] for start, end, offset, expected_start, expected_end in TEST_VECTORS: - settings = FileSettings(units='inch') + settings = FileSettings(units="inch") tool = ExcellonTool(settings, diameter=1.0) slot = DrillSlot(tool, start, end, DrillSlot.TYPE_ROUT) - assert_equal(slot.start, start) - assert_equal(slot.end, end) + assert slot.start == start + assert slot.end == end slot.offset(offset[0], offset[1]) - assert_equal(slot.start, expected_start) - assert_equal(slot.end, expected_end) + assert slot.start == expected_start + assert slot.end == expected_end + def test_drill_slot_bounds(): TEST_VECTORS = [ ((0.0, 0.0), (1.0, 1.0), 1.0, ((-0.5, 1.5), (-0.5, 1.5))), ((0.0, 0.0), (1.0, 1.0), 0.5, ((-0.25, 1.25), (-0.25, 1.25))), ] - for start, end, diameter, expected, in TEST_VECTORS: - settings = FileSettings(units='inch') + for start, end, diameter, expected in TEST_VECTORS: + settings = FileSettings(units="inch") tool = ExcellonTool(settings, diameter=diameter) slot = DrillSlot(tool, start, end, DrillSlot.TYPE_ROUT) - assert_equal(slot.bounding_box, expected) + assert slot.bounding_box == expected + def test_handling_multi_line_g00_and_g1(): """Route Mode statements with coordinates on separate line are handled @@ -355,6 +361,6 @@ M16 """ uut = ExcellonParser() uut.parse_raw(test_data) - assert_equal(len([stmt for stmt in uut.statements - if isinstance(stmt, RouteModeStmt)]), 2) - + assert ( + len([stmt for stmt in uut.statements if isinstance(stmt, RouteModeStmt)]) == 2 + ) diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index 8e6e06e..41fe294 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -3,15 +3,15 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> -from .tests import assert_equal, assert_not_equal, assert_raises +import pytest from ..excellon_statements import * from ..cam import FileSettings def test_excellon_statement_implementation(): stmt = ExcellonStatement() - assert_raises(NotImplementedError, stmt.from_excellon, None) - assert_raises(NotImplementedError, stmt.to_excellon) + pytest.raises(NotImplementedError, stmt.from_excellon, None) + pytest.raises(NotImplementedError, stmt.to_excellon) def test_excellontstmt(): @@ -26,154 +26,173 @@ def test_excellontstmt(): def test_excellontool_factory(): """ Test ExcellonTool factory methods """ - exc_line = 'T8F01B02S00003H04Z05C0.12500' - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') + exc_line = "T8F01B02S00003H04Z05C0.12500" + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) tool = ExcellonTool.from_excellon(exc_line, settings) - assert_equal(tool.number, 8) - assert_equal(tool.diameter, 0.125) - assert_equal(tool.feed_rate, 1) - assert_equal(tool.retract_rate, 2) - assert_equal(tool.rpm, 3) - assert_equal(tool.max_hit_count, 4) - assert_equal(tool.depth_offset, 5) - - stmt = {'number': 8, 'feed_rate': 1, 'retract_rate': 2, 'rpm': 3, - 'diameter': 0.125, 'max_hit_count': 4, 'depth_offset': 5} + assert tool.number == 8 + assert tool.diameter == 0.125 + assert tool.feed_rate == 1 + assert tool.retract_rate == 2 + assert tool.rpm == 3 + assert tool.max_hit_count == 4 + assert tool.depth_offset == 5 + + stmt = { + "number": 8, + "feed_rate": 1, + "retract_rate": 2, + "rpm": 3, + "diameter": 0.125, + "max_hit_count": 4, + "depth_offset": 5, + } tool = ExcellonTool.from_dict(settings, stmt) - assert_equal(tool.number, 8) - assert_equal(tool.diameter, 0.125) - assert_equal(tool.feed_rate, 1) - assert_equal(tool.retract_rate, 2) - assert_equal(tool.rpm, 3) - assert_equal(tool.max_hit_count, 4) - assert_equal(tool.depth_offset, 5) + assert tool.number == 8 + assert tool.diameter == 0.125 + assert tool.feed_rate == 1 + assert tool.retract_rate == 2 + assert tool.rpm == 3 + assert tool.max_hit_count == 4 + assert tool.depth_offset == 5 def test_excellontool_dump(): """ Test ExcellonTool to_excellon() """ - exc_lines = ['T01F0S0C0.01200', 'T02F0S0C0.01500', 'T03F0S0C0.01968', - 'T04F0S0C0.02800', 'T05F0S0C0.03300', 'T06F0S0C0.03800', - 'T07F0S0C0.04300', 'T08F0S0C0.12500', 'T09F0S0C0.13000', - 'T08B01F02H03S00003C0.12500Z04', 'T01F0S300.999C0.01200'] - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') + exc_lines = [ + "T01F0S0C0.01200", + "T02F0S0C0.01500", + "T03F0S0C0.01968", + "T04F0S0C0.02800", + "T05F0S0C0.03300", + "T06F0S0C0.03800", + "T07F0S0C0.04300", + "T08F0S0C0.12500", + "T09F0S0C0.13000", + "T08B01F02H03S00003C0.12500Z04", + "T01F0S300.999C0.01200", + ] + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) for line in exc_lines: tool = ExcellonTool.from_excellon(line, settings) - assert_equal(tool.to_excellon(), line) + assert tool.to_excellon() == line def test_excellontool_order(): - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') - line = 'T8F00S00C0.12500' + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) + line = "T8F00S00C0.12500" tool1 = ExcellonTool.from_excellon(line, settings) - line = 'T8C0.12500F00S00' + line = "T8C0.12500F00S00" tool2 = ExcellonTool.from_excellon(line, settings) - assert_equal(tool1.diameter, tool2.diameter) - assert_equal(tool1.feed_rate, tool2.feed_rate) - assert_equal(tool1.rpm, tool2.rpm) + assert tool1.diameter == tool2.diameter + assert tool1.feed_rate == tool2.feed_rate + assert tool1.rpm == tool2.rpm def test_excellontool_conversion(): - tool = ExcellonTool.from_dict(FileSettings(units='metric'), - {'number': 8, 'diameter': 25.4}) + tool = ExcellonTool.from_dict( + FileSettings(units="metric"), {"number": 8, "diameter": 25.4} + ) tool.to_inch() - assert_equal(tool.diameter, 1.) - tool = ExcellonTool.from_dict(FileSettings(units='inch'), - {'number': 8, 'diameter': 1.}) + assert tool.diameter == 1.0 + tool = ExcellonTool.from_dict( + FileSettings(units="inch"), {"number": 8, "diameter": 1.0} + ) tool.to_metric() - assert_equal(tool.diameter, 25.4) + assert tool.diameter == 25.4 # Shouldn't change units if we're already using target units - tool = ExcellonTool.from_dict(FileSettings(units='inch'), - {'number': 8, 'diameter': 25.4}) + tool = ExcellonTool.from_dict( + FileSettings(units="inch"), {"number": 8, "diameter": 25.4} + ) tool.to_inch() - assert_equal(tool.diameter, 25.4) - tool = ExcellonTool.from_dict(FileSettings(units='metric'), - {'number': 8, 'diameter': 1.}) + assert tool.diameter == 25.4 + tool = ExcellonTool.from_dict( + FileSettings(units="metric"), {"number": 8, "diameter": 1.0} + ) tool.to_metric() - assert_equal(tool.diameter, 1.) + assert tool.diameter == 1.0 def test_excellontool_repr(): - tool = ExcellonTool.from_dict(FileSettings(), - {'number': 8, 'diameter': 0.125}) - assert_equal(str(tool), '<ExcellonTool 08: 0.125in. dia.>') - tool = ExcellonTool.from_dict(FileSettings(units='metric'), - {'number': 8, 'diameter': 0.125}) - assert_equal(str(tool), '<ExcellonTool 08: 0.125mm dia.>') + tool = ExcellonTool.from_dict(FileSettings(), {"number": 8, "diameter": 0.125}) + assert str(tool) == "<ExcellonTool 08: 0.125in. dia.>" + tool = ExcellonTool.from_dict( + FileSettings(units="metric"), {"number": 8, "diameter": 0.125} + ) + assert str(tool) == "<ExcellonTool 08: 0.125mm dia.>" def test_excellontool_equality(): - t = ExcellonTool.from_dict( - FileSettings(), {'number': 8, 'diameter': 0.125}) + t = ExcellonTool.from_dict(FileSettings(), {"number": 8, "diameter": 0.125}) + t1 = ExcellonTool.from_dict(FileSettings(), {"number": 8, "diameter": 0.125}) + assert t == t1 t1 = ExcellonTool.from_dict( - FileSettings(), {'number': 8, 'diameter': 0.125}) - assert_equal(t, t1) - t1 = ExcellonTool.from_dict(FileSettings(units='metric'), - {'number': 8, 'diameter': 0.125}) - assert_not_equal(t, t1) + FileSettings(units="metric"), {"number": 8, "diameter": 0.125} + ) + assert t != t1 def test_toolselection_factory(): """ Test ToolSelectionStmt factory method """ - stmt = ToolSelectionStmt.from_excellon('T01') - assert_equal(stmt.tool, 1) - assert_equal(stmt.compensation_index, None) - stmt = ToolSelectionStmt.from_excellon('T0223') - assert_equal(stmt.tool, 2) - assert_equal(stmt.compensation_index, 23) - stmt = ToolSelectionStmt.from_excellon('T042') - assert_equal(stmt.tool, 42) - assert_equal(stmt.compensation_index, None) + stmt = ToolSelectionStmt.from_excellon("T01") + assert stmt.tool == 1 + assert stmt.compensation_index == None + stmt = ToolSelectionStmt.from_excellon("T0223") + assert stmt.tool == 2 + assert stmt.compensation_index == 23 + stmt = ToolSelectionStmt.from_excellon("T042") + assert stmt.tool == 42 + assert stmt.compensation_index == None def test_toolselection_dump(): """ Test ToolSelectionStmt to_excellon() """ - lines = ['T01', 'T0223', 'T10', 'T09', 'T0000'] + lines = ["T01", "T0223", "T10", "T09", "T0000"] for line in lines: stmt = ToolSelectionStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_z_axis_infeed_rate_factory(): """ Test ZAxisInfeedRateStmt factory method """ - stmt = ZAxisInfeedRateStmt.from_excellon('F01') - assert_equal(stmt.rate, 1) - stmt = ZAxisInfeedRateStmt.from_excellon('F2') - assert_equal(stmt.rate, 2) - stmt = ZAxisInfeedRateStmt.from_excellon('F03') - assert_equal(stmt.rate, 3) + stmt = ZAxisInfeedRateStmt.from_excellon("F01") + assert stmt.rate == 1 + stmt = ZAxisInfeedRateStmt.from_excellon("F2") + assert stmt.rate == 2 + stmt = ZAxisInfeedRateStmt.from_excellon("F03") + assert stmt.rate == 3 def test_z_axis_infeed_rate_dump(): """ Test ZAxisInfeedRateStmt to_excellon() """ - inputs = [ - ('F01', 'F01'), - ('F2', 'F02'), - ('F00003', 'F03') - ] + inputs = [("F01", "F01"), ("F2", "F02"), ("F00003", "F03")] for input_rate, expected_output in inputs: stmt = ZAxisInfeedRateStmt.from_excellon(input_rate) - assert_equal(stmt.to_excellon(), expected_output) + assert stmt.to_excellon() == expected_output def test_coordinatestmt_factory(): """ Test CoordinateStmt factory method """ - settings = FileSettings(format=(2, 5), zero_suppression='trailing', - units='inch', notation='absolute') + settings = FileSettings( + format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute" + ) - line = 'X0278207Y0065293' + line = "X0278207Y0065293" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.x, 2.78207) - assert_equal(stmt.y, 0.65293) + assert stmt.x == 2.78207 + assert stmt.y == 0.65293 # line = 'X02945' # stmt = CoordinateStmt.from_excellon(line) @@ -183,518 +202,533 @@ def test_coordinatestmt_factory(): # stmt = CoordinateStmt.from_excellon(line) # assert_equal(stmt.y, 0.575) - settings = FileSettings(format=(2, 4), zero_suppression='leading', - units='inch', notation='absolute') + settings = FileSettings( + format=(2, 4), zero_suppression="leading", units="inch", notation="absolute" + ) - line = 'X9660Y4639' + line = "X9660Y4639" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.x, 0.9660) - assert_equal(stmt.y, 0.4639) - assert_equal(stmt.to_excellon(settings), "X9660Y4639") - assert_equal(stmt.units, 'inch') + assert stmt.x == 0.9660 + assert stmt.y == 0.4639 + assert stmt.to_excellon(settings) == "X9660Y4639" + assert stmt.units == "inch" - settings.units = 'metric' + settings.units = "metric" stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" def test_coordinatestmt_dump(): """ Test CoordinateStmt to_excellon() """ - lines = ['X278207Y65293', 'X243795', 'Y82528', 'Y86028', - 'X251295Y81528', 'X2525Y78', 'X255Y575', 'Y52', - 'X2675', 'Y575', 'X2425', 'Y52', 'X23', ] - settings = FileSettings(format=(2, 4), zero_suppression='leading', - units='inch', notation='absolute') + lines = [ + "X278207Y65293", + "X243795", + "Y82528", + "Y86028", + "X251295Y81528", + "X2525Y78", + "X255Y575", + "Y52", + "X2675", + "Y575", + "X2425", + "Y52", + "X23", + ] + settings = FileSettings( + format=(2, 4), zero_suppression="leading", units="inch", notation="absolute" + ) for line in lines: stmt = CoordinateStmt.from_excellon(line, settings) - assert_equal(stmt.to_excellon(settings), line) + assert stmt.to_excellon(settings) == line def test_coordinatestmt_conversion(): settings = FileSettings() - settings.units = 'metric' - stmt = CoordinateStmt.from_excellon('X254Y254', settings) + settings.units = "metric" + stmt = CoordinateStmt.from_excellon("X254Y254", settings) # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.x == 25.4 + assert stmt.y == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.units == "inch" + assert stmt.x == 1.0 + assert stmt.y == 1.0 # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.x == 1.0 + assert stmt.y == 1.0 - settings.units = 'inch' - stmt = CoordinateStmt.from_excellon('X01Y01', settings) + settings.units = "inch" + stmt = CoordinateStmt.from_excellon("X01Y01", settings) # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 1.) + assert stmt.x == 1.0 + assert stmt.y == 1.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.units == "metric" + assert stmt.x == 25.4 + assert stmt.y == 25.4 # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 25.4) + assert stmt.x == 25.4 + assert stmt.y == 25.4 def test_coordinatestmt_offset(): - stmt = CoordinateStmt.from_excellon('X01Y01', FileSettings()) + stmt = CoordinateStmt.from_excellon("X01Y01", FileSettings()) stmt.offset() - assert_equal(stmt.x, 1) - assert_equal(stmt.y, 1) + assert stmt.x == 1 + assert stmt.y == 1 stmt.offset(1, 0) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 1.) + assert stmt.x == 2.0 + assert stmt.y == 1.0 stmt.offset(0, 1) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 2.) + assert stmt.x == 2.0 + assert stmt.y == 2.0 def test_coordinatestmt_string(): - settings = FileSettings(format=(2, 4), zero_suppression='leading', - units='inch', notation='absolute') - stmt = CoordinateStmt.from_excellon('X9660Y4639', settings) - assert_equal(str(stmt), '<Coordinate Statement: X: 0.966 Y: 0.4639 >') + settings = FileSettings( + format=(2, 4), zero_suppression="leading", units="inch", notation="absolute" + ) + stmt = CoordinateStmt.from_excellon("X9660Y4639", settings) + assert str(stmt) == "<Coordinate Statement: X: 0.966 Y: 0.4639 >" def test_repeathole_stmt_factory(): - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', - FileSettings(zeros='leading', - units='inch')) - assert_equal(stmt.count, 4) - assert_equal(stmt.xdelta, 1.5) - assert_equal(stmt.ydelta, 32) - assert_equal(stmt.units, 'inch') + stmt = RepeatHoleStmt.from_excellon( + "R0004X015Y32", FileSettings(zeros="leading", units="inch") + ) + assert stmt.count == 4 + assert stmt.xdelta == 1.5 + assert stmt.ydelta == 32 + assert stmt.units == "inch" - stmt = RepeatHoleStmt.from_excellon('R0004X015Y32', - FileSettings(zeros='leading', - units='metric')) - assert_equal(stmt.units, 'metric') + stmt = RepeatHoleStmt.from_excellon( + "R0004X015Y32", FileSettings(zeros="leading", units="metric") + ) + assert stmt.units == "metric" def test_repeatholestmt_dump(): - line = 'R4X015Y32' + line = "R4X015Y32" stmt = RepeatHoleStmt.from_excellon(line, FileSettings()) - assert_equal(stmt.to_excellon(FileSettings()), line) + assert stmt.to_excellon(FileSettings()) == line def test_repeatholestmt_conversion(): - line = 'R4X0254Y254' + line = "R4X0254Y254" settings = FileSettings() - settings.units = 'metric' + settings.units = "metric" stmt = RepeatHoleStmt.from_excellon(line, settings) # No effect stmt.to_metric() - assert_equal(stmt.xdelta, 2.54) - assert_equal(stmt.ydelta, 25.4) + assert stmt.xdelta == 2.54 + assert stmt.ydelta == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.xdelta, 0.1) - assert_equal(stmt.ydelta, 1.) + assert stmt.units == "inch" + assert stmt.xdelta == 0.1 + assert stmt.ydelta == 1.0 # no effect stmt.to_inch() - assert_equal(stmt.xdelta, 0.1) - assert_equal(stmt.ydelta, 1.) + assert stmt.xdelta == 0.1 + assert stmt.ydelta == 1.0 - line = 'R4X01Y1' - settings.units = 'inch' + line = "R4X01Y1" + settings.units = "inch" stmt = RepeatHoleStmt.from_excellon(line, settings) # no effect stmt.to_inch() - assert_equal(stmt.xdelta, 1.) - assert_equal(stmt.ydelta, 10.) + assert stmt.xdelta == 1.0 + assert stmt.ydelta == 10.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.xdelta, 25.4) - assert_equal(stmt.ydelta, 254.) + assert stmt.units == "metric" + assert stmt.xdelta == 25.4 + assert stmt.ydelta == 254.0 # No effect stmt.to_metric() - assert_equal(stmt.xdelta, 25.4) - assert_equal(stmt.ydelta, 254.) + assert stmt.xdelta == 25.4 + assert stmt.ydelta == 254.0 def test_repeathole_str(): - stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings()) - assert_equal(str(stmt), '<Repeat Hole: 4 times, offset X: 1.5 Y: 32>') + stmt = RepeatHoleStmt.from_excellon("R4X015Y32", FileSettings()) + assert str(stmt) == "<Repeat Hole: 4 times, offset X: 1.5 Y: 32>" def test_commentstmt_factory(): """ Test CommentStmt factory method """ - line = ';Layer_Color=9474304' + line = ";Layer_Color=9474304" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] - line = ';FILE_FORMAT=2:5' + line = ";FILE_FORMAT=2:5" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] - line = ';TYPE=PLATED' + line = ";TYPE=PLATED" stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.comment, line[1:]) + assert stmt.comment == line[1:] def test_commentstmt_dump(): """ Test CommentStmt to_excellon() """ - lines = [';Layer_Color=9474304', ';FILE_FORMAT=2:5', ';TYPE=PLATED', ] + lines = [";Layer_Color=9474304", ";FILE_FORMAT=2:5", ";TYPE=PLATED"] for line in lines: stmt = CommentStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_header_begin_stmt(): stmt = HeaderBeginStmt() - assert_equal(stmt.to_excellon(None), 'M48') + assert stmt.to_excellon(None) == "M48" def test_header_end_stmt(): stmt = HeaderEndStmt() - assert_equal(stmt.to_excellon(None), 'M95') + assert stmt.to_excellon(None) == "M95" def test_rewindstop_stmt(): stmt = RewindStopStmt() - assert_equal(stmt.to_excellon(None), '%') + assert stmt.to_excellon(None) == "%" def test_z_axis_rout_position_stmt(): stmt = ZAxisRoutPositionStmt() - assert_equal(stmt.to_excellon(None), 'M15') + assert stmt.to_excellon(None) == "M15" def test_retract_with_clamping_stmt(): stmt = RetractWithClampingStmt() - assert_equal(stmt.to_excellon(None), 'M16') + assert stmt.to_excellon(None) == "M16" def test_retract_without_clamping_stmt(): stmt = RetractWithoutClampingStmt() - assert_equal(stmt.to_excellon(None), 'M17') + assert stmt.to_excellon(None) == "M17" def test_cutter_compensation_off_stmt(): stmt = CutterCompensationOffStmt() - assert_equal(stmt.to_excellon(None), 'G40') + assert stmt.to_excellon(None) == "G40" def test_cutter_compensation_left_stmt(): stmt = CutterCompensationLeftStmt() - assert_equal(stmt.to_excellon(None), 'G41') + assert stmt.to_excellon(None) == "G41" def test_cutter_compensation_right_stmt(): stmt = CutterCompensationRightStmt() - assert_equal(stmt.to_excellon(None), 'G42') + assert stmt.to_excellon(None) == "G42" def test_endofprogramstmt_factory(): - settings = FileSettings(units='inch') - stmt = EndOfProgramStmt.from_excellon('M30X01Y02', settings) - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 2.) - assert_equal(stmt.units, 'inch') - settings.units = 'metric' - stmt = EndOfProgramStmt.from_excellon('M30X01', settings) - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, None) - assert_equal(stmt.units, 'metric') - stmt = EndOfProgramStmt.from_excellon('M30Y02', FileSettings()) - assert_equal(stmt.x, None) - assert_equal(stmt.y, 2.) + settings = FileSettings(units="inch") + stmt = EndOfProgramStmt.from_excellon("M30X01Y02", settings) + assert stmt.x == 1.0 + assert stmt.y == 2.0 + assert stmt.units == "inch" + settings.units = "metric" + stmt = EndOfProgramStmt.from_excellon("M30X01", settings) + assert stmt.x == 1.0 + assert stmt.y == None + assert stmt.units == "metric" + stmt = EndOfProgramStmt.from_excellon("M30Y02", FileSettings()) + assert stmt.x == None + assert stmt.y == 2.0 def test_endofprogramStmt_dump(): - lines = ['M30X01Y02', ] + lines = ["M30X01Y02"] for line in lines: stmt = EndOfProgramStmt.from_excellon(line, FileSettings()) - assert_equal(stmt.to_excellon(FileSettings()), line) + assert stmt.to_excellon(FileSettings()) == line def test_endofprogramstmt_conversion(): settings = FileSettings() - settings.units = 'metric' - stmt = EndOfProgramStmt.from_excellon('M30X0254Y254', settings) + settings.units = "metric" + stmt = EndOfProgramStmt.from_excellon("M30X0254Y254", settings) # No effect stmt.to_metric() - assert_equal(stmt.x, 2.54) - assert_equal(stmt.y, 25.4) + assert stmt.x == 2.54 + assert stmt.y == 25.4 stmt.to_inch() - assert_equal(stmt.units, 'inch') - assert_equal(stmt.x, 0.1) - assert_equal(stmt.y, 1.0) + assert stmt.units == "inch" + assert stmt.x == 0.1 + assert stmt.y == 1.0 # No effect stmt.to_inch() - assert_equal(stmt.x, 0.1) - assert_equal(stmt.y, 1.0) + assert stmt.x == 0.1 + assert stmt.y == 1.0 - settings.units = 'inch' - stmt = EndOfProgramStmt.from_excellon('M30X01Y1', settings) + settings.units = "inch" + stmt = EndOfProgramStmt.from_excellon("M30X01Y1", settings) # No effect stmt.to_inch() - assert_equal(stmt.x, 1.) - assert_equal(stmt.y, 10.0) + assert stmt.x == 1.0 + assert stmt.y == 10.0 stmt.to_metric() - assert_equal(stmt.units, 'metric') - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 254.) + assert stmt.units == "metric" + assert stmt.x == 25.4 + assert stmt.y == 254.0 # No effect stmt.to_metric() - assert_equal(stmt.x, 25.4) - assert_equal(stmt.y, 254.) + assert stmt.x == 25.4 + assert stmt.y == 254.0 def test_endofprogramstmt_offset(): stmt = EndOfProgramStmt(1, 1) stmt.offset() - assert_equal(stmt.x, 1) - assert_equal(stmt.y, 1) + assert stmt.x == 1 + assert stmt.y == 1 stmt.offset(1, 0) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 1.) + assert stmt.x == 2.0 + assert stmt.y == 1.0 stmt.offset(0, 1) - assert_equal(stmt.x, 2.) - assert_equal(stmt.y, 2.) + assert stmt.x == 2.0 + assert stmt.y == 2.0 def test_unitstmt_factory(): """ Test UnitStmt factory method """ - line = 'INCH,LZ' + line = "INCH,LZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') - assert_equal(stmt.zeros, 'leading') + assert stmt.units == "inch" + assert stmt.zeros == "leading" - line = 'INCH,TZ' + line = "INCH,TZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') - assert_equal(stmt.zeros, 'trailing') + assert stmt.units == "inch" + assert stmt.zeros == "trailing" - line = 'METRIC,LZ' + line = "METRIC,LZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') - assert_equal(stmt.zeros, 'leading') + assert stmt.units == "metric" + assert stmt.zeros == "leading" - line = 'METRIC,TZ' + line = "METRIC,TZ" stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') - assert_equal(stmt.zeros, 'trailing') + assert stmt.units == "metric" + assert stmt.zeros == "trailing" def test_unitstmt_dump(): """ Test UnitStmt to_excellon() """ - lines = ['INCH,LZ', 'INCH,TZ', 'METRIC,LZ', 'METRIC,TZ', ] + lines = ["INCH,LZ", "INCH,TZ", "METRIC,LZ", "METRIC,TZ"] for line in lines: stmt = UnitStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_unitstmt_conversion(): - stmt = UnitStmt.from_excellon('METRIC,TZ') + stmt = UnitStmt.from_excellon("METRIC,TZ") stmt.to_inch() - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" - stmt = UnitStmt.from_excellon('INCH,TZ') + stmt = UnitStmt.from_excellon("INCH,TZ") stmt.to_metric() - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" def test_incrementalmode_factory(): """ Test IncrementalModeStmt factory method """ - line = 'ICI,ON' + line = "ICI,ON" stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.mode, 'on') + assert stmt.mode == "on" - line = 'ICI,OFF' + line = "ICI,OFF" stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.mode, 'off') + assert stmt.mode == "off" def test_incrementalmode_dump(): """ Test IncrementalModeStmt to_excellon() """ - lines = ['ICI,ON', 'ICI,OFF', ] + lines = ["ICI,ON", "ICI,OFF"] for line in lines: stmt = IncrementalModeStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_incrementalmode_validation(): """ Test IncrementalModeStmt input validation """ - assert_raises(ValueError, IncrementalModeStmt, 'OFF-ISH') + pytest.raises(ValueError, IncrementalModeStmt, "OFF-ISH") def test_versionstmt_factory(): """ Test VersionStmt factory method """ - line = 'VER,1' + line = "VER,1" stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.version, 1) + assert stmt.version == 1 - line = 'VER,2' + line = "VER,2" stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.version, 2) + assert stmt.version == 2 def test_versionstmt_dump(): """ Test VersionStmt to_excellon() """ - lines = ['VER,1', 'VER,2', ] + lines = ["VER,1", "VER,2"] for line in lines: stmt = VersionStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_versionstmt_validation(): """ Test VersionStmt input validation """ - assert_raises(ValueError, VersionStmt, 3) + pytest.raises(ValueError, VersionStmt, 3) def test_formatstmt_factory(): """ Test FormatStmt factory method """ - line = 'FMAT,1' + line = "FMAT,1" stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.format, 1) + assert stmt.format == 1 - line = 'FMAT,2' + line = "FMAT,2" stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.format, 2) + assert stmt.format == 2 def test_formatstmt_dump(): """ Test FormatStmt to_excellon() """ - lines = ['FMAT,1', 'FMAT,2', ] + lines = ["FMAT,1", "FMAT,2"] for line in lines: stmt = FormatStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_formatstmt_validation(): """ Test FormatStmt input validation """ - assert_raises(ValueError, FormatStmt, 3) + pytest.raises(ValueError, FormatStmt, 3) def test_linktoolstmt_factory(): """ Test LinkToolStmt factory method """ - line = '1/2/3/4' + line = "1/2/3/4" stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + assert stmt.linked_tools == [1, 2, 3, 4] - line = '01/02/03/04' + line = "01/02/03/04" stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.linked_tools, [1, 2, 3, 4]) + assert stmt.linked_tools == [1, 2, 3, 4] def test_linktoolstmt_dump(): """ Test LinkToolStmt to_excellon() """ - lines = ['1/2/3/4', '5/6/7', ] + lines = ["1/2/3/4", "5/6/7"] for line in lines: stmt = LinkToolStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_measmodestmt_factory(): """ Test MeasuringModeStmt factory method """ - line = 'M72' + line = "M72" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" - line = 'M71' + line = "M71" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" def test_measmodestmt_dump(): """ Test MeasuringModeStmt to_excellon() """ - lines = ['M71', 'M72', ] + lines = ["M71", "M72"] for line in lines: stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.to_excellon(), line) + assert stmt.to_excellon() == line def test_measmodestmt_validation(): """ Test MeasuringModeStmt input validation """ - assert_raises(ValueError, MeasuringModeStmt.from_excellon, 'M70') - assert_raises(ValueError, MeasuringModeStmt, 'millimeters') + pytest.raises(ValueError, MeasuringModeStmt.from_excellon, "M70") + pytest.raises(ValueError, MeasuringModeStmt, "millimeters") def test_measmodestmt_conversion(): - line = 'M72' + line = "M72" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" stmt.to_metric() - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" - line = 'M71' + line = "M71" stmt = MeasuringModeStmt.from_excellon(line) - assert_equal(stmt.units, 'metric') + assert stmt.units == "metric" stmt.to_inch() - assert_equal(stmt.units, 'inch') + assert stmt.units == "inch" def test_routemode_stmt(): stmt = RouteModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G00') + assert stmt.to_excellon(FileSettings()) == "G00" def test_linearmode_stmt(): stmt = LinearModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G01') + assert stmt.to_excellon(FileSettings()) == "G01" def test_drillmode_stmt(): stmt = DrillModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G05') + assert stmt.to_excellon(FileSettings()) == "G05" def test_absolutemode_stmt(): stmt = AbsoluteModeStmt() - assert_equal(stmt.to_excellon(FileSettings()), 'G90') + assert stmt.to_excellon(FileSettings()) == "G90" def test_unknownstmt(): - stmt = UnknownStmt('TEST') - assert_equal(stmt.stmt, 'TEST') - assert_equal(str(stmt), '<Unknown Statement: TEST>') + stmt = UnknownStmt("TEST") + assert stmt.stmt == "TEST" + assert str(stmt) == "<Unknown Statement: TEST>" def test_unknownstmt_dump(): - stmt = UnknownStmt('TEST') - assert_equal(stmt.to_excellon(FileSettings()), 'TEST') + stmt = UnknownStmt("TEST") + assert stmt.to_excellon(FileSettings()) == "TEST" diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index 15f35a1..140cbd1 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -3,414 +3,413 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> -from .tests import * +import pytest from ..gerber_statements import * from ..cam import FileSettings def test_Statement_smoketest(): - stmt = Statement('Test') - assert_equal(stmt.type, 'Test') + stmt = Statement("Test") + assert stmt.type == "Test" stmt.to_metric() - assert_in('units=metric', str(stmt)) + assert "units=metric" in str(stmt) stmt.to_inch() - assert_in('units=inch', str(stmt)) + assert "units=inch" in str(stmt) stmt.to_metric() stmt.offset(1, 1) - assert_in('type=Test', str(stmt)) + assert "type=Test" in str(stmt) def test_FSParamStmt_factory(): """ Test FSParamStruct factory """ - stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} + stmt = {"param": "FS", "zero": "L", "notation": "A", "x": "27"} fs = FSParamStmt.from_dict(stmt) - assert_equal(fs.param, 'FS') - assert_equal(fs.zero_suppression, 'leading') - assert_equal(fs.notation, 'absolute') - assert_equal(fs.format, (2, 7)) + assert fs.param == "FS" + assert fs.zero_suppression == "leading" + assert fs.notation == "absolute" + assert fs.format == (2, 7) - stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '27'} + stmt = {"param": "FS", "zero": "T", "notation": "I", "x": "27"} fs = FSParamStmt.from_dict(stmt) - assert_equal(fs.param, 'FS') - assert_equal(fs.zero_suppression, 'trailing') - assert_equal(fs.notation, 'incremental') - assert_equal(fs.format, (2, 7)) + assert fs.param == "FS" + assert fs.zero_suppression == "trailing" + assert fs.notation == "incremental" + assert fs.format == (2, 7) def test_FSParamStmt(): """ Test FSParamStmt initialization """ - param = 'FS' - zeros = 'trailing' - notation = 'absolute' + param = "FS" + zeros = "trailing" + notation = "absolute" fmt = (2, 5) stmt = FSParamStmt(param, zeros, notation, fmt) - assert_equal(stmt.param, param) - assert_equal(stmt.zero_suppression, zeros) - assert_equal(stmt.notation, notation) - assert_equal(stmt.format, fmt) + assert stmt.param == param + assert stmt.zero_suppression == zeros + assert stmt.notation == notation + assert stmt.format == fmt def test_FSParamStmt_dump(): """ Test FSParamStmt to_gerber() """ - stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} + stmt = {"param": "FS", "zero": "L", "notation": "A", "x": "27"} fs = FSParamStmt.from_dict(stmt) - assert_equal(fs.to_gerber(), '%FSLAX27Y27*%') + assert fs.to_gerber() == "%FSLAX27Y27*%" - stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '25'} + stmt = {"param": "FS", "zero": "T", "notation": "I", "x": "25"} fs = FSParamStmt.from_dict(stmt) - assert_equal(fs.to_gerber(), '%FSTIX25Y25*%') + assert fs.to_gerber() == "%FSTIX25Y25*%" - settings = FileSettings(zero_suppression='leading', notation='absolute') - assert_equal(fs.to_gerber(settings), '%FSLAX25Y25*%') + settings = FileSettings(zero_suppression="leading", notation="absolute") + assert fs.to_gerber(settings) == "%FSLAX25Y25*%" def test_FSParamStmt_string(): """ Test FSParamStmt.__str__() """ - stmt = {'param': 'FS', 'zero': 'L', 'notation': 'A', 'x': '27'} + stmt = {"param": "FS", "zero": "L", "notation": "A", "x": "27"} fs = FSParamStmt.from_dict(stmt) - assert_equal(str(fs), - '<Format Spec: 2:7 leading zero suppression absolute notation>') + assert str(fs) == "<Format Spec: 2:7 leading zero suppression absolute notation>" - stmt = {'param': 'FS', 'zero': 'T', 'notation': 'I', 'x': '25'} + stmt = {"param": "FS", "zero": "T", "notation": "I", "x": "25"} fs = FSParamStmt.from_dict(stmt) - assert_equal(str(fs), - '<Format Spec: 2:5 trailing zero suppression incremental notation>') + assert ( + str(fs) == "<Format Spec: 2:5 trailing zero suppression incremental notation>" + ) def test_MOParamStmt_factory(): """ Test MOParamStruct factory """ - stmts = [{'param': 'MO', 'mo': 'IN'}, {'param': 'MO', 'mo': 'in'}, ] + stmts = [{"param": "MO", "mo": "IN"}, {"param": "MO", "mo": "in"}] for stmt in stmts: mo = MOParamStmt.from_dict(stmt) - assert_equal(mo.param, 'MO') - assert_equal(mo.mode, 'inch') + assert mo.param == "MO" + assert mo.mode == "inch" - stmts = [{'param': 'MO', 'mo': 'MM'}, {'param': 'MO', 'mo': 'mm'}, ] + stmts = [{"param": "MO", "mo": "MM"}, {"param": "MO", "mo": "mm"}] for stmt in stmts: mo = MOParamStmt.from_dict(stmt) - assert_equal(mo.param, 'MO') - assert_equal(mo.mode, 'metric') + assert mo.param == "MO" + assert mo.mode == "metric" - stmt = {'param': 'MO'} + stmt = {"param": "MO"} mo = MOParamStmt.from_dict(stmt) - assert_equal(mo.mode, None) - stmt = {'param': 'MO', 'mo': 'degrees kelvin'} - assert_raises(ValueError, MOParamStmt.from_dict, stmt) + assert mo.mode == None + stmt = {"param": "MO", "mo": "degrees kelvin"} + pytest.raises(ValueError, MOParamStmt.from_dict, stmt) def test_MOParamStmt(): """ Test MOParamStmt initialization """ - param = 'MO' - mode = 'inch' + param = "MO" + mode = "inch" stmt = MOParamStmt(param, mode) - assert_equal(stmt.param, param) + assert stmt.param == param - for mode in ['inch', 'metric']: + for mode in ["inch", "metric"]: stmt = MOParamStmt(param, mode) - assert_equal(stmt.mode, mode) + assert stmt.mode == mode def test_MOParamStmt_dump(): """ Test MOParamStmt to_gerber() """ - stmt = {'param': 'MO', 'mo': 'IN'} + stmt = {"param": "MO", "mo": "IN"} mo = MOParamStmt.from_dict(stmt) - assert_equal(mo.to_gerber(), '%MOIN*%') + assert mo.to_gerber() == "%MOIN*%" - stmt = {'param': 'MO', 'mo': 'MM'} + stmt = {"param": "MO", "mo": "MM"} mo = MOParamStmt.from_dict(stmt) - assert_equal(mo.to_gerber(), '%MOMM*%') + assert mo.to_gerber() == "%MOMM*%" def test_MOParamStmt_conversion(): - stmt = {'param': 'MO', 'mo': 'MM'} + stmt = {"param": "MO", "mo": "MM"} mo = MOParamStmt.from_dict(stmt) mo.to_inch() - assert_equal(mo.mode, 'inch') + assert mo.mode == "inch" - stmt = {'param': 'MO', 'mo': 'IN'} + stmt = {"param": "MO", "mo": "IN"} mo = MOParamStmt.from_dict(stmt) mo.to_metric() - assert_equal(mo.mode, 'metric') + assert mo.mode == "metric" def test_MOParamStmt_string(): """ Test MOParamStmt.__str__() """ - stmt = {'param': 'MO', 'mo': 'IN'} + stmt = {"param": "MO", "mo": "IN"} mo = MOParamStmt.from_dict(stmt) - assert_equal(str(mo), '<Mode: inches>') + assert str(mo) == "<Mode: inches>" - stmt = {'param': 'MO', 'mo': 'MM'} + stmt = {"param": "MO", "mo": "MM"} mo = MOParamStmt.from_dict(stmt) - assert_equal(str(mo), '<Mode: millimeters>') + assert str(mo) == "<Mode: millimeters>" def test_IPParamStmt_factory(): """ Test IPParamStruct factory """ - stmt = {'param': 'IP', 'ip': 'POS'} + stmt = {"param": "IP", "ip": "POS"} ip = IPParamStmt.from_dict(stmt) - assert_equal(ip.ip, 'positive') + assert ip.ip == "positive" - stmt = {'param': 'IP', 'ip': 'NEG'} + stmt = {"param": "IP", "ip": "NEG"} ip = IPParamStmt.from_dict(stmt) - assert_equal(ip.ip, 'negative') + assert ip.ip == "negative" def test_IPParamStmt(): """ Test IPParamStmt initialization """ - param = 'IP' - for ip in ['positive', 'negative']: + param = "IP" + for ip in ["positive", "negative"]: stmt = IPParamStmt(param, ip) - assert_equal(stmt.param, param) - assert_equal(stmt.ip, ip) + assert stmt.param == param + assert stmt.ip == ip def test_IPParamStmt_dump(): """ Test IPParamStmt to_gerber() """ - stmt = {'param': 'IP', 'ip': 'POS'} + stmt = {"param": "IP", "ip": "POS"} ip = IPParamStmt.from_dict(stmt) - assert_equal(ip.to_gerber(), '%IPPOS*%') + assert ip.to_gerber() == "%IPPOS*%" - stmt = {'param': 'IP', 'ip': 'NEG'} + stmt = {"param": "IP", "ip": "NEG"} ip = IPParamStmt.from_dict(stmt) - assert_equal(ip.to_gerber(), '%IPNEG*%') + assert ip.to_gerber() == "%IPNEG*%" def test_IPParamStmt_string(): - stmt = {'param': 'IP', 'ip': 'POS'} + stmt = {"param": "IP", "ip": "POS"} ip = IPParamStmt.from_dict(stmt) - assert_equal(str(ip), '<Image Polarity: positive>') + assert str(ip) == "<Image Polarity: positive>" - stmt = {'param': 'IP', 'ip': 'NEG'} + stmt = {"param": "IP", "ip": "NEG"} ip = IPParamStmt.from_dict(stmt) - assert_equal(str(ip), '<Image Polarity: negative>') + assert str(ip) == "<Image Polarity: negative>" def test_IRParamStmt_factory(): - stmt = {'param': 'IR', 'angle': '45'} + stmt = {"param": "IR", "angle": "45"} ir = IRParamStmt.from_dict(stmt) - assert_equal(ir.param, 'IR') - assert_equal(ir.angle, 45) + assert ir.param == "IR" + assert ir.angle == 45 def test_IRParamStmt_dump(): - stmt = {'param': 'IR', 'angle': '45'} + stmt = {"param": "IR", "angle": "45"} ir = IRParamStmt.from_dict(stmt) - assert_equal(ir.to_gerber(), '%IR45*%') + assert ir.to_gerber() == "%IR45*%" def test_IRParamStmt_string(): - stmt = {'param': 'IR', 'angle': '45'} + stmt = {"param": "IR", "angle": "45"} ir = IRParamStmt.from_dict(stmt) - assert_equal(str(ir), '<Image Angle: 45>') + assert str(ir) == "<Image Angle: 45>" def test_OFParamStmt_factory(): """ Test OFParamStmt factory """ - stmt = {'param': 'OF', 'a': '0.1234567', 'b': '0.1234567'} + stmt = {"param": "OF", "a": "0.1234567", "b": "0.1234567"} of = OFParamStmt.from_dict(stmt) - assert_equal(of.a, 0.1234567) - assert_equal(of.b, 0.1234567) + assert of.a == 0.1234567 + assert of.b == 0.1234567 def test_OFParamStmt(): """ Test IPParamStmt initialization """ - param = 'OF' + param = "OF" for val in [0.0, -3.4567]: stmt = OFParamStmt(param, val, val) - assert_equal(stmt.param, param) - assert_equal(stmt.a, val) - assert_equal(stmt.b, val) + assert stmt.param == param + assert stmt.a == val + assert stmt.b == val def test_OFParamStmt_dump(): """ Test OFParamStmt to_gerber() """ - stmt = {'param': 'OF', 'a': '0.123456', 'b': '0.123456'} + stmt = {"param": "OF", "a": "0.123456", "b": "0.123456"} of = OFParamStmt.from_dict(stmt) - assert_equal(of.to_gerber(), '%OFA0.12345B0.12345*%') + assert of.to_gerber() == "%OFA0.12345B0.12345*%" def test_OFParamStmt_conversion(): - stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} + stmt = {"param": "OF", "a": "2.54", "b": "25.4"} of = OFParamStmt.from_dict(stmt) - of.units = 'metric' + of.units = "metric" # No effect of.to_metric() - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.a == 2.54 + assert of.b == 25.4 of.to_inch() - assert_equal(of.units, 'inch') - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.units == "inch" + assert of.a == 0.1 + assert of.b == 1.0 # No effect of.to_inch() - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.a == 0.1 + assert of.b == 1.0 - stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} + stmt = {"param": "OF", "a": "0.1", "b": "1.0"} of = OFParamStmt.from_dict(stmt) - of.units = 'inch' + of.units = "inch" # No effect of.to_inch() - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.a == 0.1 + assert of.b == 1.0 of.to_metric() - assert_equal(of.units, 'metric') - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.units == "metric" + assert of.a == 2.54 + assert of.b == 25.4 # No effect of.to_metric() - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.a == 2.54 + assert of.b == 25.4 def test_OFParamStmt_offset(): - s = OFParamStmt('OF', 0, 0) + s = OFParamStmt("OF", 0, 0) s.offset(1, 0) - assert_equal(s.a, 1.) - assert_equal(s.b, 0.) + assert s.a == 1.0 + assert s.b == 0.0 s.offset(0, 1) - assert_equal(s.a, 1.) - assert_equal(s.b, 1.) + assert s.a == 1.0 + assert s.b == 1.0 def test_OFParamStmt_string(): """ Test OFParamStmt __str__ """ - stmt = {'param': 'OF', 'a': '0.123456', 'b': '0.123456'} + stmt = {"param": "OF", "a": "0.123456", "b": "0.123456"} of = OFParamStmt.from_dict(stmt) - assert_equal(str(of), '<Offset: X: 0.123456 Y: 0.123456 >') + assert str(of) == "<Offset: X: 0.123456 Y: 0.123456 >" def test_SFParamStmt_factory(): - stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} + stmt = {"param": "SF", "a": "1.4", "b": "0.9"} sf = SFParamStmt.from_dict(stmt) - assert_equal(sf.param, 'SF') - assert_equal(sf.a, 1.4) - assert_equal(sf.b, 0.9) + assert sf.param == "SF" + assert sf.a == 1.4 + assert sf.b == 0.9 def test_SFParamStmt_dump(): - stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} + stmt = {"param": "SF", "a": "1.4", "b": "0.9"} sf = SFParamStmt.from_dict(stmt) - assert_equal(sf.to_gerber(), '%SFA1.4B0.9*%') + assert sf.to_gerber() == "%SFA1.4B0.9*%" def test_SFParamStmt_conversion(): - stmt = {'param': 'OF', 'a': '2.54', 'b': '25.4'} + stmt = {"param": "OF", "a": "2.54", "b": "25.4"} of = SFParamStmt.from_dict(stmt) - of.units = 'metric' + of.units = "metric" of.to_metric() # No effect - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.a == 2.54 + assert of.b == 25.4 of.to_inch() - assert_equal(of.units, 'inch') - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.units == "inch" + assert of.a == 0.1 + assert of.b == 1.0 # No effect of.to_inch() - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.a == 0.1 + assert of.b == 1.0 - stmt = {'param': 'OF', 'a': '0.1', 'b': '1.0'} + stmt = {"param": "OF", "a": "0.1", "b": "1.0"} of = SFParamStmt.from_dict(stmt) - of.units = 'inch' + of.units = "inch" # No effect of.to_inch() - assert_equal(of.a, 0.1) - assert_equal(of.b, 1.0) + assert of.a == 0.1 + assert of.b == 1.0 of.to_metric() - assert_equal(of.units, 'metric') - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.units == "metric" + assert of.a == 2.54 + assert of.b == 25.4 # No effect of.to_metric() - assert_equal(of.a, 2.54) - assert_equal(of.b, 25.4) + assert of.a == 2.54 + assert of.b == 25.4 def test_SFParamStmt_offset(): - s = SFParamStmt('OF', 0, 0) + s = SFParamStmt("OF", 0, 0) s.offset(1, 0) - assert_equal(s.a, 1.) - assert_equal(s.b, 0.) + assert s.a == 1.0 + assert s.b == 0.0 s.offset(0, 1) - assert_equal(s.a, 1.) - assert_equal(s.b, 1.) + assert s.a == 1.0 + assert s.b == 1.0 def test_SFParamStmt_string(): - stmt = {'param': 'SF', 'a': '1.4', 'b': '0.9'} + stmt = {"param": "SF", "a": "1.4", "b": "0.9"} sf = SFParamStmt.from_dict(stmt) - assert_equal(str(sf), '<Scale Factor: X: 1.4 Y: 0.9>') + assert str(sf) == "<Scale Factor: X: 1.4 Y: 0.9>" def test_LPParamStmt_factory(): """ Test LPParamStmt factory """ - stmt = {'param': 'LP', 'lp': 'C'} + stmt = {"param": "LP", "lp": "C"} lp = LPParamStmt.from_dict(stmt) - assert_equal(lp.lp, 'clear') + assert lp.lp == "clear" - stmt = {'param': 'LP', 'lp': 'D'} + stmt = {"param": "LP", "lp": "D"} lp = LPParamStmt.from_dict(stmt) - assert_equal(lp.lp, 'dark') + assert lp.lp == "dark" def test_LPParamStmt_dump(): """ Test LPParamStmt to_gerber() """ - stmt = {'param': 'LP', 'lp': 'C'} + stmt = {"param": "LP", "lp": "C"} lp = LPParamStmt.from_dict(stmt) - assert_equal(lp.to_gerber(), '%LPC*%') + assert lp.to_gerber() == "%LPC*%" - stmt = {'param': 'LP', 'lp': 'D'} + stmt = {"param": "LP", "lp": "D"} lp = LPParamStmt.from_dict(stmt) - assert_equal(lp.to_gerber(), '%LPD*%') + assert lp.to_gerber() == "%LPD*%" def test_LPParamStmt_string(): """ Test LPParamStmt.__str__() """ - stmt = {'param': 'LP', 'lp': 'D'} + stmt = {"param": "LP", "lp": "D"} lp = LPParamStmt.from_dict(stmt) - assert_equal(str(lp), '<Level Polarity: dark>') + assert str(lp) == "<Level Polarity: dark>" - stmt = {'param': 'LP', 'lp': 'C'} + stmt = {"param": "LP", "lp": "C"} lp = LPParamStmt.from_dict(stmt) - assert_equal(str(lp), '<Level Polarity: clear>') + assert str(lp) == "<Level Polarity: clear>" def test_AMParamStmt_factory(): - name = 'DONUTVAR' - macro = ( -'''0 Test Macro. * + name = "DONUTVAR" + macro = """0 Test Macro. * 1,1,1.5,0,0* 20,1,0.9,0,0.45,12,0.45,0* 21,1,6.8,1.2,3.4,0.6,0* @@ -420,533 +419,541 @@ def test_AMParamStmt_factory(): 6,0,0,5,0.5,0.5,2,0.1,6,0* 7,0,0,7,6,0.2,0* 8,THIS IS AN UNSUPPORTED PRIMITIVE* -''') - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) +""" + s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}) s.build() - assert_equal(len(s.primitives), 10) - assert_true(isinstance(s.primitives[0], AMCommentPrimitive)) - assert_true(isinstance(s.primitives[1], AMCirclePrimitive)) - assert_true(isinstance(s.primitives[2], AMVectorLinePrimitive)) - assert_true(isinstance(s.primitives[3], AMCenterLinePrimitive)) - assert_true(isinstance(s.primitives[4], AMLowerLeftLinePrimitive)) - assert_true(isinstance(s.primitives[5], AMOutlinePrimitive)) - assert_true(isinstance(s.primitives[6], AMPolygonPrimitive)) - assert_true(isinstance(s.primitives[7], AMMoirePrimitive)) - assert_true(isinstance(s.primitives[8], AMThermalPrimitive)) - assert_true(isinstance(s.primitives[9], AMUnsupportPrimitive)) + assert len(s.primitives) == 10 + assert isinstance(s.primitives[0], AMCommentPrimitive) + assert isinstance(s.primitives[1], AMCirclePrimitive) + assert isinstance(s.primitives[2], AMVectorLinePrimitive) + assert isinstance(s.primitives[3], AMCenterLinePrimitive) + assert isinstance(s.primitives[4], AMLowerLeftLinePrimitive) + assert isinstance(s.primitives[5], AMOutlinePrimitive) + assert isinstance(s.primitives[6], AMPolygonPrimitive) + assert isinstance(s.primitives[7], AMMoirePrimitive) + assert isinstance(s.primitives[8], AMThermalPrimitive) + assert isinstance(s.primitives[9], AMUnsupportPrimitive) def testAMParamStmt_conversion(): - name = 'POLYGON' - macro = '5,1,8,25.4,25.4,25.4,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) + name = "POLYGON" + macro = "5,1,8,25.4,25.4,25.4,0*" + s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}) s.build() - s.units = 'metric' + s.units = "metric" # No effect s.to_metric() - assert_equal(s.primitives[0].position, (25.4, 25.4)) - assert_equal(s.primitives[0].diameter, 25.4) + assert s.primitives[0].position == (25.4, 25.4) + assert s.primitives[0].diameter == 25.4 s.to_inch() - assert_equal(s.units, 'inch') - assert_equal(s.primitives[0].position, (1., 1.)) - assert_equal(s.primitives[0].diameter, 1.) + assert s.units == "inch" + assert s.primitives[0].position == (1.0, 1.0) + assert s.primitives[0].diameter == 1.0 # No effect s.to_inch() - assert_equal(s.primitives[0].position, (1., 1.)) - assert_equal(s.primitives[0].diameter, 1.) + assert s.primitives[0].position == (1.0, 1.0) + assert s.primitives[0].diameter == 1.0 - macro = '5,1,8,1,1,1,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) + macro = "5,1,8,1,1,1,0*" + s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}) s.build() - s.units = 'inch' + s.units = "inch" # No effect s.to_inch() - assert_equal(s.primitives[0].position, (1., 1.)) - assert_equal(s.primitives[0].diameter, 1.) + assert s.primitives[0].position == (1.0, 1.0) + assert s.primitives[0].diameter == 1.0 s.to_metric() - assert_equal(s.units, 'metric') - assert_equal(s.primitives[0].position, (25.4, 25.4)) - assert_equal(s.primitives[0].diameter, 25.4) + assert s.units == "metric" + assert s.primitives[0].position == (25.4, 25.4) + assert s.primitives[0].diameter == 25.4 # No effect s.to_metric() - assert_equal(s.primitives[0].position, (25.4, 25.4)) - assert_equal(s.primitives[0].diameter, 25.4) + assert s.primitives[0].position == (25.4, 25.4) + assert s.primitives[0].diameter == 25.4 def test_AMParamStmt_dump(): - name = 'POLYGON' - macro = '5,1,8,25.4,25.4,25.4,0.0' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) + name = "POLYGON" + macro = "5,1,8,25.4,25.4,25.4,0.0" + s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}) s.build() - assert_equal(s.to_gerber(), '%AMPOLYGON*5,1,8,25.4,25.4,25.4,0.0*%') + assert s.to_gerber() == "%AMPOLYGON*5,1,8,25.4,25.4,25.4,0.0*%" - #TODO - Store Equations and update on unit change... - s = AMParamStmt.from_dict({'param': 'AM', 'name': 'OC8', 'macro': '5,1,8,0,0,1.08239X$1,22.5'}) + # TODO - Store Equations and update on unit change... + s = AMParamStmt.from_dict( + {"param": "AM", "name": "OC8", "macro": "5,1,8,0,0,1.08239X$1,22.5"} + ) s.build() - #assert_equal(s.to_gerber(), '%AMOC8*5,1,8,0,0,1.08239X$1,22.5*%') - assert_equal(s.to_gerber(), '%AMOC8*5,1,8,0,0,0,22.5*%') + # assert_equal(s.to_gerber(), '%AMOC8*5,1,8,0,0,1.08239X$1,22.5*%') + assert s.to_gerber() == "%AMOC8*5,1,8,0,0,0,22.5*%" def test_AMParamStmt_string(): - name = 'POLYGON' - macro = '5,1,8,25.4,25.4,25.4,0*' - s = AMParamStmt.from_dict({'param': 'AM', 'name': name, 'macro': macro}) + name = "POLYGON" + macro = "5,1,8,25.4,25.4,25.4,0*" + s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}) s.build() - assert_equal(str(s), '<Aperture Macro POLYGON: 5,1,8,25.4,25.4,25.4,0*>') + assert str(s) == "<Aperture Macro POLYGON: 5,1,8,25.4,25.4,25.4,0*>" def test_ASParamStmt_factory(): - stmt = {'param': 'AS', 'mode': 'AXBY'} + stmt = {"param": "AS", "mode": "AXBY"} s = ASParamStmt.from_dict(stmt) - assert_equal(s.param, 'AS') - assert_equal(s.mode, 'AXBY') + assert s.param == "AS" + assert s.mode == "AXBY" def test_ASParamStmt_dump(): - stmt = {'param': 'AS', 'mode': 'AXBY'} + stmt = {"param": "AS", "mode": "AXBY"} s = ASParamStmt.from_dict(stmt) - assert_equal(s.to_gerber(), '%ASAXBY*%') + assert s.to_gerber() == "%ASAXBY*%" def test_ASParamStmt_string(): - stmt = {'param': 'AS', 'mode': 'AXBY'} + stmt = {"param": "AS", "mode": "AXBY"} s = ASParamStmt.from_dict(stmt) - assert_equal(str(s), '<Axis Select: AXBY>') + assert str(s) == "<Axis Select: AXBY>" def test_INParamStmt_factory(): """ Test INParamStmt factory """ - stmt = {'param': 'IN', 'name': 'test'} + stmt = {"param": "IN", "name": "test"} inp = INParamStmt.from_dict(stmt) - assert_equal(inp.name, 'test') + assert inp.name == "test" def test_INParamStmt_dump(): """ Test INParamStmt to_gerber() """ - stmt = {'param': 'IN', 'name': 'test'} + stmt = {"param": "IN", "name": "test"} inp = INParamStmt.from_dict(stmt) - assert_equal(inp.to_gerber(), '%INtest*%') + assert inp.to_gerber() == "%INtest*%" def test_INParamStmt_string(): - stmt = {'param': 'IN', 'name': 'test'} + stmt = {"param": "IN", "name": "test"} inp = INParamStmt.from_dict(stmt) - assert_equal(str(inp), '<Image Name: test>') + assert str(inp) == "<Image Name: test>" def test_LNParamStmt_factory(): """ Test LNParamStmt factory """ - stmt = {'param': 'LN', 'name': 'test'} + stmt = {"param": "LN", "name": "test"} lnp = LNParamStmt.from_dict(stmt) - assert_equal(lnp.name, 'test') + assert lnp.name == "test" def test_LNParamStmt_dump(): """ Test LNParamStmt to_gerber() """ - stmt = {'param': 'LN', 'name': 'test'} + stmt = {"param": "LN", "name": "test"} lnp = LNParamStmt.from_dict(stmt) - assert_equal(lnp.to_gerber(), '%LNtest*%') + assert lnp.to_gerber() == "%LNtest*%" def test_LNParamStmt_string(): - stmt = {'param': 'LN', 'name': 'test'} + stmt = {"param": "LN", "name": "test"} lnp = LNParamStmt.from_dict(stmt) - assert_equal(str(lnp), '<Level Name: test>') + assert str(lnp) == "<Level Name: test>" def test_comment_stmt(): """ Test comment statement """ - stmt = CommentStmt('A comment') - assert_equal(stmt.type, 'COMMENT') - assert_equal(stmt.comment, 'A comment') + stmt = CommentStmt("A comment") + assert stmt.type == "COMMENT" + assert stmt.comment == "A comment" def test_comment_stmt_dump(): """ Test CommentStmt to_gerber() """ - stmt = CommentStmt('A comment') - assert_equal(stmt.to_gerber(), 'G04A comment*') + stmt = CommentStmt("A comment") + assert stmt.to_gerber() == "G04A comment*" def test_comment_stmt_string(): - stmt = CommentStmt('A comment') - assert_equal(str(stmt), '<Comment: A comment>') + stmt = CommentStmt("A comment") + assert str(stmt) == "<Comment: A comment>" def test_eofstmt(): """ Test EofStmt """ stmt = EofStmt() - assert_equal(stmt.type, 'EOF') + assert stmt.type == "EOF" def test_eofstmt_dump(): """ Test EofStmt to_gerber() """ stmt = EofStmt() - assert_equal(stmt.to_gerber(), 'M02*') + assert stmt.to_gerber() == "M02*" def test_eofstmt_string(): - assert_equal(str(EofStmt()), '<EOF Statement>') + assert str(EofStmt()) == "<EOF Statement>" def test_quadmodestmt_factory(): """ Test QuadrantModeStmt.from_gerber() """ - line = 'G74*' + line = "G74*" stmt = QuadrantModeStmt.from_gerber(line) - assert_equal(stmt.type, 'QuadrantMode') - assert_equal(stmt.mode, 'single-quadrant') + assert stmt.type == "QuadrantMode" + assert stmt.mode == "single-quadrant" - line = 'G75*' + line = "G75*" stmt = QuadrantModeStmt.from_gerber(line) - assert_equal(stmt.mode, 'multi-quadrant') + assert stmt.mode == "multi-quadrant" def test_quadmodestmt_validation(): """ Test QuadrantModeStmt input validation """ - line = 'G76*' - assert_raises(ValueError, QuadrantModeStmt.from_gerber, line) - assert_raises(ValueError, QuadrantModeStmt, 'quadrant-ful') + line = "G76*" + pytest.raises(ValueError, QuadrantModeStmt.from_gerber, line) + pytest.raises(ValueError, QuadrantModeStmt, "quadrant-ful") def test_quadmodestmt_dump(): """ Test QuadrantModeStmt.to_gerber() """ - for line in ('G74*', 'G75*',): + for line in ("G74*", "G75*"): stmt = QuadrantModeStmt.from_gerber(line) - assert_equal(stmt.to_gerber(), line) + assert stmt.to_gerber() == line def test_regionmodestmt_factory(): """ Test RegionModeStmt.from_gerber() """ - line = 'G36*' + line = "G36*" stmt = RegionModeStmt.from_gerber(line) - assert_equal(stmt.type, 'RegionMode') - assert_equal(stmt.mode, 'on') + assert stmt.type == "RegionMode" + assert stmt.mode == "on" - line = 'G37*' + line = "G37*" stmt = RegionModeStmt.from_gerber(line) - assert_equal(stmt.mode, 'off') + assert stmt.mode == "off" def test_regionmodestmt_validation(): """ Test RegionModeStmt input validation """ - line = 'G38*' - assert_raises(ValueError, RegionModeStmt.from_gerber, line) - assert_raises(ValueError, RegionModeStmt, 'off-ish') + line = "G38*" + pytest.raises(ValueError, RegionModeStmt.from_gerber, line) + pytest.raises(ValueError, RegionModeStmt, "off-ish") def test_regionmodestmt_dump(): """ Test RegionModeStmt.to_gerber() """ - for line in ('G36*', 'G37*',): + for line in ("G36*", "G37*"): stmt = RegionModeStmt.from_gerber(line) - assert_equal(stmt.to_gerber(), line) + assert stmt.to_gerber() == line def test_unknownstmt(): """ Test UnknownStmt """ - line = 'G696969*' + line = "G696969*" stmt = UnknownStmt(line) - assert_equal(stmt.type, 'UNKNOWN') - assert_equal(stmt.line, line) + assert stmt.type == "UNKNOWN" + assert stmt.line == line def test_unknownstmt_dump(): """ Test UnknownStmt.to_gerber() """ - lines = ('G696969*', 'M03*',) + lines = ("G696969*", "M03*") for line in lines: stmt = UnknownStmt(line) - assert_equal(stmt.to_gerber(), line) + assert stmt.to_gerber() == line def test_statement_string(): """ Test Statement.__str__() """ - stmt = Statement('PARAM') - assert_in('type=PARAM', str(stmt)) - stmt.test = 'PASS' - assert_in('test=PASS', str(stmt)) - assert_in('type=PARAM', str(stmt)) + stmt = Statement("PARAM") + assert "type=PARAM" in str(stmt) + stmt.test = "PASS" + assert "test=PASS" in str(stmt) + assert "type=PARAM" in str(stmt) def test_ADParamStmt_factory(): """ Test ADParamStmt factory """ - stmt = {'param': 'AD', 'd': 0, 'shape': 'C'} + stmt = {"param": "AD", "d": 0, "shape": "C"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.d, 0) - assert_equal(ad.shape, 'C') + assert ad.d == 0 + assert ad.shape == "C" - stmt = {'param': 'AD', 'd': 1, 'shape': 'R'} + stmt = {"param": "AD", "d": 1, "shape": "R"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.d, 1) - assert_equal(ad.shape, 'R') + assert ad.d == 1 + assert ad.shape == "R" - stmt = {'param': 'AD', 'd': 1, 'shape': 'C', "modifiers": "1.42"} + stmt = {"param": "AD", "d": 1, "shape": "C", "modifiers": "1.42"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.d, 1) - assert_equal(ad.shape, 'C') - assert_equal(ad.modifiers, [(1.42,)]) + assert ad.d == 1 + assert ad.shape == "C" + assert ad.modifiers == [(1.42,)] - stmt = {'param': 'AD', 'd': 1, 'shape': 'C', "modifiers": "1.42X"} + stmt = {"param": "AD", "d": 1, "shape": "C", "modifiers": "1.42X"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.d, 1) - assert_equal(ad.shape, 'C') - assert_equal(ad.modifiers, [(1.42,)]) + assert ad.d == 1 + assert ad.shape == "C" + assert ad.modifiers == [(1.42,)] - stmt = {'param': 'AD', 'd': 1, 'shape': 'R', "modifiers": "1.42X1.24"} + stmt = {"param": "AD", "d": 1, "shape": "R", "modifiers": "1.42X1.24"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.d, 1) - assert_equal(ad.shape, 'R') - assert_equal(ad.modifiers, [(1.42, 1.24)]) + assert ad.d == 1 + assert ad.shape == "R" + assert ad.modifiers == [(1.42, 1.24)] def test_ADParamStmt_conversion(): - stmt = {'param': 'AD', 'd': 0, 'shape': 'C', - 'modifiers': '25.4X25.4,25.4X25.4'} + stmt = {"param": "AD", "d": 0, "shape": "C", "modifiers": "25.4X25.4,25.4X25.4"} ad = ADParamStmt.from_dict(stmt) - ad.units = 'metric' + ad.units = "metric" # No effect ad.to_metric() - assert_equal(ad.modifiers[0], (25.4, 25.4)) - assert_equal(ad.modifiers[1], (25.4, 25.4)) + assert ad.modifiers[0] == (25.4, 25.4) + assert ad.modifiers[1] == (25.4, 25.4) ad.to_inch() - assert_equal(ad.units, 'inch') - assert_equal(ad.modifiers[0], (1., 1.)) - assert_equal(ad.modifiers[1], (1., 1.)) + assert ad.units == "inch" + assert ad.modifiers[0] == (1.0, 1.0) + assert ad.modifiers[1] == (1.0, 1.0) # No effect ad.to_inch() - assert_equal(ad.modifiers[0], (1., 1.)) - assert_equal(ad.modifiers[1], (1., 1.)) + assert ad.modifiers[0] == (1.0, 1.0) + assert ad.modifiers[1] == (1.0, 1.0) - stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '1X1,1X1'} + stmt = {"param": "AD", "d": 0, "shape": "C", "modifiers": "1X1,1X1"} ad = ADParamStmt.from_dict(stmt) - ad.units = 'inch' + ad.units = "inch" # No effect ad.to_inch() - assert_equal(ad.modifiers[0], (1., 1.)) - assert_equal(ad.modifiers[1], (1., 1.)) + assert ad.modifiers[0] == (1.0, 1.0) + assert ad.modifiers[1] == (1.0, 1.0) ad.to_metric() - assert_equal(ad.modifiers[0], (25.4, 25.4)) - assert_equal(ad.modifiers[1], (25.4, 25.4)) + assert ad.modifiers[0] == (25.4, 25.4) + assert ad.modifiers[1] == (25.4, 25.4) # No effect ad.to_metric() - assert_equal(ad.modifiers[0], (25.4, 25.4)) - assert_equal(ad.modifiers[1], (25.4, 25.4)) + assert ad.modifiers[0] == (25.4, 25.4) + assert ad.modifiers[1] == (25.4, 25.4) def test_ADParamStmt_dump(): - stmt = {'param': 'AD', 'd': 0, 'shape': 'C'} + stmt = {"param": "AD", "d": 0, "shape": "C"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.to_gerber(), '%ADD0C*%') - stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '1X1,1X1'} + assert ad.to_gerber() == "%ADD0C*%" + stmt = {"param": "AD", "d": 0, "shape": "C", "modifiers": "1X1,1X1"} ad = ADParamStmt.from_dict(stmt) - assert_equal(ad.to_gerber(), '%ADD0C,1X1,1X1*%') + assert ad.to_gerber() == "%ADD0C,1X1,1X1*%" def test_ADPamramStmt_string(): - stmt = {'param': 'AD', 'd': 0, 'shape': 'C'} + stmt = {"param": "AD", "d": 0, "shape": "C"} ad = ADParamStmt.from_dict(stmt) - assert_equal(str(ad), '<Aperture Definition: 0: circle>') + assert str(ad) == "<Aperture Definition: 0: circle>" - stmt = {'param': 'AD', 'd': 0, 'shape': 'R'} + stmt = {"param": "AD", "d": 0, "shape": "R"} ad = ADParamStmt.from_dict(stmt) - assert_equal(str(ad), '<Aperture Definition: 0: rectangle>') + assert str(ad) == "<Aperture Definition: 0: rectangle>" - stmt = {'param': 'AD', 'd': 0, 'shape': 'O'} + stmt = {"param": "AD", "d": 0, "shape": "O"} ad = ADParamStmt.from_dict(stmt) - assert_equal(str(ad), '<Aperture Definition: 0: obround>') + assert str(ad) == "<Aperture Definition: 0: obround>" - stmt = {'param': 'AD', 'd': 0, 'shape': 'test'} + stmt = {"param": "AD", "d": 0, "shape": "test"} ad = ADParamStmt.from_dict(stmt) - assert_equal(str(ad), '<Aperture Definition: 0: test>') + assert str(ad) == "<Aperture Definition: 0: test>" def test_MIParamStmt_factory(): - stmt = {'param': 'MI', 'a': 1, 'b': 1} + stmt = {"param": "MI", "a": 1, "b": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(mi.a, 1) - assert_equal(mi.b, 1) + assert mi.a == 1 + assert mi.b == 1 def test_MIParamStmt_dump(): - stmt = {'param': 'MI', 'a': 1, 'b': 1} + stmt = {"param": "MI", "a": 1, "b": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(mi.to_gerber(), '%MIA1B1*%') - stmt = {'param': 'MI', 'a': 1} + assert mi.to_gerber() == "%MIA1B1*%" + stmt = {"param": "MI", "a": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(mi.to_gerber(), '%MIA1B0*%') - stmt = {'param': 'MI', 'b': 1} + assert mi.to_gerber() == "%MIA1B0*%" + stmt = {"param": "MI", "b": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(mi.to_gerber(), '%MIA0B1*%') + assert mi.to_gerber() == "%MIA0B1*%" def test_MIParamStmt_string(): - stmt = {'param': 'MI', 'a': 1, 'b': 1} + stmt = {"param": "MI", "a": 1, "b": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(str(mi), '<Image Mirror: A=1 B=1>') + assert str(mi) == "<Image Mirror: A=1 B=1>" - stmt = {'param': 'MI', 'b': 1} + stmt = {"param": "MI", "b": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(str(mi), '<Image Mirror: A=0 B=1>') + assert str(mi) == "<Image Mirror: A=0 B=1>" - stmt = {'param': 'MI', 'a': 1} + stmt = {"param": "MI", "a": 1} mi = MIParamStmt.from_dict(stmt) - assert_equal(str(mi), '<Image Mirror: A=1 B=0>') + assert str(mi) == "<Image Mirror: A=1 B=0>" def test_coordstmt_ctor(): - cs = CoordStmt('G04', 0.0, 0.1, 0.2, 0.3, 'D01', FileSettings()) - assert_equal(cs.function, 'G04') - assert_equal(cs.x, 0.0) - assert_equal(cs.y, 0.1) - assert_equal(cs.i, 0.2) - assert_equal(cs.j, 0.3) - assert_equal(cs.op, 'D01') + cs = CoordStmt("G04", 0.0, 0.1, 0.2, 0.3, "D01", FileSettings()) + assert cs.function == "G04" + assert cs.x == 0.0 + assert cs.y == 0.1 + assert cs.i == 0.2 + assert cs.j == 0.3 + assert cs.op == "D01" def test_coordstmt_factory(): - stmt = {'function': 'G04', 'x': '0', 'y': '001', - 'i': '002', 'j': '003', 'op': 'D01'} + stmt = { + "function": "G04", + "x": "0", + "y": "001", + "i": "002", + "j": "003", + "op": "D01", + } cs = CoordStmt.from_dict(stmt, FileSettings()) - assert_equal(cs.function, 'G04') - assert_equal(cs.x, 0.0) - assert_equal(cs.y, 0.1) - assert_equal(cs.i, 0.2) - assert_equal(cs.j, 0.3) - assert_equal(cs.op, 'D01') + assert cs.function == "G04" + assert cs.x == 0.0 + assert cs.y == 0.1 + assert cs.i == 0.2 + assert cs.j == 0.3 + assert cs.op == "D01" def test_coordstmt_dump(): - cs = CoordStmt('G04', 0.0, 0.1, 0.2, 0.3, 'D01', FileSettings()) - assert_equal(cs.to_gerber(FileSettings()), 'G04X0Y001I002J003D01*') + cs = CoordStmt("G04", 0.0, 0.1, 0.2, 0.3, "D01", FileSettings()) + assert cs.to_gerber(FileSettings()) == "G04X0Y001I002J003D01*" def test_coordstmt_conversion(): - cs = CoordStmt('G71', 25.4, 25.4, 25.4, 25.4, 'D01', FileSettings()) - cs.units = 'metric' + cs = CoordStmt("G71", 25.4, 25.4, 25.4, 25.4, "D01", FileSettings()) + cs.units = "metric" # No effect cs.to_metric() - assert_equal(cs.x, 25.4) - assert_equal(cs.y, 25.4) - assert_equal(cs.i, 25.4) - assert_equal(cs.j, 25.4) - assert_equal(cs.function, 'G71') + assert cs.x == 25.4 + assert cs.y == 25.4 + assert cs.i == 25.4 + assert cs.j == 25.4 + assert cs.function == "G71" cs.to_inch() - assert_equal(cs.units, 'inch') - assert_equal(cs.x, 1.) - assert_equal(cs.y, 1.) - assert_equal(cs.i, 1.) - assert_equal(cs.j, 1.) - assert_equal(cs.function, 'G70') + assert cs.units == "inch" + assert cs.x == 1.0 + assert cs.y == 1.0 + assert cs.i == 1.0 + assert cs.j == 1.0 + assert cs.function == "G70" # No effect cs.to_inch() - assert_equal(cs.x, 1.) - assert_equal(cs.y, 1.) - assert_equal(cs.i, 1.) - assert_equal(cs.j, 1.) - assert_equal(cs.function, 'G70') + assert cs.x == 1.0 + assert cs.y == 1.0 + assert cs.i == 1.0 + assert cs.j == 1.0 + assert cs.function == "G70" - cs = CoordStmt('G70', 1., 1., 1., 1., 'D01', FileSettings()) - cs.units = 'inch' + cs = CoordStmt("G70", 1.0, 1.0, 1.0, 1.0, "D01", FileSettings()) + cs.units = "inch" # No effect cs.to_inch() - assert_equal(cs.x, 1.) - assert_equal(cs.y, 1.) - assert_equal(cs.i, 1.) - assert_equal(cs.j, 1.) - assert_equal(cs.function, 'G70') + assert cs.x == 1.0 + assert cs.y == 1.0 + assert cs.i == 1.0 + assert cs.j == 1.0 + assert cs.function == "G70" cs.to_metric() - assert_equal(cs.x, 25.4) - assert_equal(cs.y, 25.4) - assert_equal(cs.i, 25.4) - assert_equal(cs.j, 25.4) - assert_equal(cs.function, 'G71') + assert cs.x == 25.4 + assert cs.y == 25.4 + assert cs.i == 25.4 + assert cs.j == 25.4 + assert cs.function == "G71" # No effect cs.to_metric() - assert_equal(cs.x, 25.4) - assert_equal(cs.y, 25.4) - assert_equal(cs.i, 25.4) - assert_equal(cs.j, 25.4) - assert_equal(cs.function, 'G71') + assert cs.x == 25.4 + assert cs.y == 25.4 + assert cs.i == 25.4 + assert cs.j == 25.4 + assert cs.function == "G71" def test_coordstmt_offset(): - c = CoordStmt('G71', 0, 0, 0, 0, 'D01', FileSettings()) + c = CoordStmt("G71", 0, 0, 0, 0, "D01", FileSettings()) c.offset(1, 0) - assert_equal(c.x, 1.) - assert_equal(c.y, 0.) - assert_equal(c.i, 1.) - assert_equal(c.j, 0.) + assert c.x == 1.0 + assert c.y == 0.0 + assert c.i == 1.0 + assert c.j == 0.0 c.offset(0, 1) - assert_equal(c.x, 1.) - assert_equal(c.y, 1.) - assert_equal(c.i, 1.) - assert_equal(c.j, 1.) + assert c.x == 1.0 + assert c.y == 1.0 + assert c.i == 1.0 + assert c.j == 1.0 def test_coordstmt_string(): - cs = CoordStmt('G04', 0, 1, 2, 3, 'D01', FileSettings()) - assert_equal(str(cs), - '<Coordinate Statement: Fn: G04 X: 0 Y: 1 I: 2 J: 3 Op: Lights On>') - cs = CoordStmt('G04', None, None, None, None, 'D02', FileSettings()) - assert_equal(str(cs), '<Coordinate Statement: Fn: G04 Op: Lights Off>') - cs = CoordStmt('G04', None, None, None, None, 'D03', FileSettings()) - assert_equal(str(cs), '<Coordinate Statement: Fn: G04 Op: Flash>') - cs = CoordStmt('G04', None, None, None, None, 'TEST', FileSettings()) - assert_equal(str(cs), '<Coordinate Statement: Fn: G04 Op: TEST>') + cs = CoordStmt("G04", 0, 1, 2, 3, "D01", FileSettings()) + assert ( + str(cs) == "<Coordinate Statement: Fn: G04 X: 0 Y: 1 I: 2 J: 3 Op: Lights On>" + ) + cs = CoordStmt("G04", None, None, None, None, "D02", FileSettings()) + assert str(cs) == "<Coordinate Statement: Fn: G04 Op: Lights Off>" + cs = CoordStmt("G04", None, None, None, None, "D03", FileSettings()) + assert str(cs) == "<Coordinate Statement: Fn: G04 Op: Flash>" + cs = CoordStmt("G04", None, None, None, None, "TEST", FileSettings()) + assert str(cs) == "<Coordinate Statement: Fn: G04 Op: TEST>" def test_aperturestmt_ctor(): ast = ApertureStmt(3, False) - assert_equal(ast.d, 3) - assert_equal(ast.deprecated, False) + assert ast.d == 3 + assert ast.deprecated == False ast = ApertureStmt(4, True) - assert_equal(ast.d, 4) - assert_equal(ast.deprecated, True) + assert ast.d == 4 + assert ast.deprecated == True ast = ApertureStmt(4, 1) - assert_equal(ast.d, 4) - assert_equal(ast.deprecated, True) + assert ast.d == 4 + assert ast.deprecated == True ast = ApertureStmt(3) - assert_equal(ast.d, 3) - assert_equal(ast.deprecated, False) + assert ast.d == 3 + assert ast.deprecated == False def test_aperturestmt_dump(): ast = ApertureStmt(3, False) - assert_equal(ast.to_gerber(), 'D3*') + assert ast.to_gerber() == "D3*" ast = ApertureStmt(3, True) - assert_equal(ast.to_gerber(), 'G54D3*') - assert_equal(str(ast), '<Aperture: 3>') + assert ast.to_gerber() == "G54D3*" + assert str(ast) == "<Aperture: 3>" diff --git a/gerber/tests/test_ipc356.py b/gerber/tests/test_ipc356.py index ae2772a..77f0782 100644 --- a/gerber/tests/test_ipc356.py +++ b/gerber/tests/test_ipc356.py @@ -2,139 +2,147 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe <ham@hamiltonkib.be> +import pytest 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') +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)) - + assert isinstance(ipcfile, IPCNetlist) 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(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)}) + 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_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), '<IPC-D-356 Comment: Layer Stackup:>') + 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_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), '<IPC-D-356 Parameter: VER=IPC-D-356A>') + 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_equal(e.to_netlist(), '999') - assert_equal(str(e), '<IPC-D-356 EOF>') + assert e.to_netlist() == "999" + assert str(e) == "<IPC-D-356 EOF>" def test_outline(): - type = 'BOARD_EDGE' - points = [(0.01, 0.01), (2., 2.), (4., 2.), (4., 6.)] + 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_equal(b.type, type) - assert_equal(b.points, points) - 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) + 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(): - 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, '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), '<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_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, '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) - 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') - 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, '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) + 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" + + 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/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 diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index b932297..ad5b34f 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -2,467 +2,478 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe <ham@hamiltonkib.be> -from operator import add +import pytest +from operator import add from ..primitives import * -from .tests import * def test_primitive_smoketest(): p = Primitive() try: p.bounding_box - assert_false(True, 'should have thrown the exception') + assert not True, "should have thrown the exception" except NotImplementedError: pass - #assert_raises(NotImplementedError, p.bounding_box) + # pytest.raises(NotImplementedError, p.bounding_box) p.to_metric() p.to_inch() - #try: + # try: # p.offset(1, 1) # assert_false(True, 'should have thrown the exception') - #except NotImplementedError: + # except NotImplementedError: # pass - def test_line_angle(): """ Test Line primitive angle calculation """ - cases = [((0, 0), (1, 0), math.radians(0)), - ((0, 0), (1, 1), math.radians(45)), - ((0, 0), (0, 1), math.radians(90)), - ((0, 0), (-1, 1), math.radians(135)), - ((0, 0), (-1, 0), math.radians(180)), - ((0, 0), (-1, -1), math.radians(225)), - ((0, 0), (0, -1), math.radians(270)), - ((0, 0), (1, -1), math.radians(315)), ] + cases = [ + ((0, 0), (1, 0), math.radians(0)), + ((0, 0), (1, 1), math.radians(45)), + ((0, 0), (0, 1), math.radians(90)), + ((0, 0), (-1, 1), math.radians(135)), + ((0, 0), (-1, 0), math.radians(180)), + ((0, 0), (-1, -1), math.radians(225)), + ((0, 0), (0, -1), math.radians(270)), + ((0, 0), (1, -1), math.radians(315)), + ] for start, end, expected in cases: l = Line(start, end, 0) line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) - assert_almost_equal(line_angle, expected) + pytest.approx(line_angle, expected) def test_line_bounds(): """ Test Line primitive bounding box calculation """ - cases = [((0, 0), (1, 1), ((-1, 2), (-1, 2))), - ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), - ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), - ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), ] + cases = [ + ((0, 0), (1, 1), ((-1, 2), (-1, 2))), + ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), + ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), + ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), + ] c = Circle((0, 0), 2) r = Rectangle((0, 0), 2, 2) for shape in (c, r): for start, end, expected in cases: l = Line(start, end, shape) - assert_equal(l.bounding_box, expected) + assert l.bounding_box == expected # Test a non-square rectangle r = Rectangle((0, 0), 3, 2) - cases = [((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))), - ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))), - ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))), - ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))), ] + cases = [ + ((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))), + ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))), + ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))), + ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))), + ] for start, end, expected in cases: l = Line(start, end, r) - assert_equal(l.bounding_box, expected) + assert l.bounding_box == expected def test_line_vertices(): c = Circle((0, 0), 2) l = Line((0, 0), (1, 1), c) - assert_equal(l.vertices, None) + assert l.vertices == None # All 4 compass points, all 4 quadrants and the case where start == end - test_cases = [((0, 0), (1, 0), ((-1, -1), (-1, 1), (2, 1), (2, -1))), - ((0, 0), (1, 1), ((-1, -1), (-1, 1), - (0, 2), (2, 2), (2, 0), (1, -1))), - ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), - ((0, 0), (-1, 1), ((-1, -1), (-2, 0), - (-2, 2), (0, 2), (1, 1), (1, -1))), - ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), - ((0, 0), (-1, -1), ((-2, -2), (1, -1), - (1, 1), (-1, 1), (-2, 0), (0, -2))), - ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), - ((0, 0), (1, -1), ((-1, -1), (0, -2), - (2, -2), (2, 0), (1, 1), (-1, 1))), - ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))), ] + test_cases = [ + ((0, 0), (1, 0), ((-1, -1), (-1, 1), (2, 1), (2, -1))), + ((0, 0), (1, 1), ((-1, -1), (-1, 1), (0, 2), (2, 2), (2, 0), (1, -1))), + ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), + ((0, 0), (-1, 1), ((-1, -1), (-2, 0), (-2, 2), (0, 2), (1, 1), (1, -1))), + ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), + ((0, 0), (-1, -1), ((-2, -2), (1, -1), (1, 1), (-1, 1), (-2, 0), (0, -2))), + ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), + ((0, 0), (1, -1), ((-1, -1), (0, -2), (2, -2), (2, 0), (1, 1), (-1, 1))), + ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))), + ] r = Rectangle((0, 0), 2, 2) for start, end, vertices in test_cases: l = Line(start, end, r) - assert_equal(set(vertices), set(l.vertices)) + assert set(vertices) == set(l.vertices) def test_line_conversion(): - c = Circle((0, 0), 25.4, units='metric') - l = Line((2.54, 25.4), (254.0, 2540.0), c, units='metric') + c = Circle((0, 0), 25.4, units="metric") + l = Line((2.54, 25.4), (254.0, 2540.0), c, units="metric") # No effect l.to_metric() - assert_equal(l.start, (2.54, 25.4)) - assert_equal(l.end, (254.0, 2540.0)) - assert_equal(l.aperture.diameter, 25.4) + assert l.start == (2.54, 25.4) + assert l.end == (254.0, 2540.0) + assert l.aperture.diameter == 25.4 l.to_inch() - assert_equal(l.start, (0.1, 1.0)) - assert_equal(l.end, (10.0, 100.0)) - assert_equal(l.aperture.diameter, 1.0) + assert l.start == (0.1, 1.0) + assert l.end == (10.0, 100.0) + assert l.aperture.diameter == 1.0 # No effect l.to_inch() - assert_equal(l.start, (0.1, 1.0)) - assert_equal(l.end, (10.0, 100.0)) - assert_equal(l.aperture.diameter, 1.0) + assert l.start == (0.1, 1.0) + assert l.end == (10.0, 100.0) + assert l.aperture.diameter == 1.0 - c = Circle((0, 0), 1.0, units='inch') - l = Line((0.1, 1.0), (10.0, 100.0), c, units='inch') + c = Circle((0, 0), 1.0, units="inch") + l = Line((0.1, 1.0), (10.0, 100.0), c, units="inch") # No effect l.to_inch() - assert_equal(l.start, (0.1, 1.0)) - assert_equal(l.end, (10.0, 100.0)) - assert_equal(l.aperture.diameter, 1.0) + assert l.start == (0.1, 1.0) + assert l.end == (10.0, 100.0) + assert l.aperture.diameter == 1.0 l.to_metric() - assert_equal(l.start, (2.54, 25.4)) - assert_equal(l.end, (254.0, 2540.0)) - assert_equal(l.aperture.diameter, 25.4) + assert l.start == (2.54, 25.4) + assert l.end == (254.0, 2540.0) + assert l.aperture.diameter == 25.4 # No effect l.to_metric() - assert_equal(l.start, (2.54, 25.4)) - assert_equal(l.end, (254.0, 2540.0)) - assert_equal(l.aperture.diameter, 25.4) + assert l.start == (2.54, 25.4) + assert l.end == (254.0, 2540.0) + assert l.aperture.diameter == 25.4 - r = Rectangle((0, 0), 25.4, 254.0, units='metric') - l = Line((2.54, 25.4), (254.0, 2540.0), r, units='metric') + r = Rectangle((0, 0), 25.4, 254.0, units="metric") + l = Line((2.54, 25.4), (254.0, 2540.0), r, units="metric") l.to_inch() - assert_equal(l.start, (0.1, 1.0)) - assert_equal(l.end, (10.0, 100.0)) - assert_equal(l.aperture.width, 1.0) - assert_equal(l.aperture.height, 10.0) + assert l.start == (0.1, 1.0) + assert l.end == (10.0, 100.0) + assert l.aperture.width == 1.0 + assert l.aperture.height == 10.0 - r = Rectangle((0, 0), 1.0, 10.0, units='inch') - l = Line((0.1, 1.0), (10.0, 100.0), r, units='inch') + r = Rectangle((0, 0), 1.0, 10.0, units="inch") + l = Line((0.1, 1.0), (10.0, 100.0), r, units="inch") l.to_metric() - assert_equal(l.start, (2.54, 25.4)) - assert_equal(l.end, (254.0, 2540.0)) - assert_equal(l.aperture.width, 25.4) - assert_equal(l.aperture.height, 254.0) + assert l.start == (2.54, 25.4) + assert l.end == (254.0, 2540.0) + assert l.aperture.width == 25.4 + assert l.aperture.height == 254.0 def test_line_offset(): c = Circle((0, 0), 1) l = Line((0, 0), (1, 1), c) l.offset(1, 0) - assert_equal(l.start, (1., 0.)) - assert_equal(l.end, (2., 1.)) + assert l.start == (1.0, 0.0) + assert l.end == (2.0, 1.0) l.offset(0, 1) - assert_equal(l.start, (1., 1.)) - assert_equal(l.end, (2., 2.)) + assert l.start == (1.0, 1.0) + assert l.end == (2.0, 2.0) def test_arc_radius(): """ Test Arc primitive radius calculation """ - cases = [((-3, 4), (5, 0), (0, 0), 5), - ((0, 1), (1, 0), (0, 0), 1), ] + cases = [((-3, 4), (5, 0), (0, 0), 5), ((0, 1), (1, 0), (0, 0), 1)] for start, end, center, radius in cases: - a = Arc(start, end, center, 'clockwise', 0, 'single-quadrant') - assert_equal(a.radius, radius) + a = Arc(start, end, center, "clockwise", 0, "single-quadrant") + assert a.radius == radius def test_arc_sweep_angle(): """ Test Arc primitive sweep angle calculation """ - cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)), - ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)), - ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)), - ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)), ] + cases = [ + ((1, 0), (0, 1), (0, 0), "counterclockwise", math.radians(90)), + ((1, 0), (0, 1), (0, 0), "clockwise", math.radians(270)), + ((1, 0), (-1, 0), (0, 0), "clockwise", math.radians(180)), + ((1, 0), (-1, 0), (0, 0), "counterclockwise", math.radians(180)), + ] for start, end, center, direction, sweep in cases: - c = Circle((0,0), 1) - a = Arc(start, end, center, direction, c, 'single-quadrant') - assert_equal(a.sweep_angle, sweep) + c = Circle((0, 0), 1) + a = Arc(start, end, center, direction, c, "single-quadrant") + assert a.sweep_angle == sweep def test_arc_bounds(): """ Test Arc primitive bounding box calculation """ cases = [ - ((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((1, 0), (0, 1), (0, 0), 'counterclockwise',((-0.5, 1.5), (-0.5, 1.5))), - - ((0, 1), (-1, 0), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((0, 1), (-1, 0), (0, 0), 'counterclockwise', ((-1.5, 0.5), (-0.5, 1.5))), - - ((-1, 0), (0, -1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((-1, 0), (0, -1), (0, 0), 'counterclockwise', ((-1.5, 0.5), (-1.5, 0.5))), - - ((0, -1), (1, 0), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((0, -1), (1, 0), (0, 0), 'counterclockwise',((-0.5, 1.5), (-1.5, 0.5))), - + ((1, 0), (0, 1), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (0, 1), (0, 0), "counterclockwise", ((-0.5, 1.5), (-0.5, 1.5))), + ((0, 1), (-1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))), + ((0, 1), (-1, 0), (0, 0), "counterclockwise", ((-1.5, 0.5), (-0.5, 1.5))), + ((-1, 0), (0, -1), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))), + ((-1, 0), (0, -1), (0, 0), "counterclockwise", ((-1.5, 0.5), (-1.5, 0.5))), + ((0, -1), (1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))), + ((0, -1), (1, 0), (0, 0), "counterclockwise", ((-0.5, 1.5), (-1.5, 0.5))), # Arcs with the same start and end point render a full circle - ((1, 0), (1, 0), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((1, 0), (1, 0), (0, 0), 'counterclockwise', ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (1, 0), (0, 0), "clockwise", ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (1, 0), (0, 0), "counterclockwise", ((-1.5, 1.5), (-1.5, 1.5))), ] for start, end, center, direction, bounds in cases: - c = Circle((0,0), 1) - a = Arc(start, end, center, direction, c, 'multi-quadrant') - assert_equal(a.bounding_box, bounds) + c = Circle((0, 0), 1) + a = Arc(start, end, center, direction, c, "multi-quadrant") + assert a.bounding_box == bounds + def test_arc_bounds_no_aperture(): """ Test Arc primitive bounding box calculation ignoring aperture """ cases = [ - ((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.0, 1.0), (-1.0, 1.0))), - ((1, 0), (0, 1), (0, 0), 'counterclockwise',((0.0, 1.0), (0.0, 1.0))), - - ((0, 1), (-1, 0), (0, 0), 'clockwise', ((-1.0, 1.0), (-1.0, 1.0))), - ((0, 1), (-1, 0), (0, 0), 'counterclockwise', ((-1.0, 0.0), (0.0, 1.0))), - - ((-1, 0), (0, -1), (0, 0), 'clockwise', ((-1.0, 1.0), (-1.0, 1.0))), - ((-1, 0), (0, -1), (0, 0), 'counterclockwise', ((-1.0, 0.0), (-1.0, 0.0))), - - ((0, -1), (1, 0), (0, 0), 'clockwise', ((-1.0, 1.0), (-1.0, 1.0))), - ((0, -1), (1, 0), (0, 0), 'counterclockwise',((-0.0, 1.0), (-1.0, 0.0))), - + ((1, 0), (0, 1), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))), + ((1, 0), (0, 1), (0, 0), "counterclockwise", ((0.0, 1.0), (0.0, 1.0))), + ((0, 1), (-1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))), + ((0, 1), (-1, 0), (0, 0), "counterclockwise", ((-1.0, 0.0), (0.0, 1.0))), + ((-1, 0), (0, -1), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))), + ((-1, 0), (0, -1), (0, 0), "counterclockwise", ((-1.0, 0.0), (-1.0, 0.0))), + ((0, -1), (1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))), + ((0, -1), (1, 0), (0, 0), "counterclockwise", ((-0.0, 1.0), (-1.0, 0.0))), # Arcs with the same start and end point render a full circle - ((1, 0), (1, 0), (0, 0), 'clockwise', ((-1.0, 1.0), (-1.0, 1.0))), - ((1, 0), (1, 0), (0, 0), 'counterclockwise', ((-1.0, 1.0), (-1.0, 1.0))), + ((1, 0), (1, 0), (0, 0), "clockwise", ((-1.0, 1.0), (-1.0, 1.0))), + ((1, 0), (1, 0), (0, 0), "counterclockwise", ((-1.0, 1.0), (-1.0, 1.0))), ] for start, end, center, direction, bounds in cases: - c = Circle((0,0), 1) - a = Arc(start, end, center, direction, c, 'multi-quadrant') - assert_equal(a.bounding_box_no_aperture, bounds) + c = Circle((0, 0), 1) + a = Arc(start, end, center, direction, c, "multi-quadrant") + assert a.bounding_box_no_aperture == bounds def test_arc_conversion(): - c = Circle((0, 0), 25.4, units='metric') - a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0), - 'clockwise', c, 'single-quadrant', units='metric') + c = Circle((0, 0), 25.4, units="metric") + a = Arc( + (2.54, 25.4), + (254.0, 2540.0), + (25400.0, 254000.0), + "clockwise", + c, + "single-quadrant", + units="metric", + ) # No effect a.to_metric() - assert_equal(a.start, (2.54, 25.4)) - assert_equal(a.end, (254.0, 2540.0)) - assert_equal(a.center, (25400.0, 254000.0)) - assert_equal(a.aperture.diameter, 25.4) + assert a.start == (2.54, 25.4) + assert a.end == (254.0, 2540.0) + assert a.center == (25400.0, 254000.0) + assert a.aperture.diameter == 25.4 a.to_inch() - assert_equal(a.start, (0.1, 1.0)) - assert_equal(a.end, (10.0, 100.0)) - assert_equal(a.center, (1000.0, 10000.0)) - assert_equal(a.aperture.diameter, 1.0) + assert a.start == (0.1, 1.0) + assert a.end == (10.0, 100.0) + assert a.center == (1000.0, 10000.0) + assert a.aperture.diameter == 1.0 # no effect a.to_inch() - assert_equal(a.start, (0.1, 1.0)) - assert_equal(a.end, (10.0, 100.0)) - assert_equal(a.center, (1000.0, 10000.0)) - assert_equal(a.aperture.diameter, 1.0) - - c = Circle((0, 0), 1.0, units='inch') - a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), - 'clockwise', c, 'single-quadrant', units='inch') + assert a.start == (0.1, 1.0) + assert a.end == (10.0, 100.0) + assert a.center == (1000.0, 10000.0) + assert a.aperture.diameter == 1.0 + + c = Circle((0, 0), 1.0, units="inch") + a = Arc( + (0.1, 1.0), + (10.0, 100.0), + (1000.0, 10000.0), + "clockwise", + c, + "single-quadrant", + units="inch", + ) a.to_metric() - assert_equal(a.start, (2.54, 25.4)) - assert_equal(a.end, (254.0, 2540.0)) - assert_equal(a.center, (25400.0, 254000.0)) - assert_equal(a.aperture.diameter, 25.4) + assert a.start == (2.54, 25.4) + assert a.end == (254.0, 2540.0) + assert a.center == (25400.0, 254000.0) + assert a.aperture.diameter == 25.4 def test_arc_offset(): c = Circle((0, 0), 1) - a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c, 'single-quadrant') + a = Arc((0, 0), (1, 1), (2, 2), "clockwise", c, "single-quadrant") a.offset(1, 0) - assert_equal(a.start, (1., 0.)) - assert_equal(a.end, (2., 1.)) - assert_equal(a.center, (3., 2.)) + assert a.start == (1.0, 0.0) + assert a.end == (2.0, 1.0) + assert a.center == (3.0, 2.0) a.offset(0, 1) - assert_equal(a.start, (1., 1.)) - assert_equal(a.end, (2., 2.)) - assert_equal(a.center, (3., 3.)) + assert a.start == (1.0, 1.0) + assert a.end == (2.0, 2.0) + assert a.center == (3.0, 3.0) def test_circle_radius(): """ Test Circle primitive radius calculation """ c = Circle((1, 1), 2) - assert_equal(c.radius, 1) + assert c.radius == 1 def test_circle_hole_radius(): """ Test Circle primitive hole radius calculation """ c = Circle((1, 1), 4, 2) - assert_equal(c.hole_radius, 1) + assert c.hole_radius == 1 def test_circle_bounds(): """ Test Circle bounding box calculation """ c = Circle((1, 1), 2) - assert_equal(c.bounding_box, ((0, 2), (0, 2))) + assert c.bounding_box == ((0, 2), (0, 2)) def test_circle_conversion(): """Circle conversion of units""" # Circle initially metric, no hole - c = Circle((2.54, 25.4), 254.0, units='metric') + c = Circle((2.54, 25.4), 254.0, units="metric") c.to_metric() # shouldn't do antyhing - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, None) + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == None c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, None) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == None # no effect c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, None) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == None # Circle initially metric, with hole - c = Circle((2.54, 25.4), 254.0, 127.0, units='metric') + c = Circle((2.54, 25.4), 254.0, 127.0, units="metric") - c.to_metric() #shouldn't do antyhing - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 127.) + c.to_metric() # shouldn't do antyhing + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == 127.0 c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 5.) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == 5.0 # no effect c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 5.) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == 5.0 # Circle initially inch, no hole - c = Circle((0.1, 1.0), 10.0, units='inch') + c = Circle((0.1, 1.0), 10.0, units="inch") # No effect c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, None) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == None c.to_metric() - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, None) + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == None # no effect c.to_metric() - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, None) + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == None - c = Circle((0.1, 1.0), 10.0, 5.0, units='inch') - #No effect + c = Circle((0.1, 1.0), 10.0, 5.0, units="inch") + # No effect c.to_inch() - assert_equal(c.position, (0.1, 1.)) - assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 5.) + assert c.position == (0.1, 1.0) + assert c.diameter == 10.0 + assert c.hole_diameter == 5.0 c.to_metric() - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 127.) + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == 127.0 # no effect c.to_metric() - assert_equal(c.position, (2.54, 25.4)) - assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 127.) + assert c.position == (2.54, 25.4) + assert c.diameter == 254.0 + assert c.hole_diameter == 127.0 def test_circle_offset(): c = Circle((0, 0), 1) c.offset(1, 0) - assert_equal(c.position, (1., 0.)) + assert c.position == (1.0, 0.0) c.offset(0, 1) - assert_equal(c.position, (1., 1.)) + assert c.position == (1.0, 1.0) def test_ellipse_ctor(): """ Test ellipse creation """ e = Ellipse((2, 2), 3, 2) - assert_equal(e.position, (2, 2)) - assert_equal(e.width, 3) - assert_equal(e.height, 2) + assert e.position == (2, 2) + assert e.width == 3 + assert e.height == 2 def test_ellipse_bounds(): """ Test ellipse bounding box calculation """ e = Ellipse((2, 2), 4, 2) - assert_equal(e.bounding_box, ((0, 4), (1, 3))) + assert e.bounding_box == ((0, 4), (1, 3)) e = Ellipse((2, 2), 4, 2, rotation=90) - assert_equal(e.bounding_box, ((1, 3), (0, 4))) + assert e.bounding_box == ((1, 3), (0, 4)) e = Ellipse((2, 2), 4, 2, rotation=180) - assert_equal(e.bounding_box, ((0, 4), (1, 3))) + assert e.bounding_box == ((0, 4), (1, 3)) e = Ellipse((2, 2), 4, 2, rotation=270) - assert_equal(e.bounding_box, ((1, 3), (0, 4))) + assert e.bounding_box == ((1, 3), (0, 4)) def test_ellipse_conversion(): - e = Ellipse((2.54, 25.4), 254.0, 2540., units='metric') + e = Ellipse((2.54, 25.4), 254.0, 2540.0, units="metric") # No effect e.to_metric() - assert_equal(e.position, (2.54, 25.4)) - assert_equal(e.width, 254.) - assert_equal(e.height, 2540.) + assert e.position == (2.54, 25.4) + assert e.width == 254.0 + assert e.height == 2540.0 e.to_inch() - assert_equal(e.position, (0.1, 1.)) - assert_equal(e.width, 10.) - assert_equal(e.height, 100.) + assert e.position == (0.1, 1.0) + assert e.width == 10.0 + assert e.height == 100.0 # No effect e.to_inch() - assert_equal(e.position, (0.1, 1.)) - assert_equal(e.width, 10.) - assert_equal(e.height, 100.) + assert e.position == (0.1, 1.0) + assert e.width == 10.0 + assert e.height == 100.0 - e = Ellipse((0.1, 1.), 10.0, 100., units='inch') + e = Ellipse((0.1, 1.0), 10.0, 100.0, units="inch") # no effect e.to_inch() - assert_equal(e.position, (0.1, 1.)) - assert_equal(e.width, 10.) - assert_equal(e.height, 100.) + assert e.position == (0.1, 1.0) + assert e.width == 10.0 + assert e.height == 100.0 e.to_metric() - assert_equal(e.position, (2.54, 25.4)) - assert_equal(e.width, 254.) - assert_equal(e.height, 2540.) + assert e.position == (2.54, 25.4) + assert e.width == 254.0 + assert e.height == 2540.0 # No effect e.to_metric() - assert_equal(e.position, (2.54, 25.4)) - assert_equal(e.width, 254.) - assert_equal(e.height, 2540.) + assert e.position == (2.54, 25.4) + assert e.width == 254.0 + assert e.height == 2540.0 def test_ellipse_offset(): e = Ellipse((0, 0), 1, 2) e.offset(1, 0) - assert_equal(e.position, (1., 0.)) + assert e.position == (1.0, 0.0) e.offset(0, 1) - assert_equal(e.position, (1., 1.)) + assert e.position == (1.0, 1.0) def test_rectangle_ctor(): @@ -471,19 +482,19 @@ def test_rectangle_ctor(): test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: r = Rectangle(pos, width, height) - assert_equal(r.position, pos) - assert_equal(r.width, width) - assert_equal(r.height, height) + assert r.position == pos + assert r.width == width + assert r.height == height def test_rectangle_hole_radius(): """ Test rectangle hole diameter calculation """ - r = Rectangle((0,0), 2, 2) - assert_equal(0, r.hole_radius) + r = Rectangle((0, 0), 2, 2) + assert 0 == r.hole_radius - r = Rectangle((0,0), 2, 2, 1) - assert_equal(0.5, r.hole_radius) + r = Rectangle((0, 0), 2, 2, 1) + assert 0.5 == r.hole_radius def test_rectangle_bounds(): @@ -491,126 +502,137 @@ def test_rectangle_bounds(): """ r = Rectangle((0, 0), 2, 2) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) r = Rectangle((0, 0), 2, 2, rotation=45) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) - assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_rectangle_vertices(): sqrt2 = math.sqrt(2.0) TEST_VECTORS = [ ((0, 0), 2.0, 2.0, 0.0, ((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0))), ((0, 0), 2.0, 3.0, 0.0, ((-1.0, -1.5), (-1.0, 1.5), (1.0, 1.5), (1.0, -1.5))), - ((0, 0), 2.0, 2.0, 90.0,((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0))), - ((0, 0), 3.0, 2.0, 90.0,((-1.0, -1.5), (-1.0, 1.5), (1.0, 1.5), (1.0, -1.5))), - ((0, 0), 2.0, 2.0, 45.0,((-sqrt2, 0.0), (0.0, sqrt2), (sqrt2, 0), (0, -sqrt2))), + ((0, 0), 2.0, 2.0, 90.0, ((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0))), + ((0, 0), 3.0, 2.0, 90.0, ((-1.0, -1.5), (-1.0, 1.5), (1.0, 1.5), (1.0, -1.5))), + ( + (0, 0), + 2.0, + 2.0, + 45.0, + ((-sqrt2, 0.0), (0.0, sqrt2), (sqrt2, 0), (0, -sqrt2)), + ), ] for pos, width, height, rotation, expected in TEST_VECTORS: r = Rectangle(pos, width, height, rotation=rotation) for test, expect in zip(sorted(r.vertices), sorted(expected)): - assert_array_almost_equal(test, expect) + pytest.approx(test, expect) r = Rectangle((0, 0), 2.0, 2.0, rotation=0.0) r.rotation = 45.0 - for test, expect in zip(sorted(r.vertices), sorted(((-sqrt2, 0.0), (0.0, sqrt2), (sqrt2, 0), (0, -sqrt2)))): - assert_array_almost_equal(test, expect) + for test, expect in zip( + sorted(r.vertices), + sorted(((-sqrt2, 0.0), (0.0, sqrt2), (sqrt2, 0), (0, -sqrt2))), + ): + pytest.approx(test, expect) + def test_rectangle_segments(): r = Rectangle((0, 0), 2.0, 2.0) expected = [vtx for segment in r.segments for vtx in segment] for vertex in r.vertices: - assert_in(vertex, expected) + assert vertex in expected def test_rectangle_conversion(): """Test converting rectangles between units""" # Initially metric no hole - r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') + r = Rectangle((2.54, 25.4), 254.0, 2540.0, units="metric") r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 # Initially metric with hole - r = Rectangle((2.54, 25.4), 254.0, 2540.0, 127.0, units='metric') + r = Rectangle((2.54, 25.4), 254.0, 2540.0, 127.0, units="metric") r.to_metric() - assert_equal(r.position, (2.54,25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.hole_diameter, 127.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.hole_diameter == 127.0 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.hole_diameter, 5.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.hole_diameter == 5.0 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.hole_diameter, 5.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.hole_diameter == 5.0 # Initially inch, no hole - r = Rectangle((0.1, 1.0), 10.0, 100.0, units='inch') + r = Rectangle((0.1, 1.0), 10.0, 100.0, units="inch") r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 # Initially inch with hole - r = Rectangle((0.1, 1.0), 10.0, 100.0, 5.0, units='inch') + r = Rectangle((0.1, 1.0), 10.0, 100.0, 5.0, units="inch") r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.hole_diameter, 5.0) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.hole_diameter == 5.0 r.to_metric() - assert_equal(r.position, (2.54,25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.hole_diameter, 127.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.hole_diameter == 127.0 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.hole_diameter, 127.0) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.hole_diameter == 127.0 def test_rectangle_offset(): r = Rectangle((0, 0), 1, 2) r.offset(1, 0) - assert_equal(r.position, (1., 0.)) + assert r.position == (1.0, 0.0) r.offset(0, 1) - assert_equal(r.position, (1., 1.)) + assert r.position == (1.0, 1.0) def test_diamond_ctor(): @@ -619,9 +641,9 @@ def test_diamond_ctor(): test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: d = Diamond(pos, width, height) - assert_equal(d.position, pos) - assert_equal(d.width, width) - assert_equal(d.height, height) + assert d.position == pos + assert d.width == width + assert d.height == height def test_diamond_bounds(): @@ -629,71 +651,73 @@ def test_diamond_bounds(): """ d = Diamond((0, 0), 2, 2) xbounds, ybounds = d.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) d = Diamond((0, 0), math.sqrt(2), math.sqrt(2), rotation=45) xbounds, ybounds = d.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) def test_diamond_conversion(): - d = Diamond((2.54, 25.4), 254.0, 2540.0, units='metric') + d = Diamond((2.54, 25.4), 254.0, 2540.0, units="metric") d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.width, 254.0) - assert_equal(d.height, 2540.0) + assert d.position == (2.54, 25.4) + assert d.width == 254.0 + assert d.height == 2540.0 d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.width, 10.0) - assert_equal(d.height, 100.0) + assert d.position == (0.1, 1.0) + assert d.width == 10.0 + assert d.height == 100.0 d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.width, 10.0) - assert_equal(d.height, 100.0) + assert d.position == (0.1, 1.0) + assert d.width == 10.0 + assert d.height == 100.0 - d = Diamond((0.1, 1.0), 10.0, 100.0, units='inch') + d = Diamond((0.1, 1.0), 10.0, 100.0, units="inch") d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.width, 10.0) - assert_equal(d.height, 100.0) + assert d.position == (0.1, 1.0) + assert d.width == 10.0 + assert d.height == 100.0 d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.width, 254.0) - assert_equal(d.height, 2540.0) + assert d.position == (2.54, 25.4) + assert d.width == 254.0 + assert d.height == 2540.0 d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.width, 254.0) - assert_equal(d.height, 2540.0) + assert d.position == (2.54, 25.4) + assert d.width == 254.0 + assert d.height == 2540.0 def test_diamond_offset(): d = Diamond((0, 0), 1, 2) d.offset(1, 0) - assert_equal(d.position, (1., 0.)) + assert d.position == (1.0, 0.0) d.offset(0, 1) - assert_equal(d.position, (1., 1.)) + assert d.position == (1.0, 1.0) def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation """ - test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), - ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1, 1), 1, 2, 0.4, (False, False, False, False))) + test_cases = ( + ((0, 0), 1, 1, 0.2, (True, True, False, False)), + ((0, 0), 1, 2, 0.3, (True, True, True, True)), + ((1, 1), 1, 2, 0.4, (False, False, False, False)), + ) for pos, width, height, chamfer, corners in test_cases: r = ChamferRectangle(pos, width, height, chamfer, corners) - assert_equal(r.position, pos) - assert_equal(r.width, width) - assert_equal(r.height, height) - assert_equal(r.chamfer, chamfer) - assert_array_almost_equal(r.corners, corners) + assert r.position == pos + assert r.width == width + assert r.height == height + assert r.chamfer == chamfer + pytest.approx(r.corners, corners) def test_chamfer_rectangle_bounds(): @@ -701,91 +725,124 @@ def test_chamfer_rectangle_bounds(): """ r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) - r = ChamferRectangle( - (0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) + r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) - assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_chamfer_rectangle_conversion(): - r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, - (True, True, False, False), units='metric') + r = ChamferRectangle( + (2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units="metric" + ) r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.chamfer, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.chamfer == 0.254 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.chamfer, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.chamfer == 0.01 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.chamfer, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.chamfer == 0.01 - r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, - (True, True, False, False), units='inch') + r = ChamferRectangle( + (0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units="inch" + ) r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.chamfer, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.chamfer == 0.01 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.chamfer, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.chamfer == 0.254 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.chamfer, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.chamfer == 0.254 def test_chamfer_rectangle_offset(): r = ChamferRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position, (1., 0.)) + assert r.position == (1.0, 0.0) r.offset(0, 1) - assert_equal(r.position, (1., 1.)) + assert r.position == (1.0, 1.0) + def test_chamfer_rectangle_vertices(): TEST_VECTORS = [ - (1.0, (True, True, True, True), ((-2.5, -1.5), (-2.5, 1.5), (-1.5, 2.5), (1.5, 2.5), (2.5, 1.5), (2.5, -1.5), (1.5, -2.5), (-1.5, -2.5))), - (1.0, (True, False, False, False), ((-2.5, -2.5), (-2.5, 2.5), (1.5, 2.5), (2.5, 1.5), (2.5, -2.5))), - (1.0, (False, True, False, False), ((-2.5, -2.5), (-2.5, 1.5), (-1.5, 2.5), (2.5, 2.5), (2.5, -2.5))), - (1.0, (False, False, True, False), ((-2.5, -1.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -2.5), (-1.5, -2.5))), - (1.0, (False, False, False, True), ((-2.5, -2.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -1.5), (1.5, -2.5))), + ( + 1.0, + (True, True, True, True), + ( + (-2.5, -1.5), + (-2.5, 1.5), + (-1.5, 2.5), + (1.5, 2.5), + (2.5, 1.5), + (2.5, -1.5), + (1.5, -2.5), + (-1.5, -2.5), + ), + ), + ( + 1.0, + (True, False, False, False), + ((-2.5, -2.5), (-2.5, 2.5), (1.5, 2.5), (2.5, 1.5), (2.5, -2.5)), + ), + ( + 1.0, + (False, True, False, False), + ((-2.5, -2.5), (-2.5, 1.5), (-1.5, 2.5), (2.5, 2.5), (2.5, -2.5)), + ), + ( + 1.0, + (False, False, True, False), + ((-2.5, -1.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -2.5), (-1.5, -2.5)), + ), + ( + 1.0, + (False, False, False, True), + ((-2.5, -2.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -1.5), (1.5, -2.5)), + ), ] for chamfer, corners, expected in TEST_VECTORS: r = ChamferRectangle((0, 0), 5, 5, chamfer, corners) - assert_equal(set(r.vertices), set(expected)) + assert set(r.vertices) == set(expected) def test_round_rectangle_ctor(): """ Test round rectangle creation """ - test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), - ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1, 1), 1, 2, 0.4, (False, False, False, False))) + test_cases = ( + ((0, 0), 1, 1, 0.2, (True, True, False, False)), + ((0, 0), 1, 2, 0.3, (True, True, True, True)), + ((1, 1), 1, 2, 0.4, (False, False, False, False)), + ) for pos, width, height, radius, corners in test_cases: r = RoundRectangle(pos, width, height, radius, corners) - assert_equal(r.position, pos) - assert_equal(r.width, width) - assert_equal(r.height, height) - assert_equal(r.radius, radius) - assert_array_almost_equal(r.corners, corners) + assert r.position == pos + assert r.width == width + assert r.height == height + assert r.radius == radius + pytest.approx(r.corners, corners) def test_round_rectangle_bounds(): @@ -793,78 +850,77 @@ def test_round_rectangle_bounds(): """ r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) - r = RoundRectangle((0, 0), 2, 2, 0.2, - (True, True, False, False), rotation=45) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) + r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) - assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(xbounds, (-math.sqrt(2), math.sqrt(2))) + pytest.approx(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_round_rectangle_conversion(): - r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, - (True, True, False, False), units='metric') + r = RoundRectangle( + (2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units="metric" + ) r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.radius, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.radius == 0.254 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.radius, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.radius == 0.01 r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.radius, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.radius == 0.01 - r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, - (True, True, False, False), units='inch') + r = RoundRectangle( + (0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units="inch" + ) r.to_inch() - assert_equal(r.position, (0.1, 1.0)) - assert_equal(r.width, 10.0) - assert_equal(r.height, 100.0) - assert_equal(r.radius, 0.01) + assert r.position == (0.1, 1.0) + assert r.width == 10.0 + assert r.height == 100.0 + assert r.radius == 0.01 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.radius, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.radius == 0.254 r.to_metric() - assert_equal(r.position, (2.54, 25.4)) - assert_equal(r.width, 254.0) - assert_equal(r.height, 2540.0) - assert_equal(r.radius, 0.254) + assert r.position == (2.54, 25.4) + assert r.width == 254.0 + assert r.height == 2540.0 + assert r.radius == 0.254 def test_round_rectangle_offset(): r = RoundRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position, (1., 0.)) + assert r.position == (1.0, 0.0) r.offset(0, 1) - assert_equal(r.position, (1., 1.)) + assert r.position == (1.0, 1.0) def test_obround_ctor(): """ Test obround creation """ - test_cases = (((0, 0), 1, 1), - ((0, 0), 1, 2), - ((1, 1), 1, 2)) + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: o = Obround(pos, width, height) - assert_equal(o.position, pos) - assert_equal(o.width, width) - assert_equal(o.height, height) + assert o.position == pos + assert o.width == width + assert o.height == height def test_obround_bounds(): @@ -872,94 +928,92 @@ def test_obround_bounds(): """ o = Obround((2, 2), 2, 4) xbounds, ybounds = o.bounding_box - assert_array_almost_equal(xbounds, (1, 3)) - assert_array_almost_equal(ybounds, (0, 4)) + pytest.approx(xbounds, (1, 3)) + pytest.approx(ybounds, (0, 4)) o = Obround((2, 2), 4, 2) xbounds, ybounds = o.bounding_box - assert_array_almost_equal(xbounds, (0, 4)) - assert_array_almost_equal(ybounds, (1, 3)) + pytest.approx(xbounds, (0, 4)) + pytest.approx(ybounds, (1, 3)) def test_obround_orientation(): o = Obround((0, 0), 2, 1) - assert_equal(o.orientation, 'horizontal') + assert o.orientation == "horizontal" o = Obround((0, 0), 1, 2) - assert_equal(o.orientation, 'vertical') + assert o.orientation == "vertical" def test_obround_subshapes(): o = Obround((0, 0), 1, 4) ss = o.subshapes - assert_array_almost_equal(ss['rectangle'].position, (0, 0)) - assert_array_almost_equal(ss['circle1'].position, (0, 1.5)) - assert_array_almost_equal(ss['circle2'].position, (0, -1.5)) + pytest.approx(ss["rectangle"].position, (0, 0)) + pytest.approx(ss["circle1"].position, (0, 1.5)) + pytest.approx(ss["circle2"].position, (0, -1.5)) o = Obround((0, 0), 4, 1) ss = o.subshapes - assert_array_almost_equal(ss['rectangle'].position, (0, 0)) - assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) - assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) + pytest.approx(ss["rectangle"].position, (0, 0)) + pytest.approx(ss["circle1"].position, (1.5, 0)) + pytest.approx(ss["circle2"].position, (-1.5, 0)) def test_obround_conversion(): - o = Obround((2.54, 25.4), 254.0, 2540.0, units='metric') + o = Obround((2.54, 25.4), 254.0, 2540.0, units="metric") # No effect o.to_metric() - assert_equal(o.position, (2.54, 25.4)) - assert_equal(o.width, 254.0) - assert_equal(o.height, 2540.0) + assert o.position == (2.54, 25.4) + assert o.width == 254.0 + assert o.height == 2540.0 o.to_inch() - assert_equal(o.position, (0.1, 1.0)) - assert_equal(o.width, 10.0) - assert_equal(o.height, 100.0) + assert o.position == (0.1, 1.0) + assert o.width == 10.0 + assert o.height == 100.0 # No effect o.to_inch() - assert_equal(o.position, (0.1, 1.0)) - assert_equal(o.width, 10.0) - assert_equal(o.height, 100.0) + assert o.position == (0.1, 1.0) + assert o.width == 10.0 + assert o.height == 100.0 - o = Obround((0.1, 1.0), 10.0, 100.0, units='inch') + o = Obround((0.1, 1.0), 10.0, 100.0, units="inch") # No effect o.to_inch() - assert_equal(o.position, (0.1, 1.0)) - assert_equal(o.width, 10.0) - assert_equal(o.height, 100.0) + assert o.position == (0.1, 1.0) + assert o.width == 10.0 + assert o.height == 100.0 o.to_metric() - assert_equal(o.position, (2.54, 25.4)) - assert_equal(o.width, 254.0) - assert_equal(o.height, 2540.0) + assert o.position == (2.54, 25.4) + assert o.width == 254.0 + assert o.height == 2540.0 # No effect o.to_metric() - assert_equal(o.position, (2.54, 25.4)) - assert_equal(o.width, 254.0) - assert_equal(o.height, 2540.0) + assert o.position == (2.54, 25.4) + assert o.width == 254.0 + assert o.height == 2540.0 def test_obround_offset(): o = Obround((0, 0), 1, 2) o.offset(1, 0) - assert_equal(o.position, (1., 0.)) + assert o.position == (1.0, 0.0) o.offset(0, 1) - assert_equal(o.position, (1., 1.)) + assert o.position == (1.0, 1.0) def test_polygon_ctor(): """ Test polygon creation """ - test_cases = (((0, 0), 3, 5, 0), - ((0, 0), 5, 6, 0), - ((1, 1), 7, 7, 45)) + test_cases = (((0, 0), 3, 5, 0), ((0, 0), 5, 6, 0), ((1, 1), 7, 7, 45)) for pos, sides, radius, hole_diameter in test_cases: p = Polygon(pos, sides, radius, hole_diameter) - assert_equal(p.position, pos) - assert_equal(p.sides, sides) - assert_equal(p.radius, radius) - assert_equal(p.hole_diameter, hole_diameter) + assert p.position == pos + assert p.sides == sides + assert p.radius == radius + assert p.hole_diameter == hole_diameter def test_polygon_bounds(): @@ -967,90 +1021,102 @@ def test_polygon_bounds(): """ p = Polygon((2, 2), 3, 2, 0) xbounds, ybounds = p.bounding_box - assert_array_almost_equal(xbounds, (0, 4)) - assert_array_almost_equal(ybounds, (0, 4)) + pytest.approx(xbounds, (0, 4)) + pytest.approx(ybounds, (0, 4)) p = Polygon((2, 2), 3, 4, 0) xbounds, ybounds = p.bounding_box - assert_array_almost_equal(xbounds, (-2, 6)) - assert_array_almost_equal(ybounds, (-2, 6)) + pytest.approx(xbounds, (-2, 6)) + pytest.approx(ybounds, (-2, 6)) def test_polygon_conversion(): - p = Polygon((2.54, 25.4), 3, 254.0, 0, units='metric') + p = Polygon((2.54, 25.4), 3, 254.0, 0, units="metric") # No effect p.to_metric() - assert_equal(p.position, (2.54, 25.4)) - assert_equal(p.radius, 254.0) + assert p.position == (2.54, 25.4) + assert p.radius == 254.0 p.to_inch() - assert_equal(p.position, (0.1, 1.0)) - assert_equal(p.radius, 10.0) + assert p.position == (0.1, 1.0) + assert p.radius == 10.0 # No effect p.to_inch() - assert_equal(p.position, (0.1, 1.0)) - assert_equal(p.radius, 10.0) + assert p.position == (0.1, 1.0) + assert p.radius == 10.0 - p = Polygon((0.1, 1.0), 3, 10.0, 0, units='inch') + p = Polygon((0.1, 1.0), 3, 10.0, 0, units="inch") # No effect p.to_inch() - assert_equal(p.position, (0.1, 1.0)) - assert_equal(p.radius, 10.0) + assert p.position == (0.1, 1.0) + assert p.radius == 10.0 p.to_metric() - assert_equal(p.position, (2.54, 25.4)) - assert_equal(p.radius, 254.0) + assert p.position == (2.54, 25.4) + assert p.radius == 254.0 # No effect p.to_metric() - assert_equal(p.position, (2.54, 25.4)) - assert_equal(p.radius, 254.0) + assert p.position == (2.54, 25.4) + assert p.radius == 254.0 def test_polygon_offset(): p = Polygon((0, 0), 5, 10, 0) p.offset(1, 0) - assert_equal(p.position, (1., 0.)) + assert p.position == (1.0, 0.0) p.offset(0, 1) - assert_equal(p.position, (1., 1.)) + assert p.position == (1.0, 1.0) def test_region_ctor(): """ Test Region creation """ apt = Circle((0, 0), 0) - lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), - Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) + lines = ( + Line((0, 0), (1, 0), apt), + Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), + Line((0, 1), (0, 0), apt), + ) points = ((0, 0), (1, 0), (1, 1), (0, 1)) r = Region(lines) for i, p in enumerate(lines): - assert_equal(r.primitives[i], p) + assert r.primitives[i] == p def test_region_bounds(): """ Test region bounding box calculation """ apt = Circle((0, 0), 0) - lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), - Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) + lines = ( + Line((0, 0), (1, 0), apt), + Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), + Line((0, 1), (0, 0), apt), + ) r = Region(lines) xbounds, ybounds = r.bounding_box - assert_array_almost_equal(xbounds, (0, 1)) - assert_array_almost_equal(ybounds, (0, 1)) + pytest.approx(xbounds, (0, 1)) + pytest.approx(ybounds, (0, 1)) def test_region_offset(): apt = Circle((0, 0), 0) - lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), - Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) + lines = ( + Line((0, 0), (1, 0), apt), + Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), + Line((0, 1), (0, 0), apt), + ) r = Region(lines) xlim, ylim = r.bounding_box r.offset(0, 1) new_xlim, new_ylim = r.bounding_box - assert_array_almost_equal(new_xlim, xlim) - assert_array_almost_equal(new_ylim, tuple([y + 1 for y in ylim])) + pytest.approx(new_xlim, xlim) + pytest.approx(new_ylim, tuple([y + 1 for y in ylim])) def test_round_butterfly_ctor(): @@ -1059,58 +1125,58 @@ def test_round_butterfly_ctor(): test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, diameter in test_cases: b = RoundButterfly(pos, diameter) - assert_equal(b.position, pos) - assert_equal(b.diameter, diameter) - assert_equal(b.radius, diameter / 2.) + assert b.position == pos + assert b.diameter == diameter + assert b.radius == diameter / 2.0 def test_round_butterfly_ctor_validation(): """ Test RoundButterfly argument validation """ - assert_raises(TypeError, RoundButterfly, 3, 5) - assert_raises(TypeError, RoundButterfly, (3, 4, 5), 5) + pytest.raises(TypeError, RoundButterfly, 3, 5) + pytest.raises(TypeError, RoundButterfly, (3, 4, 5), 5) def test_round_butterfly_conversion(): - b = RoundButterfly((2.54, 25.4), 254.0, units='metric') + b = RoundButterfly((2.54, 25.4), 254.0, units="metric") # No Effect b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.diameter, (254.0)) + assert b.position == (2.54, 25.4) + assert b.diameter == (254.0) b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.diameter, 10.0) + assert b.position == (0.1, 1.0) + assert b.diameter == 10.0 # No effect b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.diameter, 10.0) + assert b.position == (0.1, 1.0) + assert b.diameter == 10.0 - b = RoundButterfly((0.1, 1.0), 10.0, units='inch') + b = RoundButterfly((0.1, 1.0), 10.0, units="inch") # No effect b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.diameter, 10.0) + assert b.position == (0.1, 1.0) + assert b.diameter == 10.0 b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.diameter, (254.0)) + assert b.position == (2.54, 25.4) + assert b.diameter == (254.0) # No Effect b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.diameter, (254.0)) + assert b.position == (2.54, 25.4) + assert b.diameter == (254.0) def test_round_butterfly_offset(): b = RoundButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position, (1., 0.)) + assert b.position == (1.0, 0.0) b.offset(0, 1) - assert_equal(b.position, (1., 1.)) + assert b.position == (1.0, 1.0) def test_round_butterfly_bounds(): @@ -1118,8 +1184,8 @@ def test_round_butterfly_bounds(): """ b = RoundButterfly((0, 0), 2) xbounds, ybounds = b.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) def test_square_butterfly_ctor(): @@ -1128,15 +1194,15 @@ def test_square_butterfly_ctor(): test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, side in test_cases: b = SquareButterfly(pos, side) - assert_equal(b.position, pos) - assert_equal(b.side, side) + assert b.position == pos + assert b.side == side def test_square_butterfly_ctor_validation(): """ Test SquareButterfly argument validation """ - assert_raises(TypeError, SquareButterfly, 3, 5) - assert_raises(TypeError, SquareButterfly, (3, 4, 5), 5) + pytest.raises(TypeError, SquareButterfly, 3, 5) + pytest.raises(TypeError, SquareButterfly, (3, 4, 5), 5) def test_square_butterfly_bounds(): @@ -1144,125 +1210,129 @@ def test_square_butterfly_bounds(): """ b = SquareButterfly((0, 0), 2) xbounds, ybounds = b.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) def test_squarebutterfly_conversion(): - b = SquareButterfly((2.54, 25.4), 254.0, units='metric') + b = SquareButterfly((2.54, 25.4), 254.0, units="metric") # No effect b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.side, (254.0)) + assert b.position == (2.54, 25.4) + assert b.side == (254.0) b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.side, 10.0) + assert b.position == (0.1, 1.0) + assert b.side == 10.0 # No effect b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.side, 10.0) + assert b.position == (0.1, 1.0) + assert b.side == 10.0 - b = SquareButterfly((0.1, 1.0), 10.0, units='inch') + b = SquareButterfly((0.1, 1.0), 10.0, units="inch") # No effect b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.side, 10.0) + assert b.position == (0.1, 1.0) + assert b.side == 10.0 b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.side, (254.0)) + assert b.position == (2.54, 25.4) + assert b.side == (254.0) # No effect b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.side, (254.0)) + assert b.position == (2.54, 25.4) + assert b.side == (254.0) def test_square_butterfly_offset(): b = SquareButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position, (1., 0.)) + assert b.position == (1.0, 0.0) b.offset(0, 1) - assert_equal(b.position, (1., 1.)) + assert b.position == (1.0, 1.0) def test_donut_ctor(): """ Test Donut primitive creation """ - test_cases = (((0, 0), 'round', 3, 5), ((0, 0), 'square', 5, 7), - ((1, 1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) + test_cases = ( + ((0, 0), "round", 3, 5), + ((0, 0), "square", 5, 7), + ((1, 1), "hexagon", 7, 9), + ((2, 2), "octagon", 9, 11), + ) for pos, shape, in_d, out_d in test_cases: d = Donut(pos, shape, in_d, out_d) - assert_equal(d.position, pos) - assert_equal(d.shape, shape) - assert_equal(d.inner_diameter, in_d) - assert_equal(d.outer_diameter, out_d) + assert d.position == pos + assert d.shape == shape + assert d.inner_diameter == in_d + assert d.outer_diameter == out_d def test_donut_ctor_validation(): - assert_raises(TypeError, Donut, 3, 'round', 5, 7) - assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) - assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) - assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) + pytest.raises(TypeError, Donut, 3, "round", 5, 7) + pytest.raises(TypeError, Donut, (3, 4, 5), "round", 5, 7) + pytest.raises(ValueError, Donut, (0, 0), "triangle", 3, 5) + pytest.raises(ValueError, Donut, (0, 0), "round", 5, 3) def test_donut_bounds(): - d = Donut((0, 0), 'round', 0.0, 2.0) + d = Donut((0, 0), "round", 0.0, 2.0) xbounds, ybounds = d.bounding_box - assert_equal(xbounds, (-1., 1.)) - assert_equal(ybounds, (-1., 1.)) + assert xbounds == (-1.0, 1.0) + assert ybounds == (-1.0, 1.0) def test_donut_conversion(): - d = Donut((2.54, 25.4), 'round', 254.0, 2540.0, units='metric') + d = Donut((2.54, 25.4), "round", 254.0, 2540.0, units="metric") # No effect d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.inner_diameter, 254.0) - assert_equal(d.outer_diameter, 2540.0) + assert d.position == (2.54, 25.4) + assert d.inner_diameter == 254.0 + assert d.outer_diameter == 2540.0 d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.inner_diameter, 10.0) - assert_equal(d.outer_diameter, 100.0) + assert d.position == (0.1, 1.0) + assert d.inner_diameter == 10.0 + assert d.outer_diameter == 100.0 # No effect d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.inner_diameter, 10.0) - assert_equal(d.outer_diameter, 100.0) + assert d.position == (0.1, 1.0) + assert d.inner_diameter == 10.0 + assert d.outer_diameter == 100.0 - d = Donut((0.1, 1.0), 'round', 10.0, 100.0, units='inch') + d = Donut((0.1, 1.0), "round", 10.0, 100.0, units="inch") # No effect d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.inner_diameter, 10.0) - assert_equal(d.outer_diameter, 100.0) + assert d.position == (0.1, 1.0) + assert d.inner_diameter == 10.0 + assert d.outer_diameter == 100.0 d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.inner_diameter, 254.0) - assert_equal(d.outer_diameter, 2540.0) + assert d.position == (2.54, 25.4) + assert d.inner_diameter == 254.0 + assert d.outer_diameter == 2540.0 # No effect d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.inner_diameter, 254.0) - assert_equal(d.outer_diameter, 2540.0) + assert d.position == (2.54, 25.4) + assert d.inner_diameter == 254.0 + assert d.outer_diameter == 2540.0 def test_donut_offset(): - d = Donut((0, 0), 'round', 1, 10) + d = Donut((0, 0), "round", 1, 10) d.offset(1, 0) - assert_equal(d.position, (1., 0.)) + assert d.position == (1.0, 0.0) d.offset(0, 1) - assert_equal(d.position, (1., 1.)) + assert d.position == (1.0, 1.0) def test_drill_ctor(): @@ -1271,89 +1341,89 @@ def test_drill_ctor(): test_cases = (((0, 0), 2), ((1, 1), 3), ((2, 2), 5)) for position, diameter in test_cases: d = Drill(position, diameter) - assert_equal(d.position, position) - assert_equal(d.diameter, diameter) - assert_equal(d.radius, diameter / 2.) + assert d.position == position + assert d.diameter == diameter + assert d.radius == diameter / 2.0 def test_drill_ctor_validation(): """ Test drill argument validation """ - assert_raises(TypeError, Drill, 3, 5) - assert_raises(TypeError, Drill, (3,4,5), 5) - + pytest.raises(TypeError, Drill, 3, 5) + pytest.raises(TypeError, Drill, (3, 4, 5), 5) def test_drill_bounds(): d = Drill((0, 0), 2) xbounds, ybounds = d.bounding_box - assert_array_almost_equal(xbounds, (-1, 1)) - assert_array_almost_equal(ybounds, (-1, 1)) + pytest.approx(xbounds, (-1, 1)) + pytest.approx(ybounds, (-1, 1)) d = Drill((1, 2), 2) xbounds, ybounds = d.bounding_box - assert_array_almost_equal(xbounds, (0, 2)) - assert_array_almost_equal(ybounds, (1, 3)) + pytest.approx(xbounds, (0, 2)) + pytest.approx(ybounds, (1, 3)) def test_drill_conversion(): - d = Drill((2.54, 25.4), 254., units='metric') + d = Drill((2.54, 25.4), 254.0, units="metric") - #No effect + # No effect d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.diameter, 254.0) + assert d.position == (2.54, 25.4) + assert d.diameter == 254.0 d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.diameter, 10.0) + assert d.position == (0.1, 1.0) + assert d.diameter == 10.0 - #No effect + # No effect d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.diameter, 10.0) + assert d.position == (0.1, 1.0) + assert d.diameter == 10.0 - d = Drill((0.1, 1.0), 10., units='inch') + d = Drill((0.1, 1.0), 10.0, units="inch") # No effect d.to_inch() - assert_equal(d.position, (0.1, 1.0)) - assert_equal(d.diameter, 10.0) + assert d.position == (0.1, 1.0) + assert d.diameter == 10.0 d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.diameter, 254.0) + assert d.position == (2.54, 25.4) + assert d.diameter == 254.0 # No effect d.to_metric() - assert_equal(d.position, (2.54, 25.4)) - assert_equal(d.diameter, 254.0) + assert d.position == (2.54, 25.4) + assert d.diameter == 254.0 def test_drill_offset(): - d = Drill((0, 0), 1.) + d = Drill((0, 0), 1.0) d.offset(1, 0) - assert_equal(d.position, (1., 0.)) + assert d.position == (1.0, 0.0) d.offset(0, 1) - assert_equal(d.position, (1., 1.)) + assert d.position == (1.0, 1.0) def test_drill_equality(): - d = Drill((2.54, 25.4), 254.) - d1 = Drill((2.54, 25.4), 254.) - assert_equal(d, d1) + d = Drill((2.54, 25.4), 254.0) + d1 = Drill((2.54, 25.4), 254.0) + assert d == d1 d1 = Drill((2.54, 25.4), 254.2) - assert_not_equal(d, d1) + assert d != d1 def test_slot_bounds(): """ Test Slot primitive bounding box calculation """ - cases = [((0, 0), (1, 1), ((-1, 2), (-1, 2))), - ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), - ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), - ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), ] + cases = [ + ((0, 0), (1, 1), ((-1, 2), (-1, 2))), + ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), + ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), + ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), + ] for start, end, expected in cases: s = Slot(start, end, 2.0) - assert_equal(s.bounding_box, expected) - + assert s.bounding_box == expected diff --git a/gerber/tests/test_rs274x.py b/gerber/tests/test_rs274x.py index 4c69446..e7baf11 100644 --- a/gerber/tests/test_rs274x.py +++ b/gerber/tests/test_rs274x.py @@ -3,53 +3,53 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> import os +import pytest from ..rs274x import read, GerberFile -from .tests import * -TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), - 'resources/top_copper.GTL') +TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), "resources/top_copper.GTL") -MULTILINE_READ_FILE = os.path.join(os.path.dirname(__file__), - 'resources/multiline_read.ger') +MULTILINE_READ_FILE = os.path.join( + os.path.dirname(__file__), "resources/multiline_read.ger" +) def test_read(): top_copper = read(TOP_COPPER_FILE) - assert(isinstance(top_copper, GerberFile)) + assert isinstance(top_copper, GerberFile) def test_multiline_read(): multiline = read(MULTILINE_READ_FILE) - assert(isinstance(multiline, GerberFile)) - assert_equal(10, len(multiline.statements)) + assert isinstance(multiline, GerberFile) + assert 10 == len(multiline.statements) def test_comments_parameter(): top_copper = read(TOP_COPPER_FILE) - assert_equal(top_copper.comments[0], 'This is a comment,:') + assert top_copper.comments[0] == "This is a comment,:" def test_size_parameter(): top_copper = read(TOP_COPPER_FILE) size = top_copper.size - assert_almost_equal(size[0], 2.256900, 6) - assert_almost_equal(size[1], 1.500000, 6) + pytest.approx(size[0], 2.256900, 6) + pytest.approx(size[1], 1.500000, 6) def test_conversion(): top_copper = read(TOP_COPPER_FILE) - assert_equal(top_copper.units, 'inch') + assert top_copper.units == "inch" top_copper_inch = read(TOP_COPPER_FILE) top_copper.to_metric() for statement in top_copper_inch.statements: statement.to_metric() for primitive in top_copper_inch.primitives: primitive.to_metric() - assert_equal(top_copper.units, 'metric') + assert top_copper.units == "metric" for i, m in zip(top_copper.statements, top_copper_inch.statements): - assert_equal(i, m) + assert i == m for i, m in zip(top_copper.primitives, top_copper_inch.primitives): - assert_equal(i, m) + assert i == m diff --git a/gerber/tests/test_rs274x_backend.py b/gerber/tests/test_rs274x_backend.py index e128841..13347c5 100644 --- a/gerber/tests/test_rs274x_backend.py +++ b/gerber/tests/test_rs274x_backend.py @@ -7,62 +7,86 @@ import os from ..render.rs274x_backend import Rs274xContext from ..rs274x import read -from .tests import * + def test_render_two_boxes(): """Umaco exapmle of two boxes""" - _test_render('resources/example_two_square_boxes.gbr', 'golden/example_two_square_boxes.gbr') + _test_render( + "resources/example_two_square_boxes.gbr", "golden/example_two_square_boxes.gbr" + ) def _test_render_single_quadrant(): """Umaco exapmle of a single quadrant arc""" # TODO there is probably a bug here - _test_render('resources/example_single_quadrant.gbr', 'golden/example_single_quadrant.gbr') + _test_render( + "resources/example_single_quadrant.gbr", "golden/example_single_quadrant.gbr" + ) def _test_render_simple_contour(): """Umaco exapmle of a simple arrow-shaped contour""" - _test_render('resources/example_simple_contour.gbr', 'golden/example_simple_contour.gbr') + _test_render( + "resources/example_simple_contour.gbr", "golden/example_simple_contour.gbr" + ) def _test_render_single_contour_1(): """Umaco example of a single contour The resulting image for this test is used by other tests because they must generate the same output.""" - _test_render('resources/example_single_contour_1.gbr', 'golden/example_single_contour.gbr') + _test_render( + "resources/example_single_contour_1.gbr", "golden/example_single_contour.gbr" + ) def _test_render_single_contour_2(): """Umaco exapmle of a single contour, alternate contour end order The resulting image for this test is used by other tests because they must generate the same output.""" - _test_render('resources/example_single_contour_2.gbr', 'golden/example_single_contour.gbr') + _test_render( + "resources/example_single_contour_2.gbr", "golden/example_single_contour.gbr" + ) def _test_render_single_contour_3(): """Umaco exapmle of a single contour with extra line""" - _test_render('resources/example_single_contour_3.gbr', 'golden/example_single_contour_3.gbr') + _test_render( + "resources/example_single_contour_3.gbr", "golden/example_single_contour_3.gbr" + ) def _test_render_not_overlapping_contour(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_not_overlapping_contour.gbr', 'golden/example_not_overlapping_contour.gbr') + _test_render( + "resources/example_not_overlapping_contour.gbr", + "golden/example_not_overlapping_contour.gbr", + ) def _test_render_not_overlapping_touching(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_not_overlapping_touching.gbr', 'golden/example_not_overlapping_touching.gbr') + _test_render( + "resources/example_not_overlapping_touching.gbr", + "golden/example_not_overlapping_touching.gbr", + ) def _test_render_overlapping_touching(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_overlapping_touching.gbr', 'golden/example_overlapping_touching.gbr') + _test_render( + "resources/example_overlapping_touching.gbr", + "golden/example_overlapping_touching.gbr", + ) def _test_render_overlapping_contour(): """Umaco example of D02 staring a second contour""" - _test_render('resources/example_overlapping_contour.gbr', 'golden/example_overlapping_contour.gbr') + _test_render( + "resources/example_overlapping_contour.gbr", + "golden/example_overlapping_contour.gbr", + ) def _DISABLED_test_render_level_holes(): @@ -70,76 +94,96 @@ def _DISABLED_test_render_level_holes(): # TODO This is clearly rendering wrong. I'm temporarily checking this in because there are more # rendering fixes in the related repository that may resolve these. - _test_render('resources/example_level_holes.gbr', 'golden/example_overlapping_contour.gbr') + _test_render( + "resources/example_level_holes.gbr", "golden/example_overlapping_contour.gbr" + ) def _DISABLED_test_render_cutin(): """Umaco example of using a cutin""" # TODO This is clearly rendering wrong. - _test_render('resources/example_cutin.gbr', 'golden/example_cutin.gbr') + _test_render("resources/example_cutin.gbr", "golden/example_cutin.gbr") def _test_render_fully_coincident(): """Umaco example of coincident lines rendering two contours""" - _test_render('resources/example_fully_coincident.gbr', 'golden/example_fully_coincident.gbr') + _test_render( + "resources/example_fully_coincident.gbr", "golden/example_fully_coincident.gbr" + ) def _test_render_coincident_hole(): """Umaco example of coincident lines rendering a hole in the contour""" - _test_render('resources/example_coincident_hole.gbr', 'golden/example_coincident_hole.gbr') + _test_render( + "resources/example_coincident_hole.gbr", "golden/example_coincident_hole.gbr" + ) def _test_render_cutin_multiple(): """Umaco example of a region with multiple cutins""" - _test_render('resources/example_cutin_multiple.gbr', 'golden/example_cutin_multiple.gbr') + _test_render( + "resources/example_cutin_multiple.gbr", "golden/example_cutin_multiple.gbr" + ) def _test_flash_circle(): """Umaco example a simple circular flash with and without a hole""" - _test_render('resources/example_flash_circle.gbr', 'golden/example_flash_circle.gbr') + _test_render( + "resources/example_flash_circle.gbr", "golden/example_flash_circle.gbr" + ) def _test_flash_rectangle(): """Umaco example a simple rectangular flash with and without a hole""" - _test_render('resources/example_flash_rectangle.gbr', 'golden/example_flash_rectangle.gbr') + _test_render( + "resources/example_flash_rectangle.gbr", "golden/example_flash_rectangle.gbr" + ) def _test_flash_obround(): """Umaco example a simple obround flash with and without a hole""" - _test_render('resources/example_flash_obround.gbr', 'golden/example_flash_obround.gbr') + _test_render( + "resources/example_flash_obround.gbr", "golden/example_flash_obround.gbr" + ) def _test_flash_polygon(): """Umaco example a simple polygon flash with and without a hole""" - _test_render('resources/example_flash_polygon.gbr', 'golden/example_flash_polygon.gbr') + _test_render( + "resources/example_flash_polygon.gbr", "golden/example_flash_polygon.gbr" + ) def _test_holes_dont_clear(): """Umaco example that an aperture with a hole does not clear the area""" - _test_render('resources/example_holes_dont_clear.gbr', 'golden/example_holes_dont_clear.gbr') + _test_render( + "resources/example_holes_dont_clear.gbr", "golden/example_holes_dont_clear.gbr" + ) def _test_render_am_exposure_modifier(): """Umaco example that an aperture macro with a hole does not clear the area""" - _test_render('resources/example_am_exposure_modifier.gbr', 'golden/example_am_exposure_modifier.gbr') + _test_render( + "resources/example_am_exposure_modifier.gbr", + "golden/example_am_exposure_modifier.gbr", + ) def _resolve_path(path): - return os.path.join(os.path.dirname(__file__), - path) + return os.path.join(os.path.dirname(__file__), path) -def _test_render(gerber_path, png_expected_path, create_output_path = None): +def _test_render(gerber_path, png_expected_path, create_output_path=None): """Render the gerber file and compare to the expected PNG output. Parameters @@ -168,18 +212,21 @@ def _test_render(gerber_path, png_expected_path, create_output_path = None): # 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: + 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_false(True, 'Test created the output %s. This needs to be disabled to make sure the test behaves correctly' % (create_output_path,)) + 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: + with open(png_expected_path, "r") as expected_file: expected_contents = expected_file.read() - assert_equal(expected_contents, actual_contents.getvalue()) + assert expected_contents == actual_contents.getvalue() return gerber diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py index 35f6f47..68484d1 100644 --- a/gerber/tests/test_utils.py +++ b/gerber/tests/test_utils.py @@ -3,7 +3,7 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> -from .tests import assert_equal, assert_raises +import pytest from ..utils import * @@ -14,60 +14,99 @@ def test_zero_suppression(): 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), - ('0', 0.0)] + 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), + ("0", 0.0), + ] for string, value in test_cases: - assert_equal(value, parse_gerber_value(string, fmt, zero_suppression)) - assert_equal(string, write_gerber_value(value, fmt, 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), - ('0', 0.0)] + 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), + ("0", 0.0), + ] for string, value in test_cases: - assert_equal(value, parse_gerber_value(string, fmt, zero_suppression)) - assert_equal(string, write_gerber_value(value, fmt, zero_suppression)) + assert value == parse_gerber_value(string, fmt, zero_suppression) + assert string == write_gerber_value(value, fmt, zero_suppression) - assert_equal(write_gerber_value(0.000000001, fmt, 'leading'), '0') - assert_equal(write_gerber_value(0.000000001, fmt, 'trailing'), '0') + assert write_gerber_value(0.000000001, fmt, "leading") == "0" + assert write_gerber_value(0.000000001, fmt, "trailing") == "0" 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), - ((2, 6), '0', 0)] + 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), + ((2, 6), "0", 0), + ] for fmt, string, value in test_cases: - assert_equal(value, parse_gerber_value(string, fmt, zero_suppression)) - assert_equal(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), - ((2, 5), '0', 0)] + 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), + ((2, 5), "0", 0), + ] for fmt, string, value in test_cases: - assert_equal(value, parse_gerber_value(string, fmt, zero_suppression)) - assert_equal(string, write_gerber_value(value, fmt, zero_suppression)) + assert value == parse_gerber_value(string, fmt, zero_suppression) + assert string == write_gerber_value(value, fmt, zero_suppression) def test_decimal_truncation(): @@ -76,54 +115,53 @@ def test_decimal_truncation(): 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_equal(result, calculated) + calculated = "1." + "".join(str(y) for y in range(1, x + 1)) + 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') - assert_equal(decimal_string(0, precision=6, padding=True), '0.000000') + assert decimal_string(value, precision=3, padding=True) == "1.123" + assert decimal_string(value, precision=4, padding=True) == "1.1230" + assert decimal_string(value, precision=5, padding=True) == "1.12300" + assert decimal_string(value, precision=6, padding=True) == "1.123000" + assert decimal_string(0, precision=6, padding=True) == "0.000000" def test_parse_format_validation(): """ Test parse_gerber_value() format validation """ - assert_raises(ValueError, parse_gerber_value, '00001111', (7, 5)) - assert_raises(ValueError, parse_gerber_value, '00001111', (5, 8)) - assert_raises(ValueError, parse_gerber_value, '00001111', (13, 1)) + pytest.raises(ValueError, parse_gerber_value, "00001111", (7, 5)) + pytest.raises(ValueError, parse_gerber_value, "00001111", (5, 8)) + pytest.raises(ValueError, parse_gerber_value, "00001111", (13, 1)) def test_write_format_validation(): """ Test write_gerber_value() format validation """ - assert_raises(ValueError, write_gerber_value, 69.0, (7, 5)) - assert_raises(ValueError, write_gerber_value, 69.0, (5, 8)) - assert_raises(ValueError, write_gerber_value, 69.0, (13, 1)) + pytest.raises(ValueError, write_gerber_value, 69.0, (7, 5)) + pytest.raises(ValueError, write_gerber_value, 69.0, (5, 8)) + pytest.raises(ValueError, write_gerber_value, 69.0, (13, 1)) def test_detect_format_with_short_file(): """ Verify file format detection works with short files """ - assert_equal('unknown', detect_file_format('gerber/tests/__init__.py')) + assert "unknown" == detect_file_format("gerber/tests/__init__.py") def test_validate_coordinates(): - assert_raises(TypeError, validate_coordinates, 3) - assert_raises(TypeError, validate_coordinates, 3.1) - assert_raises(TypeError, validate_coordinates, '14') - assert_raises(TypeError, validate_coordinates, (0,)) - assert_raises(TypeError, validate_coordinates, (0, 1, 2)) - assert_raises(TypeError, validate_coordinates, (0, 'string')) + pytest.raises(TypeError, validate_coordinates, 3) + pytest.raises(TypeError, validate_coordinates, 3.1) + pytest.raises(TypeError, validate_coordinates, "14") + pytest.raises(TypeError, validate_coordinates, (0,)) + pytest.raises(TypeError, validate_coordinates, (0, 1, 2)) + pytest.raises(TypeError, validate_coordinates, (0, "string")) def test_convex_hull(): points = [(0, 0), (1, 0), (1, 1), (0.5, 0.5), (0, 1), (0, 0)] expected = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)] - assert_equal(set(convex_hull(points)), set(expected)) -
\ No newline at end of file + assert set(convex_hull(points)) == set(expected) diff --git a/gerber/tests/tests.py b/gerber/tests/tests.py deleted file mode 100644 index ac08208..0000000 --- a/gerber/tests/tests.py +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Author: Hamilton Kibbe <ham@hamiltonkib.be> - -from nose.tools import assert_in -from nose.tools import assert_not_in -from nose.tools import assert_equal -from nose.tools import assert_not_equal -from nose.tools import assert_almost_equal -from nose.tools import assert_true -from nose.tools import assert_false -from nose.tools import assert_raises -from nose.tools import raises -from nose import with_setup - -__all__ = ['assert_in', 'assert_not_in', 'assert_equal', 'assert_not_equal', - 'assert_almost_equal', 'assert_array_almost_equal', 'assert_true', - 'assert_false', 'assert_raises', 'raises', 'with_setup'] - - -def assert_array_almost_equal(arr1, arr2, decimal=6): - assert_equal(len(arr1), len(arr2)) - for i in range(len(arr1)): - assert_almost_equal(arr1[i], arr2[i], decimal) diff --git a/requirements-dev.txt b/requirements-dev.txt index c1e695d..1238afe 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ # install base requirements -r requirements.txt -coverage==4.5.4 -nose==1.3.7 + pytest==4.6.6 + pytest-cov==2.8.1 |