summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gerbonara/gerber/tests/test_cam.py151
-rw-r--r--gerbonara/gerber/tests/test_common.py38
-rw-r--r--gerbonara/gerber/tests/test_excellon_statements.py734
-rw-r--r--gerbonara/gerber/tests/test_gerber_statements.py903
-rw-r--r--gerbonara/gerber/tests/test_primitives.py897
5 files changed, 0 insertions, 2723 deletions
diff --git a/gerbonara/gerber/tests/test_cam.py b/gerbonara/gerber/tests/test_cam.py
deleted file mode 100644
index 8a71a32..0000000
--- a/gerbonara/gerber/tests/test_cam.py
+++ /dev/null
@@ -1,151 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-
-import pytest
-
-from ..cam import CamFile, FileSettings
-
-
-def test_filesettings_defaults():
- """ Test FileSettings default values
- """
- fs = FileSettings()
- 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 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 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 fs.units == "metric"
- assert fs.notation == "incremental"
- assert fs.zero_suppression == "leading"
- assert fs.format == (1, 2)
-
-
-def test_camfile_init():
- """ Smoke test CamFile test
- """
- cf = CamFile()
-
-
-def test_camfile_settings():
- """ Test CamFile Default Settings
- """
- cf = CamFile()
- assert cf.settings == FileSettings()
-
-
-def test_bounds_override_smoketest():
- cf = CamFile()
- cf.bounds
-
-
-def test_zeros():
- """ Test zero/zero_suppression interaction
- """
- fs = FileSettings()
- assert fs.zero_suppression == "trailing"
- assert fs.zeros == "leading"
-
- fs["zero_suppression"] = "leading"
- assert fs.zero_suppression == "leading"
- assert fs.zeros == "trailing"
-
- fs.zero_suppression = "trailing"
- assert fs.zero_suppression == "trailing"
- assert fs.zeros == "leading"
-
- fs["zeros"] = "trailing"
- assert fs.zeros == "trailing"
- assert fs.zero_suppression == "leading"
-
- fs.zeros = "leading"
- assert fs.zeros == "leading"
- assert fs.zero_suppression == "trailing"
-
- fs = FileSettings(zeros="leading")
- assert fs.zeros == "leading"
- assert fs.zero_suppression == "trailing"
-
- fs = FileSettings(zero_suppression="leading")
- assert fs.zeros == "trailing"
- assert fs.zero_suppression == "leading"
-
- fs = FileSettings(zeros="leading", zero_suppression="trailing")
- assert fs.zeros == "leading"
- assert fs.zero_suppression == "trailing"
-
- 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
- pytest.raises(ValueError, FileSettings, "absolute-ish", "inch", None, (2, 5), None)
-
- # degrees kelvin isn't a valid unit for a CAM file
- pytest.raises(
- ValueError, FileSettings, "absolute", "degrees kelvin", None, (2, 5), None
- )
-
- 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
- # pytest.raises(ValueError, FileSettings, 'absolute',
- # 'inch', 'following', (2, 5), 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()
- 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/gerbonara/gerber/tests/test_common.py b/gerbonara/gerber/tests/test_common.py
deleted file mode 100644
index e4c023c..0000000
--- a/gerbonara/gerber/tests/test_common.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-from ..exceptions import ParseError
-from ..common import read, loads
-from ..excellon import ExcellonFile
-from ..rs274x import GerberFile
-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")
-
-
-def test_file_type_detection():
- """ Test file type detection
- """
- ncdrill = read(NCDRILL_FILE)
- top_copper = read(TOP_COPPER_FILE)
- assert isinstance(ncdrill, ExcellonFile)
- assert isinstance(top_copper, GerberFile)
-
-
-def test_load_from_string():
- with open(NCDRILL_FILE, "r") as f:
- ncdrill = loads(f.read())
- with open(TOP_COPPER_FILE, "r") as f:
- top_copper = loads(f.read())
- assert isinstance(ncdrill, ExcellonFile)
- assert isinstance(top_copper, GerberFile)
-
-
-def test_file_type_validation():
- """ Test file format validation
- """
- pytest.raises(ParseError, read, __file__)
diff --git a/gerbonara/gerber/tests/test_excellon_statements.py b/gerbonara/gerber/tests/test_excellon_statements.py
deleted file mode 100644
index 41fe294..0000000
--- a/gerbonara/gerber/tests/test_excellon_statements.py
+++ /dev/null
@@ -1,734 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-
-import pytest
-from ..excellon_statements import *
-from ..cam import FileSettings
-
-
-def test_excellon_statement_implementation():
- stmt = ExcellonStatement()
- pytest.raises(NotImplementedError, stmt.from_excellon, None)
- pytest.raises(NotImplementedError, stmt.to_excellon)
-
-
-def test_excellontstmt():
- """ Smoke test ExcellonStatement
- """
- stmt = ExcellonStatement()
- stmt.to_inch()
- stmt.to_metric()
- stmt.offset()
-
-
-def test_excellontool_factory():
- """ Test ExcellonTool factory methods
- """
- exc_line = "T8F01B02S00003H04Z05C0.12500"
- settings = FileSettings(
- format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute"
- )
- tool = ExcellonTool.from_excellon(exc_line, settings)
- 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 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"
- )
- for line in exc_lines:
- tool = ExcellonTool.from_excellon(line, settings)
- assert tool.to_excellon() == line
-
-
-def test_excellontool_order():
- settings = FileSettings(
- format=(2, 5), zero_suppression="trailing", units="inch", notation="absolute"
- )
- line = "T8F00S00C0.12500"
- tool1 = ExcellonTool.from_excellon(line, settings)
- line = "T8C0.12500F00S00"
- tool2 = ExcellonTool.from_excellon(line, settings)
- 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.to_inch()
- assert tool.diameter == 1.0
- tool = ExcellonTool.from_dict(
- FileSettings(units="inch"), {"number": 8, "diameter": 1.0}
- )
- tool.to_metric()
- 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.to_inch()
- assert tool.diameter == 25.4
- tool = ExcellonTool.from_dict(
- FileSettings(units="metric"), {"number": 8, "diameter": 1.0}
- )
- tool.to_metric()
- assert tool.diameter == 1.0
-
-
-def test_excellontool_repr():
- 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})
- t1 = ExcellonTool.from_dict(FileSettings(), {"number": 8, "diameter": 0.125})
- assert t == t1
- t1 = ExcellonTool.from_dict(
- 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 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"]
- for line in lines:
- stmt = ToolSelectionStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_z_axis_infeed_rate_factory():
- """ Test ZAxisInfeedRateStmt factory method
- """
- 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")]
- for input_rate, expected_output in inputs:
- stmt = ZAxisInfeedRateStmt.from_excellon(input_rate)
- 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"
- )
-
- line = "X0278207Y0065293"
- stmt = CoordinateStmt.from_excellon(line, settings)
- assert stmt.x == 2.78207
- assert stmt.y == 0.65293
-
- # line = 'X02945'
- # stmt = CoordinateStmt.from_excellon(line)
- # assert_equal(stmt.x, 2.945)
-
- # line = 'Y00575'
- # stmt = CoordinateStmt.from_excellon(line)
- # assert_equal(stmt.y, 0.575)
-
- settings = FileSettings(
- format=(2, 4), zero_suppression="leading", units="inch", notation="absolute"
- )
-
- line = "X9660Y4639"
- stmt = CoordinateStmt.from_excellon(line, settings)
- assert stmt.x == 0.9660
- assert stmt.y == 0.4639
- assert stmt.to_excellon(settings) == "X9660Y4639"
- assert stmt.units == "inch"
-
- settings.units = "metric"
- stmt = CoordinateStmt.from_excellon(line, settings)
- 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"
- )
- for line in lines:
- stmt = CoordinateStmt.from_excellon(line, settings)
- assert stmt.to_excellon(settings) == line
-
-
-def test_coordinatestmt_conversion():
-
- settings = FileSettings()
- settings.units = "metric"
- stmt = CoordinateStmt.from_excellon("X254Y254", settings)
-
- # No effect
- stmt.to_metric()
- assert stmt.x == 25.4
- assert stmt.y == 25.4
-
- stmt.to_inch()
- assert stmt.units == "inch"
- assert stmt.x == 1.0
- assert stmt.y == 1.0
-
- # No effect
- stmt.to_inch()
- assert stmt.x == 1.0
- assert stmt.y == 1.0
-
- settings.units = "inch"
- stmt = CoordinateStmt.from_excellon("X01Y01", settings)
-
- # No effect
- stmt.to_inch()
- assert stmt.x == 1.0
- assert stmt.y == 1.0
-
- stmt.to_metric()
- assert stmt.units == "metric"
- assert stmt.x == 25.4
- assert stmt.y == 25.4
-
- # No effect
- stmt.to_metric()
- assert stmt.x == 25.4
- assert stmt.y == 25.4
-
-
-def test_coordinatestmt_offset():
- stmt = CoordinateStmt.from_excellon("X01Y01", FileSettings())
- stmt.offset()
- assert stmt.x == 1
- assert stmt.y == 1
- stmt.offset(1, 0)
- assert stmt.x == 2.0
- assert stmt.y == 1.0
- stmt.offset(0, 1)
- 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 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 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 stmt.units == "metric"
-
-
-def test_repeatholestmt_dump():
- line = "R4X015Y32"
- stmt = RepeatHoleStmt.from_excellon(line, FileSettings())
- assert stmt.to_excellon(FileSettings()) == line
-
-
-def test_repeatholestmt_conversion():
- line = "R4X0254Y254"
- settings = FileSettings()
- settings.units = "metric"
- stmt = RepeatHoleStmt.from_excellon(line, settings)
-
- # No effect
- stmt.to_metric()
- assert stmt.xdelta == 2.54
- assert stmt.ydelta == 25.4
-
- stmt.to_inch()
- assert stmt.units == "inch"
- assert stmt.xdelta == 0.1
- assert stmt.ydelta == 1.0
-
- # no effect
- stmt.to_inch()
- assert stmt.xdelta == 0.1
- assert stmt.ydelta == 1.0
-
- line = "R4X01Y1"
- settings.units = "inch"
- stmt = RepeatHoleStmt.from_excellon(line, settings)
-
- # no effect
- stmt.to_inch()
- assert stmt.xdelta == 1.0
- assert stmt.ydelta == 10.0
-
- stmt.to_metric()
- assert stmt.units == "metric"
- assert stmt.xdelta == 25.4
- assert stmt.ydelta == 254.0
-
- # No effect
- stmt.to_metric()
- assert stmt.xdelta == 25.4
- assert stmt.ydelta == 254.0
-
-
-def test_repeathole_str():
- 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"
- stmt = CommentStmt.from_excellon(line)
- assert stmt.comment == line[1:]
-
- line = ";FILE_FORMAT=2:5"
- stmt = CommentStmt.from_excellon(line)
- assert stmt.comment == line[1:]
-
- line = ";TYPE=PLATED"
- stmt = CommentStmt.from_excellon(line)
- assert stmt.comment == line[1:]
-
-
-def test_commentstmt_dump():
- """ Test CommentStmt to_excellon()
- """
- lines = [";Layer_Color=9474304", ";FILE_FORMAT=2:5", ";TYPE=PLATED"]
- for line in lines:
- stmt = CommentStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_header_begin_stmt():
- stmt = HeaderBeginStmt()
- assert stmt.to_excellon(None) == "M48"
-
-
-def test_header_end_stmt():
- stmt = HeaderEndStmt()
- assert stmt.to_excellon(None) == "M95"
-
-
-def test_rewindstop_stmt():
- stmt = RewindStopStmt()
- assert stmt.to_excellon(None) == "%"
-
-
-def test_z_axis_rout_position_stmt():
- stmt = ZAxisRoutPositionStmt()
- assert stmt.to_excellon(None) == "M15"
-
-
-def test_retract_with_clamping_stmt():
- stmt = RetractWithClampingStmt()
- assert stmt.to_excellon(None) == "M16"
-
-
-def test_retract_without_clamping_stmt():
- stmt = RetractWithoutClampingStmt()
- assert stmt.to_excellon(None) == "M17"
-
-
-def test_cutter_compensation_off_stmt():
- stmt = CutterCompensationOffStmt()
- assert stmt.to_excellon(None) == "G40"
-
-
-def test_cutter_compensation_left_stmt():
- stmt = CutterCompensationLeftStmt()
- assert stmt.to_excellon(None) == "G41"
-
-
-def test_cutter_compensation_right_stmt():
- stmt = CutterCompensationRightStmt()
- assert stmt.to_excellon(None) == "G42"
-
-
-def test_endofprogramstmt_factory():
- 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"]
- for line in lines:
- stmt = EndOfProgramStmt.from_excellon(line, FileSettings())
- assert stmt.to_excellon(FileSettings()) == line
-
-
-def test_endofprogramstmt_conversion():
- settings = FileSettings()
- settings.units = "metric"
- stmt = EndOfProgramStmt.from_excellon("M30X0254Y254", settings)
- # No effect
- stmt.to_metric()
- assert stmt.x == 2.54
- assert stmt.y == 25.4
-
- stmt.to_inch()
- assert stmt.units == "inch"
- assert stmt.x == 0.1
- assert stmt.y == 1.0
-
- # No effect
- stmt.to_inch()
- assert stmt.x == 0.1
- assert stmt.y == 1.0
-
- settings.units = "inch"
- stmt = EndOfProgramStmt.from_excellon("M30X01Y1", settings)
-
- # No effect
- stmt.to_inch()
- assert stmt.x == 1.0
- assert stmt.y == 10.0
-
- stmt.to_metric()
- assert stmt.units == "metric"
- assert stmt.x == 25.4
- assert stmt.y == 254.0
-
- # No effect
- stmt.to_metric()
- assert stmt.x == 25.4
- assert stmt.y == 254.0
-
-
-def test_endofprogramstmt_offset():
- stmt = EndOfProgramStmt(1, 1)
- stmt.offset()
- assert stmt.x == 1
- assert stmt.y == 1
- stmt.offset(1, 0)
- assert stmt.x == 2.0
- assert stmt.y == 1.0
- stmt.offset(0, 1)
- assert stmt.x == 2.0
- assert stmt.y == 2.0
-
-
-def test_unitstmt_factory():
- """ Test UnitStmt factory method
- """
- line = "INCH,LZ"
- stmt = UnitStmt.from_excellon(line)
- assert stmt.units == "inch"
- assert stmt.zeros == "leading"
-
- line = "INCH,TZ"
- stmt = UnitStmt.from_excellon(line)
- assert stmt.units == "inch"
- assert stmt.zeros == "trailing"
-
- line = "METRIC,LZ"
- stmt = UnitStmt.from_excellon(line)
- assert stmt.units == "metric"
- assert stmt.zeros == "leading"
-
- line = "METRIC,TZ"
- stmt = UnitStmt.from_excellon(line)
- 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"]
- for line in lines:
- stmt = UnitStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_unitstmt_conversion():
- stmt = UnitStmt.from_excellon("METRIC,TZ")
- stmt.to_inch()
- assert stmt.units == "inch"
-
- stmt = UnitStmt.from_excellon("INCH,TZ")
- stmt.to_metric()
- assert stmt.units == "metric"
-
-
-def test_incrementalmode_factory():
- """ Test IncrementalModeStmt factory method
- """
- line = "ICI,ON"
- stmt = IncrementalModeStmt.from_excellon(line)
- assert stmt.mode == "on"
-
- line = "ICI,OFF"
- stmt = IncrementalModeStmt.from_excellon(line)
- assert stmt.mode == "off"
-
-
-def test_incrementalmode_dump():
- """ Test IncrementalModeStmt to_excellon()
- """
- lines = ["ICI,ON", "ICI,OFF"]
- for line in lines:
- stmt = IncrementalModeStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_incrementalmode_validation():
- """ Test IncrementalModeStmt input validation
- """
- pytest.raises(ValueError, IncrementalModeStmt, "OFF-ISH")
-
-
-def test_versionstmt_factory():
- """ Test VersionStmt factory method
- """
- line = "VER,1"
- stmt = VersionStmt.from_excellon(line)
- assert stmt.version == 1
-
- line = "VER,2"
- stmt = VersionStmt.from_excellon(line)
- assert stmt.version == 2
-
-
-def test_versionstmt_dump():
- """ Test VersionStmt to_excellon()
- """
- lines = ["VER,1", "VER,2"]
- for line in lines:
- stmt = VersionStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_versionstmt_validation():
- """ Test VersionStmt input validation
- """
- pytest.raises(ValueError, VersionStmt, 3)
-
-
-def test_formatstmt_factory():
- """ Test FormatStmt factory method
- """
- line = "FMAT,1"
- stmt = FormatStmt.from_excellon(line)
- assert stmt.format == 1
-
- line = "FMAT,2"
- stmt = FormatStmt.from_excellon(line)
- assert stmt.format == 2
-
-
-def test_formatstmt_dump():
- """ Test FormatStmt to_excellon()
- """
- lines = ["FMAT,1", "FMAT,2"]
- for line in lines:
- stmt = FormatStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_formatstmt_validation():
- """ Test FormatStmt input validation
- """
- pytest.raises(ValueError, FormatStmt, 3)
-
-
-def test_linktoolstmt_factory():
- """ Test LinkToolStmt factory method
- """
- line = "1/2/3/4"
- stmt = LinkToolStmt.from_excellon(line)
- assert stmt.linked_tools == [1, 2, 3, 4]
-
- line = "01/02/03/04"
- stmt = LinkToolStmt.from_excellon(line)
- assert stmt.linked_tools == [1, 2, 3, 4]
-
-
-def test_linktoolstmt_dump():
- """ Test LinkToolStmt to_excellon()
- """
- lines = ["1/2/3/4", "5/6/7"]
- for line in lines:
- stmt = LinkToolStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_measmodestmt_factory():
- """ Test MeasuringModeStmt factory method
- """
- line = "M72"
- stmt = MeasuringModeStmt.from_excellon(line)
- assert stmt.units == "inch"
-
- line = "M71"
- stmt = MeasuringModeStmt.from_excellon(line)
- assert stmt.units == "metric"
-
-
-def test_measmodestmt_dump():
- """ Test MeasuringModeStmt to_excellon()
- """
- lines = ["M71", "M72"]
- for line in lines:
- stmt = MeasuringModeStmt.from_excellon(line)
- assert stmt.to_excellon() == line
-
-
-def test_measmodestmt_validation():
- """ Test MeasuringModeStmt input validation
- """
- pytest.raises(ValueError, MeasuringModeStmt.from_excellon, "M70")
- pytest.raises(ValueError, MeasuringModeStmt, "millimeters")
-
-
-def test_measmodestmt_conversion():
- line = "M72"
- stmt = MeasuringModeStmt.from_excellon(line)
- assert stmt.units == "inch"
- stmt.to_metric()
- assert stmt.units == "metric"
-
- line = "M71"
- stmt = MeasuringModeStmt.from_excellon(line)
- assert stmt.units == "metric"
- stmt.to_inch()
- assert stmt.units == "inch"
-
-
-def test_routemode_stmt():
- stmt = RouteModeStmt()
- assert stmt.to_excellon(FileSettings()) == "G00"
-
-
-def test_linearmode_stmt():
- stmt = LinearModeStmt()
- assert stmt.to_excellon(FileSettings()) == "G01"
-
-
-def test_drillmode_stmt():
- stmt = DrillModeStmt()
- assert stmt.to_excellon(FileSettings()) == "G05"
-
-
-def test_absolutemode_stmt():
- stmt = AbsoluteModeStmt()
- assert stmt.to_excellon(FileSettings()) == "G90"
-
-
-def test_unknownstmt():
- stmt = UnknownStmt("TEST")
- assert stmt.stmt == "TEST"
- assert str(stmt) == "<Unknown Statement: TEST>"
-
-
-def test_unknownstmt_dump():
- stmt = UnknownStmt("TEST")
- assert stmt.to_excellon(FileSettings()) == "TEST"
diff --git a/gerbonara/gerber/tests/test_gerber_statements.py b/gerbonara/gerber/tests/test_gerber_statements.py
deleted file mode 100644
index 17e2591..0000000
--- a/gerbonara/gerber/tests/test_gerber_statements.py
+++ /dev/null
@@ -1,903 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-
-import pytest
-from ..gerber_statements import *
-from ..cam import FileSettings
-
-
-def test_Statement_smoketest():
- stmt = Statement("Test")
- assert stmt.type == "Test"
- stmt.to_metric()
- assert "units=metric" in str(stmt)
- stmt.to_inch()
- assert "units=inch" in str(stmt)
- stmt.to_metric()
- stmt.offset(1, 1)
- assert "type=Test" in str(stmt)
-
-
-def test_FSParamStmt_factory():
- """ Test FSParamStruct factory
- """
- stmt = {"param": "FS", "zero": "L", "notation": "A", "x": "27"}
- fs = FSParamStmt.from_dict(stmt)
- 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"}
- fs = FSParamStmt.from_dict(stmt)
- 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"
- fmt = (2, 5)
- stmt = FSParamStmt(param, zeros, notation, 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"}
- fs = FSParamStmt.from_dict(stmt)
- assert fs.to_gerber() == "%FSLAX27Y27*%"
-
- stmt = {"param": "FS", "zero": "T", "notation": "I", "x": "25"}
- fs = FSParamStmt.from_dict(stmt)
- assert fs.to_gerber() == "%FSTIX25Y25*%"
-
- 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"}
- fs = FSParamStmt.from_dict(stmt)
- assert str(fs) == "<Format Spec: 2:7 leading zero suppression absolute notation>"
-
- stmt = {"param": "FS", "zero": "T", "notation": "I", "x": "25"}
- fs = FSParamStmt.from_dict(stmt)
- 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"}]
- for stmt in stmts:
- mo = MOParamStmt.from_dict(stmt)
- assert mo.param == "MO"
- assert mo.mode == "inch"
-
- stmts = [{"param": "MO", "mo": "MM"}, {"param": "MO", "mo": "mm"}]
- for stmt in stmts:
- mo = MOParamStmt.from_dict(stmt)
- assert mo.param == "MO"
- assert mo.mode == "metric"
-
- stmt = {"param": "MO"}
- mo = 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"
- stmt = MOParamStmt(param, mode)
- assert stmt.param == param
-
- for mode in ["inch", "metric"]:
- stmt = MOParamStmt(param, mode)
- assert stmt.mode == mode
-
-
-def test_MOParamStmt_dump():
- """ Test MOParamStmt to_gerber()
- """
- stmt = {"param": "MO", "mo": "IN"}
- mo = MOParamStmt.from_dict(stmt)
- assert mo.to_gerber() == "%MOIN*%"
-
- stmt = {"param": "MO", "mo": "MM"}
- mo = MOParamStmt.from_dict(stmt)
- assert mo.to_gerber() == "%MOMM*%"
-
-
-def test_MOParamStmt_conversion():
- stmt = {"param": "MO", "mo": "MM"}
- mo = MOParamStmt.from_dict(stmt)
- mo.to_inch()
- assert mo.mode == "inch"
-
- stmt = {"param": "MO", "mo": "IN"}
- mo = MOParamStmt.from_dict(stmt)
- mo.to_metric()
- assert mo.mode == "metric"
-
-
-def test_MOParamStmt_string():
- """ Test MOParamStmt.__str__()
- """
- stmt = {"param": "MO", "mo": "IN"}
- mo = MOParamStmt.from_dict(stmt)
- assert str(mo) == "<Mode: inches>"
-
- stmt = {"param": "MO", "mo": "MM"}
- mo = MOParamStmt.from_dict(stmt)
- assert str(mo) == "<Mode: millimeters>"
-
-
-def test_IPParamStmt_factory():
- """ Test IPParamStruct factory
- """
- stmt = {"param": "IP", "ip": "POS"}
- ip = IPParamStmt.from_dict(stmt)
- assert ip.ip == "positive"
-
- stmt = {"param": "IP", "ip": "NEG"}
- ip = IPParamStmt.from_dict(stmt)
- assert ip.ip == "negative"
-
-
-def test_IPParamStmt():
- """ Test IPParamStmt initialization
- """
- param = "IP"
- for ip in ["positive", "negative"]:
- stmt = IPParamStmt(param, ip)
- assert stmt.param == param
- assert stmt.ip == ip
-
-
-def test_IPParamStmt_dump():
- """ Test IPParamStmt to_gerber()
- """
- stmt = {"param": "IP", "ip": "POS"}
- ip = IPParamStmt.from_dict(stmt)
- assert ip.to_gerber() == "%IPPOS*%"
-
- stmt = {"param": "IP", "ip": "NEG"}
- ip = IPParamStmt.from_dict(stmt)
- assert ip.to_gerber() == "%IPNEG*%"
-
-
-def test_IPParamStmt_string():
- stmt = {"param": "IP", "ip": "POS"}
- ip = IPParamStmt.from_dict(stmt)
- assert str(ip) == "<Image Polarity: positive>"
-
- stmt = {"param": "IP", "ip": "NEG"}
- ip = IPParamStmt.from_dict(stmt)
- assert str(ip) == "<Image Polarity: negative>"
-
-
-def test_IRParamStmt_factory():
- stmt = {"param": "IR", "angle": "45"}
- ir = IRParamStmt.from_dict(stmt)
- assert ir.param == "IR"
- assert ir.angle == 45
-
-
-def test_IRParamStmt_dump():
- stmt = {"param": "IR", "angle": "45"}
- ir = IRParamStmt.from_dict(stmt)
- assert ir.to_gerber() == "%IR45*%"
-
-
-def test_IRParamStmt_string():
- stmt = {"param": "IR", "angle": "45"}
- ir = IRParamStmt.from_dict(stmt)
- assert str(ir) == "<Image Angle: 45>"
-
-
-def test_OFParamStmt_factory():
- """ Test OFParamStmt factory
- """
- stmt = {"param": "OF", "a": "0.1234567", "b": "0.1234567"}
- of = OFParamStmt.from_dict(stmt)
- assert of.a == 0.1234567
- assert of.b == 0.1234567
-
-
-def test_OFParamStmt():
- """ Test IPParamStmt initialization
- """
- param = "OF"
- for val in [0.0, -3.4567]:
- stmt = OFParamStmt(param, val, 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"}
- of = OFParamStmt.from_dict(stmt)
- assert of.to_gerber() == "%OFA0.12345B0.12345*%"
-
-
-def test_OFParamStmt_conversion():
- stmt = {"param": "OF", "a": "2.54", "b": "25.4"}
- of = OFParamStmt.from_dict(stmt)
- of.units = "metric"
-
- # No effect
- of.to_metric()
- assert of.a == 2.54
- assert of.b == 25.4
-
- of.to_inch()
- assert of.units == "inch"
- assert of.a == 0.1
- assert of.b == 1.0
-
- # No effect
- of.to_inch()
- assert of.a == 0.1
- assert of.b == 1.0
-
- stmt = {"param": "OF", "a": "0.1", "b": "1.0"}
- of = OFParamStmt.from_dict(stmt)
- of.units = "inch"
-
- # No effect
- of.to_inch()
- assert of.a == 0.1
- assert of.b == 1.0
-
- of.to_metric()
- assert of.units == "metric"
- assert of.a == 2.54
- assert of.b == 25.4
-
- # No effect
- of.to_metric()
- assert of.a == 2.54
- assert of.b == 25.4
-
-
-def test_OFParamStmt_offset():
- s = OFParamStmt("OF", 0, 0)
- s.offset(1, 0)
- assert s.a == 1.0
- assert s.b == 0.0
- s.offset(0, 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"}
- of = OFParamStmt.from_dict(stmt)
- assert str(of) == "<Offset: X: 0.123456 Y: 0.123456 >"
-
-
-def test_SFParamStmt_factory():
- stmt = {"param": "SF", "a": "1.4", "b": "0.9"}
- sf = SFParamStmt.from_dict(stmt)
- 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"}
- sf = SFParamStmt.from_dict(stmt)
- assert sf.to_gerber() == "%SFA1.4B0.9*%"
-
-
-def test_SFParamStmt_conversion():
- stmt = {"param": "OF", "a": "2.54", "b": "25.4"}
- of = SFParamStmt.from_dict(stmt)
- of.units = "metric"
- of.to_metric()
-
- # No effect
- assert of.a == 2.54
- assert of.b == 25.4
-
- of.to_inch()
- assert of.units == "inch"
- assert of.a == 0.1
- assert of.b == 1.0
-
- # No effect
- of.to_inch()
- assert of.a == 0.1
- assert of.b == 1.0
-
- stmt = {"param": "OF", "a": "0.1", "b": "1.0"}
- of = SFParamStmt.from_dict(stmt)
- of.units = "inch"
-
- # No effect
- of.to_inch()
- assert of.a == 0.1
- assert of.b == 1.0
-
- of.to_metric()
- assert of.units == "metric"
- assert of.a == 2.54
- assert of.b == 25.4
-
- # No effect
- of.to_metric()
- assert of.a == 2.54
- assert of.b == 25.4
-
-
-def test_SFParamStmt_offset():
- s = SFParamStmt("OF", 0, 0)
- s.offset(1, 0)
- assert s.a == 1.0
- assert s.b == 0.0
- s.offset(0, 1)
- assert s.a == 1.0
- assert s.b == 1.0
-
-
-def test_SFParamStmt_string():
- stmt = {"param": "SF", "a": "1.4", "b": "0.9"}
- sf = SFParamStmt.from_dict(stmt)
- assert str(sf) == "<Scale Factor: X: 1.4 Y: 0.9>"
-
-
-def test_LPParamStmt_factory():
- """ Test LPParamStmt factory
- """
- stmt = {"param": "LP", "lp": "C"}
- lp = LPParamStmt.from_dict(stmt)
- assert lp.lp == "clear"
-
- stmt = {"param": "LP", "lp": "D"}
- lp = LPParamStmt.from_dict(stmt)
- assert lp.lp == "dark"
-
-
-def test_LPParamStmt_dump():
- """ Test LPParamStmt to_gerber()
- """
- stmt = {"param": "LP", "lp": "C"}
- lp = LPParamStmt.from_dict(stmt)
- assert lp.to_gerber() == "%LPC*%"
-
- stmt = {"param": "LP", "lp": "D"}
- lp = LPParamStmt.from_dict(stmt)
- assert lp.to_gerber() == "%LPD*%"
-
-
-def test_LPParamStmt_string():
- """ Test LPParamStmt.__str__()
- """
- stmt = {"param": "LP", "lp": "D"}
- lp = LPParamStmt.from_dict(stmt)
- assert str(lp) == "<Level Polarity: dark>"
-
- stmt = {"param": "LP", "lp": "C"}
- lp = LPParamStmt.from_dict(stmt)
- assert str(lp) == "<Level Polarity: clear>"
-
-
-def test_AMParamStmt_factory():
- 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*
-4,1,4,0.1,0.1,0.5,0.1,0.5,0.5,0.1,0.5,0.1,0.1,0*
-5,1,8,0,0,8,0*
-7,0,0,7,6,0.2,0*
-"""
- s = AMParamStmt.from_dict({"param": "AM", "name": name, "macro": macro}, units='mm')
- 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[5], AMOutlinePrimitive)
- assert isinstance(s.primitives[6], AMPolygonPrimitive)
- assert isinstance(s.primitives[8], AMThermalPrimitive)
-
-
-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}, units='mm')
- 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"}, units='mm')
- # 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}, units='mm')
- 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"}
- s = ASParamStmt.from_dict(stmt)
- assert s.param == "AS"
- assert s.mode == "AXBY"
-
-
-def test_ASParamStmt_dump():
- stmt = {"param": "AS", "mode": "AXBY"}
- s = ASParamStmt.from_dict(stmt)
- assert s.to_gerber() == "%ASAXBY*%"
-
-
-def test_ASParamStmt_string():
- stmt = {"param": "AS", "mode": "AXBY"}
- s = ASParamStmt.from_dict(stmt)
- assert str(s) == "<Axis Select: AXBY>"
-
-
-def test_INParamStmt_factory():
- """ Test INParamStmt factory
- """
- stmt = {"param": "IN", "name": "test"}
- inp = INParamStmt.from_dict(stmt)
- assert inp.name == "test"
-
-
-def test_INParamStmt_dump():
- """ Test INParamStmt to_gerber()
- """
- stmt = {"param": "IN", "name": "test"}
- inp = INParamStmt.from_dict(stmt)
- assert inp.to_gerber() == "%INtest*%"
-
-
-def test_INParamStmt_string():
- stmt = {"param": "IN", "name": "test"}
- inp = INParamStmt.from_dict(stmt)
- assert str(inp) == "<Image Name: test>"
-
-
-def test_LNParamStmt_factory():
- """ Test LNParamStmt factory
- """
- stmt = {"param": "LN", "name": "test"}
- lnp = LNParamStmt.from_dict(stmt)
- assert lnp.name == "test"
-
-
-def test_LNParamStmt_dump():
- """ Test LNParamStmt to_gerber()
- """
- stmt = {"param": "LN", "name": "test"}
- lnp = LNParamStmt.from_dict(stmt)
- assert lnp.to_gerber() == "%LNtest*%"
-
-
-def test_LNParamStmt_string():
- stmt = {"param": "LN", "name": "test"}
- lnp = LNParamStmt.from_dict(stmt)
- assert str(lnp) == "<Level Name: test>"
-
-
-def test_comment_stmt():
- """ Test comment statement
- """
- 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 stmt.to_gerber() == "G04A comment*"
-
-
-def test_comment_stmt_string():
- stmt = CommentStmt("A comment")
- assert str(stmt) == "<Comment: A comment>"
-
-
-def test_eofstmt():
- """ Test EofStmt
- """
- stmt = EofStmt()
- assert stmt.type == "EOF"
-
-
-def test_eofstmt_dump():
- """ Test EofStmt to_gerber()
- """
- stmt = EofStmt()
- assert stmt.to_gerber() == "M02*"
-
-
-def test_eofstmt_string():
- assert str(EofStmt()) == "<EOF Statement>"
-
-
-def test_quadmodestmt_factory():
- """ Test QuadrantModeStmt.from_gerber()
- """
- line = "G74*"
- stmt = QuadrantModeStmt.from_gerber(line)
- assert stmt.type == "QuadrantMode"
- assert stmt.mode == "single-quadrant"
-
- line = "G75*"
- stmt = QuadrantModeStmt.from_gerber(line)
- assert stmt.mode == "multi-quadrant"
-
-
-def test_quadmodestmt_validation():
- """ Test QuadrantModeStmt input validation
- """
- 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*"):
- stmt = QuadrantModeStmt.from_gerber(line)
- assert stmt.to_gerber() == line
-
-
-def test_regionmodestmt_factory():
- """ Test RegionModeStmt.from_gerber()
- """
- line = "G36*"
- stmt = RegionModeStmt.from_gerber(line)
- assert stmt.type == "RegionMode"
- assert stmt.mode == "on"
-
- line = "G37*"
- stmt = RegionModeStmt.from_gerber(line)
- assert stmt.mode == "off"
-
-
-def test_regionmodestmt_validation():
- """ Test RegionModeStmt input validation
- """
- 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*"):
- stmt = RegionModeStmt.from_gerber(line)
- assert stmt.to_gerber() == line
-
-
-def test_unknownstmt():
- """ Test UnknownStmt
- """
- line = "G696969*"
- stmt = UnknownStmt(line)
- assert stmt.type == "UNKNOWN"
- assert stmt.line == line
-
-
-def test_unknownstmt_dump():
- """ Test UnknownStmt.to_gerber()
- """
- lines = ("G696969*", "M03*")
- for line in lines:
- stmt = UnknownStmt(line)
- assert stmt.to_gerber() == line
-
-
-def test_statement_string():
- """ Test Statement.__str__()
- """
- 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"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.d == 0
- assert ad.shape == "C"
-
- stmt = {"param": "AD", "d": 1, "shape": "R"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.d == 1
- assert ad.shape == "R"
-
- stmt = {"param": "AD", "d": 1, "shape": "C", "modifiers": "1.42"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.d == 1
- assert ad.shape == "C"
- assert ad.modifiers == [(1.42,)]
-
- stmt = {"param": "AD", "d": 1, "shape": "C", "modifiers": "1.42X"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.d == 1
- assert ad.shape == "C"
- assert ad.modifiers == [(1.42,)]
-
- stmt = {"param": "AD", "d": 1, "shape": "R", "modifiers": "1.42X1.24"}
- ad = ADParamStmt.from_dict(stmt)
- 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"}
- ad = ADParamStmt.from_dict(stmt)
- ad.units = "metric"
-
- # No effect
- ad.to_metric()
- assert ad.modifiers[0] == (25.4, 25.4)
- assert ad.modifiers[1] == (25.4, 25.4)
-
- ad.to_inch()
- 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 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"}
- ad = ADParamStmt.from_dict(stmt)
- ad.units = "inch"
-
- # No effect
- ad.to_inch()
- assert ad.modifiers[0] == (1.0, 1.0)
- assert ad.modifiers[1] == (1.0, 1.0)
-
- ad.to_metric()
- assert ad.modifiers[0] == (25.4, 25.4)
- assert ad.modifiers[1] == (25.4, 25.4)
-
- # No effect
- ad.to_metric()
- 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"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.to_gerber() == "%ADD0C*%"
- stmt = {"param": "AD", "d": 0, "shape": "C", "modifiers": "1X1,1X1"}
- ad = ADParamStmt.from_dict(stmt)
- assert ad.to_gerber() == "%ADD0C,1X1,1X1*%"
-
-
-def test_ADPamramStmt_string():
- stmt = {"param": "AD", "d": 0, "shape": "C"}
- ad = ADParamStmt.from_dict(stmt)
- assert str(ad) == "<Aperture Definition: 0: circle>"
-
- stmt = {"param": "AD", "d": 0, "shape": "R"}
- ad = ADParamStmt.from_dict(stmt)
- assert str(ad) == "<Aperture Definition: 0: rectangle>"
-
- stmt = {"param": "AD", "d": 0, "shape": "O"}
- ad = ADParamStmt.from_dict(stmt)
- assert str(ad) == "<Aperture Definition: 0: obround>"
-
- stmt = {"param": "AD", "d": 0, "shape": "test"}
- ad = ADParamStmt.from_dict(stmt)
- assert str(ad) == "<Aperture Definition: 0: test>"
-
-
-def test_MIParamStmt_factory():
- stmt = {"param": "MI", "a": 1, "b": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert mi.a == 1
- assert mi.b == 1
-
-
-def test_MIParamStmt_dump():
- stmt = {"param": "MI", "a": 1, "b": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert mi.to_gerber() == "%MIA1B1*%"
- stmt = {"param": "MI", "a": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert mi.to_gerber() == "%MIA1B0*%"
- stmt = {"param": "MI", "b": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert mi.to_gerber() == "%MIA0B1*%"
-
-
-def test_MIParamStmt_string():
- stmt = {"param": "MI", "a": 1, "b": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert str(mi) == "<Image Mirror: A=1 B=1>"
-
- stmt = {"param": "MI", "b": 1}
- mi = MIParamStmt.from_dict(stmt)
- assert str(mi) == "<Image Mirror: A=0 B=1>"
-
- stmt = {"param": "MI", "a": 1}
- mi = MIParamStmt.from_dict(stmt)
- 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 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",
- }
- cs = CoordStmt.from_dict(stmt, 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_dump():
- 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"
-
- # No effect
- cs.to_metric()
- 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 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 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.0, 1.0, 1.0, 1.0, "D01", FileSettings())
- cs.units = "inch"
-
- # No effect
- cs.to_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"
-
- cs.to_metric()
- 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 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.offset(1, 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 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 (
- 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 ast.d == 3
- assert ast.deprecated == False
- ast = ApertureStmt(4, True)
- assert ast.d == 4
- assert ast.deprecated == True
- ast = ApertureStmt(4, 1)
- assert ast.d == 4
- assert ast.deprecated == True
- ast = ApertureStmt(3)
- assert ast.d == 3
- assert ast.deprecated == False
-
-
-def test_aperturestmt_dump():
- ast = ApertureStmt(3, False)
- assert ast.to_gerber() == "D3*"
- ast = ApertureStmt(3, True)
- assert ast.to_gerber() == "G54D3*"
- assert str(ast) == "<Aperture: 3>"
diff --git a/gerbonara/gerber/tests/test_primitives.py b/gerbonara/gerber/tests/test_primitives.py
deleted file mode 100644
index 3f8df51..0000000
--- a/gerbonara/gerber/tests/test_primitives.py
+++ /dev/null
@@ -1,897 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-
-import pytest
-from operator import add
-from ..primitives import *
-
-
-def test_primitive_smoketest():
- p = Primitive()
- try:
- p.bounding_box
- assert not True, "should have thrown the exception"
- except NotImplementedError:
- pass
- # pytest.raises(NotImplementedError, p.bounding_box)
-
- p.to_metric()
- p.to_inch()
- # try:
- # p.offset(1, 1)
- # assert_false(True, 'should have thrown the exception')
- # 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)),
- ]
- for start, end, expected in cases:
- l = Line(start, end, 0)
- line_angle = (l.angle + 2 * math.pi) % (2 * math.pi)
- pytest.approx(line_angle, expected)
-
-
-def test_line_bounds():
- """ Test Line primitive bounding box calculation
- """
- cases = [
- ((0, 0), (1, 1), ((-1, -1), (2, 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 l.bounding_box == expected
- # Test a non-square rectangle
- r = Rectangle((0, 0), 3, 2)
- cases = [
- ((0, 0), (1, 1), ((-1.5, -1), (2.5, 2))),
- ((-1, -1), (1, 1), ((-2.5, -2), (2.5, 2))),
- ((1, 1), (-1, -1), ((-2.5, -2), (2.5, 2))),
- ((-1, 1), (1, -1), ((-2.5, -2), (2.5, 2))),
- ]
- for start, end, expected in cases:
- l = Line(start, end, r)
- assert l.bounding_box == expected
-
-
-def test_line_vertices():
- c = Circle((0, 0), 2)
- l = Line((0, 0), (1, 1), c)
- 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))),
- ]
- r = Rectangle((0, 0), 2, 2)
-
- for start, end, vertices in test_cases:
- l = Line(start, end, r)
- 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")
-
- # No effect
- l.to_metric()
- assert l.start == (2.54, 25.4)
- assert l.end == (254.0, 2540.0)
- assert l.aperture.diameter == 25.4
-
- l.to_inch()
- 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 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")
-
- # No effect
- l.to_inch()
- assert l.start == (0.1, 1.0)
- assert l.end == (10.0, 100.0)
- assert l.aperture.diameter == 1.0
-
- l.to_metric()
- 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 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")
- l.to_inch()
- 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")
- l.to_metric()
- 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 l.start == (1.0, 0.0)
- assert l.end == (2.0, 1.0)
- l.offset(0, 1)
- 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)]
-
- for start, end, center, radius in cases:
- 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)),
- ]
-
- for start, end, center, direction, sweep in cases:
- 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, -0.5), (1.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, -1.5), (0.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))),
- ]
- for start, end, center, direction, bounds in cases:
- 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, 0.0), (1.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, -1.0), (0.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))),
- ]
- for start, end, center, direction, bounds in cases:
- 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",
- )
-
- # No effect
- a.to_metric()
- 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 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 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 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.offset(1, 0)
- 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 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 c.radius == 1
-
-
-def test_circle_hole_radius():
- """ Test Circle primitive hole radius calculation
- """
- c = Circle((1, 1), 4, 2)
- assert c.hole_radius == 1
-
-
-def test_circle_bounds():
- """ Test Circle bounding box calculation
- """
- c = Circle((1, 1), 2)
- assert c.bounding_box == ((0, 0), (2, 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.to_metric() # shouldn't do antyhing
- assert c.position == (2.54, 25.4)
- assert c.diameter == 254.0
- assert c.hole_diameter == None
-
- c.to_inch()
- assert c.position == (0.1, 1.0)
- assert c.diameter == 10.0
- assert c.hole_diameter == None
-
- # no effect
- c.to_inch()
- 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.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 c.position == (0.1, 1.0)
- assert c.diameter == 10.0
- assert c.hole_diameter == 5.0
-
- # no effect
- c.to_inch()
- 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")
- # No effect
- c.to_inch()
- assert c.position == (0.1, 1.0)
- assert c.diameter == 10.0
- assert c.hole_diameter == None
-
- c.to_metric()
- assert c.position == (2.54, 25.4)
- assert c.diameter == 254.0
- assert c.hole_diameter == None
-
- # no effect
- c.to_metric()
- 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.to_inch()
- assert c.position == (0.1, 1.0)
- assert c.diameter == 10.0
- assert c.hole_diameter == 5.0
-
- c.to_metric()
- assert c.position == (2.54, 25.4)
- assert c.diameter == 254.0
- assert c.hole_diameter == 127.0
-
- # no effect
- c.to_metric()
- 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 c.position == (1.0, 0.0)
- c.offset(0, 1)
- assert c.position == (1.0, 1.0)
-
-
-def test_rectangle_ctor():
- """ Test rectangle creation
- """
- 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 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 0 == r.hole_radius
-
- r = Rectangle((0, 0), 2, 2, 1)
- assert 0.5 == r.hole_radius
-
-
-def test_rectangle_bounds():
- """ Test rectangle bounding box calculation
- """
- r = Rectangle((0, 0), 2, 2)
- bounds = r.bounding_box
- pytest.approx(bounds[0], (-1, -1))
- pytest.approx(bounds[1], (1, 1))
- r = Rectangle((0, 0), 2, 2, rotation=45)
- bounds = r.bounding_box
- pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2)))
- pytest.approx(bounds[1], (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)),
- ),
- ]
- 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)):
- 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))),
- ):
- 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 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.to_metric()
- assert r.position == (2.54, 25.4)
- assert r.width == 254.0
- assert r.height == 2540.0
-
- r.to_inch()
- assert r.position == (0.1, 1.0)
- assert r.width == 10.0
- assert r.height == 100.0
-
- r.to_inch()
- 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.to_metric()
- 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 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 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.to_inch()
- assert r.position == (0.1, 1.0)
- assert r.width == 10.0
- assert r.height == 100.0
-
- r.to_metric()
- assert r.position == (2.54, 25.4)
- assert r.width == 254.0
- assert r.height == 2540.0
-
- r.to_metric()
- 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.to_inch()
- 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 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 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 r.position == (1.0, 0.0)
- r.offset(0, 1)
- assert r.position == (1.0, 1.0)
-
-
-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)),
- )
- for pos, width, height, radius, corners in test_cases:
- r = RoundRectangle(pos, width, height, radius, 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():
- """ Test round rectangle bounding box calculation
- """
- r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False))
- bounds = r.bounding_box
- pytest.approx(bounds[0], (-1, -1))
- pytest.approx(bounds[1], (1, 1))
- r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45)
- bounds = r.bounding_box
- pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2)))
- pytest.approx(bounds[1], (math.sqrt(2), math.sqrt(2)))
-
-
-def test_obround_ctor():
- """ Test obround creation
- """
- 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 o.position == pos
- assert o.width == width
- assert o.height == height
-
-
-def test_obround_bounds():
- """ Test obround bounding box calculation
- """
- o = Obround((2, 2), 2, 4)
- bounds = o.bounding_box
- pytest.approx(bounds[0], (1, 0))
- pytest.approx(bounds[1], (3, 4))
- o = Obround((2, 2), 4, 2)
- bounds = o.bounding_box
- pytest.approx(bounds[0], (0, 1))
- pytest.approx(bounds[1], (4, 3))
-
-
-def test_obround_orientation():
- o = Obround((0, 0), 2, 1)
- assert o.orientation == "horizontal"
- o = Obround((0, 0), 1, 2)
- assert o.orientation == "vertical"
-
-
-def test_obround_subshapes():
- o = Obround((0, 0), 1, 4)
- ss = o.subshapes
- 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
- 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")
-
- # No effect
- o.to_metric()
- assert o.position == (2.54, 25.4)
- assert o.width == 254.0
- assert o.height == 2540.0
-
- o.to_inch()
- assert o.position == (0.1, 1.0)
- assert o.width == 10.0
- assert o.height == 100.0
-
- # No effect
- o.to_inch()
- 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")
-
- # No effect
- o.to_inch()
- assert o.position == (0.1, 1.0)
- assert o.width == 10.0
- assert o.height == 100.0
-
- o.to_metric()
- assert o.position == (2.54, 25.4)
- assert o.width == 254.0
- assert o.height == 2540.0
-
- # No effect
- o.to_metric()
- 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 o.position == (1.0, 0.0)
- o.offset(0, 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))
- for pos, sides, radius, hole_diameter in test_cases:
- p = Polygon(pos, sides, radius, hole_diameter)
- assert p.position == pos
- assert p.sides == sides
- assert p.radius == radius
- assert p.hole_diameter == hole_diameter
-
-
-def test_polygon_bounds():
- """ Test polygon bounding box calculation
- """
- p = Polygon((2, 2), 3, 2, 0)
- bounds = p.bounding_box
- pytest.approx(bounds[0], (0, 0))
- pytest.approx(bounds[0], (4, 4))
- p = Polygon((2, 2), 3, 4, 0)
- bounds = p.bounding_box
- pytest.approx(bounds[0], (-2, -2))
- pytest.approx(bounds[1], (6, 6))
-
-
-def test_polygon_conversion():
- p = Polygon((2.54, 25.4), 3, 254.0, 0, units="metric")
-
- # No effect
- p.to_metric()
- assert p.position == (2.54, 25.4)
- assert p.radius == 254.0
-
- p.to_inch()
- assert p.position == (0.1, 1.0)
- assert p.radius == 10.0
-
- # No effect
- p.to_inch()
- assert p.position == (0.1, 1.0)
- assert p.radius == 10.0
-
- p = Polygon((0.1, 1.0), 3, 10.0, 0, units="inch")
-
- # No effect
- p.to_inch()
- assert p.position == (0.1, 1.0)
- assert p.radius == 10.0
-
- p.to_metric()
- assert p.position == (2.54, 25.4)
- assert p.radius == 254.0
-
- # No effect
- p.to_metric()
- 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 p.position == (1.0, 0.0)
- p.offset(0, 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),
- )
- points = ((0, 0), (1, 0), (1, 1), (0, 1))
- r = Region(lines)
- for i, p in enumerate(lines):
- 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),
- )
- r = Region(lines)
- bounds = r.bounding_box
- pytest.approx(bounds[0], (0, 0))
- pytest.approx(bounds[1], (1, 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),
- )
- r = Region(lines)
- xlim, ylim = r.bounding_box
- r.offset(0, 1)
- new_xlim, new_ylim = r.bounding_box
- pytest.approx(new_xlim, xlim)
- pytest.approx(new_ylim, tuple([y + 1 for y in ylim]))
-
-
-def test_drill_ctor():
- """ Test drill primitive creation
- """
- test_cases = (((0, 0), 2), ((1, 1), 3), ((2, 2), 5))
- for position, diameter in test_cases:
- d = Drill(position, diameter)
- assert d.position == position
- assert d.diameter == diameter
- assert d.radius == diameter / 2.0
-
-
-def test_drill_ctor_validation():
- """ Test drill argument validation
- """
- pytest.raises(TypeError, Drill, 3, 5)
- pytest.raises(TypeError, Drill, (3, 4, 5), 5)
-
-
-def test_drill_bounds():
- d = Drill((0, 0), 2)
- bounds = d.bounding_box
- pytest.approx(bounds[0], (-1, -1))
- pytest.approx(bounds[1], (1, 1))
- d = Drill((1, 2), 2)
- bounds = d.bounding_box
- pytest.approx(bounds[0], (0, 1))
- pytest.approx(bounds[1], (2, 3))
-
-
-def test_drill_conversion():
- d = Drill((2.54, 25.4), 254.0, units="metric")
-
- # No effect
- d.to_metric()
- assert d.position == (2.54, 25.4)
- assert d.diameter == 254.0
-
- d.to_inch()
- assert d.position == (0.1, 1.0)
- assert d.diameter == 10.0
-
- # No effect
- d.to_inch()
- assert d.position == (0.1, 1.0)
- assert d.diameter == 10.0
-
- d = Drill((0.1, 1.0), 10.0, units="inch")
-
- # No effect
- d.to_inch()
- assert d.position == (0.1, 1.0)
- assert d.diameter == 10.0
-
- d.to_metric()
- assert d.position == (2.54, 25.4)
- assert d.diameter == 254.0
-
- # No effect
- d.to_metric()
- assert d.position == (2.54, 25.4)
- assert d.diameter == 254.0
-
-
-def test_drill_offset():
- d = Drill((0, 0), 1.0)
- d.offset(1, 0)
- assert d.position == (1.0, 0.0)
- d.offset(0, 1)
- assert d.position == (1.0, 1.0)
-
-
-def test_drill_equality():
- 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 d != d1
-
-
-def test_slot_bounds():
- """ Test Slot primitive bounding box calculation
- """
- cases = [
- (( 0, 0), ( 1, 1), ((-1, -1), (2, 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 s.bounding_box == expected
-