From 18e3b87625ddb739faeddffcaed48e12db6c7e8b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 19 Oct 2014 22:23:00 -0400 Subject: Test update --- gerber/tests/test_excellon.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 gerber/tests/test_excellon.py (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py new file mode 100644 index 0000000..72e3d7d --- /dev/null +++ b/gerber/tests/test_excellon.py @@ -0,0 +1,32 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe +from ..excellon import read, detect_excellon_format, ExcellonFile +from tests import * + +import os + +NCDRILL_FILE = os.path.join(os.path.dirname(__file__), + 'resources/ncdrill.DRD') + +def test_format_detection(): + """ Test file type detection + """ + settings = detect_excellon_format(NCDRILL_FILE) + assert_equal(settings['format'], (2, 4)) + assert_equal(settings['zero_suppression'], 'leading') + +def test_read(): + ncdrill = read(NCDRILL_FILE) + assert(isinstance(ncdrill, ExcellonFile)) + +def test_read_settings(): + ncdrill = read(NCDRILL_FILE) + assert_equal(ncdrill.settings.format, (2, 4)) + assert_equal(ncdrill.settings.zero_suppression, 'leading') + + + + + -- cgit From b495d51354eff7b858dbbd41740865eba7f39100 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 25 Jan 2015 14:19:48 -0500 Subject: Changed zeros/zero suppression conventions to match file format specs --- gerber/tests/test_excellon.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 72e3d7d..70e4560 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -15,18 +15,13 @@ def test_format_detection(): """ settings = detect_excellon_format(NCDRILL_FILE) assert_equal(settings['format'], (2, 4)) - assert_equal(settings['zero_suppression'], 'leading') + assert_equal(settings['zeros'], 'trailing') def test_read(): ncdrill = read(NCDRILL_FILE) assert(isinstance(ncdrill, ExcellonFile)) - + def test_read_settings(): ncdrill = read(NCDRILL_FILE) - assert_equal(ncdrill.settings.format, (2, 4)) - assert_equal(ncdrill.settings.zero_suppression, 'leading') - - - - - + assert_equal(ncdrill.settings['format'], (2, 4)) + assert_equal(ncdrill.settings['zeros'], 'trailing') -- cgit From 5cf1fa74b42eb8feaab23078bef6f31f6d647c33 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 15 Feb 2015 02:20:02 -0500 Subject: Tests and bugfixes --- gerber/tests/test_excellon.py | 112 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 70e4560..de45b44 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe -from ..excellon import read, detect_excellon_format, ExcellonFile +from ..cam import FileSettings +from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from tests import * import os @@ -25,3 +26,112 @@ def test_read_settings(): ncdrill = read(NCDRILL_FILE) assert_equal(ncdrill.settings['format'], (2, 4)) assert_equal(ncdrill.settings['zeros'], 'trailing') + +def test_bounds(): + ncdrill = read(NCDRILL_FILE) + xbound, ybound = ncdrill.bounds + assert_array_almost_equal(xbound, (0.1300, 2.1430)) + assert_array_almost_equal(ybound, (0.3946, 1.7164)) + +def test_report(): + ncdrill = read(NCDRILL_FILE) + +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) + +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]) + +def test_parse_whitespace(): + p = ExcellonParser(FileSettings()) + assert_equal(p._parse(' '), None) + +def test_parse_comment(): + p = ExcellonParser(FileSettings()) + p._parse(';A comment') + assert_equal(p.statements[0].comment, 'A comment') + +def test_parse_format_comment(): + p = ExcellonParser(FileSettings()) + p._parse('; FILE_FORMAT=9:9 ') + assert_equal(p.format, (9, 9)) + +def test_parse_header(): + p = ExcellonParser(FileSettings()) + p._parse('M48 ') + assert_equal(p.state, 'HEADER') + p._parse('M95 ') + assert_equal(p.state, 'DRILL') + +def test_parse_rout(): + p = ExcellonParser(FileSettings()) + p._parse('G00 ') + assert_equal(p.state, 'ROUT') + p._parse('G05 ') + assert_equal(p.state, 'DRILL') + +def test_parse_version(): + p = ExcellonParser(FileSettings()) + p._parse('VER,1 ') + assert_equal(p.statements[0].version, 1) + p._parse('VER,2 ') + assert_equal(p.statements[1].version, 2) + +def test_parse_format(): + p = ExcellonParser(FileSettings()) + p._parse('FMAT,1 ') + assert_equal(p.statements[0].format, 1) + p._parse('FMAT,2 ') + assert_equal(p.statements[1].format, 2) + +def test_parse_units(): + settings = FileSettings(units='inch', zeros='trailing') + p = ExcellonParser(settings) + p._parse(';METRIC,LZ') + assert_equal(p.units, 'inch') + assert_equal(p.zeros, 'trailing') + p._parse('METRIC,LZ') + assert_equal(p.units, 'metric') + assert_equal(p.zeros, 'leading') + +def test_parse_incremental_mode(): + settings = FileSettings(units='inch', zeros='trailing') + p = ExcellonParser(settings) + assert_equal(p.notation, 'absolute') + p._parse('ICI,ON ') + assert_equal(p.notation, 'incremental') + p._parse('ICI,OFF ') + assert_equal(p.notation, 'absolute') + +def test_parse_absolute_mode(): + settings = FileSettings(units='inch', zeros='trailing') + p = ExcellonParser(settings) + assert_equal(p.notation, 'absolute') + p._parse('ICI,ON ') + assert_equal(p.notation, 'incremental') + p._parse('G90 ') + assert_equal(p.notation, 'absolute') + +def test_parse_repeat_hole(): + p = ExcellonParser(FileSettings()) + p._parse('R03X1.5Y1.5') + assert_equal(p.statements[0].count, 3) + +def test_parse_incremental_position(): + p = ExcellonParser(FileSettings(notation='incremental')) + p._parse('X01Y01') + p._parse('X01Y01') + assert_equal(p.pos, [2.,2.]) + +def test_parse_unknown(): + p = ExcellonParser(FileSettings()) + p._parse('Not A Valid Statement') + assert_equal(p.statements[0].stmt, 'Not A Valid Statement') + + -- cgit From bfe14841604b6be403e7123e8b6667b1f0aff6f6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 15 Feb 2015 03:29:47 -0500 Subject: Add cairo example code, and use example-generated image in readme --- gerber/tests/test_excellon.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index de45b44..ea067b5 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -4,6 +4,7 @@ # Author: Hamilton Kibbe from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser +from ..excellon_statements import ExcellonTool from tests import * import os @@ -120,6 +121,7 @@ def test_parse_absolute_mode(): def test_parse_repeat_hole(): p = ExcellonParser(FileSettings()) + p.active_tool = ExcellonTool(FileSettings(), number=8) p._parse('R03X1.5Y1.5') assert_equal(p.statements[0].count, 3) -- cgit From 288ac27084b47166ac662402ea340d0aa25d8f56 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 04:31:23 -0500 Subject: Get unit conversion working for Gerber/Excellon files Started operations module for file operations/transforms --- gerber/tests/test_excellon.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index ea067b5..24cf793 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -2,12 +2,13 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe +import os + from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from ..excellon_statements import ExcellonTool from tests import * -import os NCDRILL_FILE = os.path.join(os.path.dirname(__file__), 'resources/ncdrill.DRD') @@ -37,6 +38,29 @@ def test_bounds(): def test_report(): ncdrill = read(NCDRILL_FILE) + +def test_conversion(): + import copy + ncdrill = read(NCDRILL_FILE) + assert_equal(ncdrill.settings.units, 'inch') + ncdrill_inch = copy.deepcopy(ncdrill) + ncdrill.to_metric() + assert_equal(ncdrill.settings.units, 'metric') + + for tool in ncdrill_inch.tools.itervalues(): + tool.to_metric() + for primitive in ncdrill_inch.primitives: + primitive.to_metric() + for statement in ncdrill_inch.statements: + statement.to_metric() + + for m_tool, i_tool in zip(ncdrill.tools.itervalues(), ncdrill_inch.tools.itervalues()): + assert_equal(i_tool, m_tool) + + for m, i in zip(ncdrill.primitives,ncdrill_inch.primitives): + assert_equal(m, i) + + def test_parser_hole_count(): settings = FileSettings(**detect_excellon_format(NCDRILL_FILE)) p = ExcellonParser(settings) -- cgit From e71d7a24b5be3e68d36494869595eec934db4bd2 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 21:14:30 -0500 Subject: Python 3 tests passing --- gerber/tests/test_excellon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 24cf793..d47ad6a 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -7,7 +7,7 @@ import os from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from ..excellon_statements import ExcellonTool -from tests import * +from .tests import * NCDRILL_FILE = os.path.join(os.path.dirname(__file__), @@ -47,14 +47,14 @@ def test_conversion(): ncdrill.to_metric() assert_equal(ncdrill.settings.units, 'metric') - for tool in ncdrill_inch.tools.itervalues(): + for tool in iter(ncdrill_inch.tools.values()): tool.to_metric() for primitive in ncdrill_inch.primitives: primitive.to_metric() for statement in ncdrill_inch.statements: statement.to_metric() - for m_tool, i_tool in zip(ncdrill.tools.itervalues(), ncdrill_inch.tools.itervalues()): + for m_tool, i_tool in zip(iter(ncdrill.tools.values()), iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) for m, i in zip(ncdrill.primitives,ncdrill_inch.primitives): -- cgit From 94f3976915d64a77135a1fdc8983085ee8d2e1f9 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 11 Jun 2015 11:20:56 -0400 Subject: Add keys to statements for linking to primitives. Add some API features to ExcellonFile, such as getting a tool path length and changing tool parameters. Excellonfiles write method generates statements based on the drill hits in the hits member, so drill hits in a generated file can be re-ordered by re-ordering the drill hits in ExcellonFile.hits. see #30 --- gerber/tests/test_excellon.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index d47ad6a..006277d 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -24,6 +24,17 @@ def test_read(): ncdrill = read(NCDRILL_FILE) assert(isinstance(ncdrill, ExcellonFile)) +def test_write(): + ncdrill = read(NCDRILL_FILE) + ncdrill.write('test.ncd') + with open(NCDRILL_FILE) as src: + srclines = src.readlines() + + with open('test.ncd') as res: + for idx, line in enumerate(res): + assert_equal(line.strip(), srclines[idx].strip()) + os.remove('test.ncd') + def test_read_settings(): ncdrill = read(NCDRILL_FILE) assert_equal(ncdrill.settings['format'], (2, 4)) @@ -47,9 +58,11 @@ def test_conversion(): ncdrill.to_metric() assert_equal(ncdrill.settings.units, 'metric') + inch_primitives = ncdrill_inch.primitives + for tool in iter(ncdrill_inch.tools.values()): tool.to_metric() - for primitive in ncdrill_inch.primitives: + for primitive in inch_primitives: primitive.to_metric() for statement in ncdrill_inch.statements: statement.to_metric() @@ -57,7 +70,7 @@ def test_conversion(): for m_tool, i_tool in zip(iter(ncdrill.tools.values()), iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) - for m, i in zip(ncdrill.primitives,ncdrill_inch.primitives): + for m, i in zip(ncdrill.primitives,inch_primitives): assert_equal(m, i) -- cgit From dd63b169f177389602e17bc6ced53bd0f1ba0de3 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 10 Oct 2015 16:51:21 -0400 Subject: Allow files to be read from strings per #37 Adds a loads() method to the top level module which generates a GerberFile or ExcellonFile from a string --- gerber/tests/test_excellon.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 006277d..b821649 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -11,41 +11,51 @@ from .tests import * NCDRILL_FILE = os.path.join(os.path.dirname(__file__), - 'resources/ncdrill.DRD') + 'resources/ncdrill.DRD') def test_format_detection(): """ Test file type detection """ - settings = detect_excellon_format(NCDRILL_FILE) + with open(NCDRILL_FILE) as f: + data = f.read() + settings = detect_excellon_format(data) assert_equal(settings['format'], (2, 4)) assert_equal(settings['zeros'], 'trailing') + settings = detect_excellon_format(filename=NCDRILL_FILE) + assert_equal(settings['format'], (2, 4)) + assert_equal(settings['zeros'], 'trailing') + + def test_read(): ncdrill = read(NCDRILL_FILE) assert(isinstance(ncdrill, ExcellonFile)) + def test_write(): ncdrill = read(NCDRILL_FILE) ncdrill.write('test.ncd') with open(NCDRILL_FILE) as src: - srclines = src.readlines() - + srclines = src.readlines() with open('test.ncd') as res: - for idx, line in enumerate(res): - assert_equal(line.strip(), srclines[idx].strip()) + for idx, line in enumerate(res): + assert_equal(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') + def test_bounds(): ncdrill = read(NCDRILL_FILE) xbound, ybound = ncdrill.bounds assert_array_almost_equal(xbound, (0.1300, 2.1430)) assert_array_almost_equal(ybound, (0.3946, 1.7164)) + def test_report(): ncdrill = read(NCDRILL_FILE) @@ -57,9 +67,7 @@ def test_conversion(): ncdrill_inch = copy.deepcopy(ncdrill) ncdrill.to_metric() assert_equal(ncdrill.settings.units, 'metric') - inch_primitives = ncdrill_inch.primitives - for tool in iter(ncdrill_inch.tools.values()): tool.to_metric() for primitive in inch_primitives: @@ -80,26 +88,31 @@ def test_parser_hole_count(): p.parse(NCDRILL_FILE) assert_equal(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]) + def test_parse_whitespace(): p = ExcellonParser(FileSettings()) assert_equal(p._parse(' '), None) + def test_parse_comment(): p = ExcellonParser(FileSettings()) p._parse(';A comment') assert_equal(p.statements[0].comment, 'A comment') + def test_parse_format_comment(): p = ExcellonParser(FileSettings()) p._parse('; FILE_FORMAT=9:9 ') assert_equal(p.format, (9, 9)) + def test_parse_header(): p = ExcellonParser(FileSettings()) p._parse('M48 ') @@ -107,6 +120,7 @@ def test_parse_header(): p._parse('M95 ') assert_equal(p.state, 'DRILL') + def test_parse_rout(): p = ExcellonParser(FileSettings()) p._parse('G00 ') @@ -114,6 +128,7 @@ def test_parse_rout(): p._parse('G05 ') assert_equal(p.state, 'DRILL') + def test_parse_version(): p = ExcellonParser(FileSettings()) p._parse('VER,1 ') @@ -121,6 +136,7 @@ def test_parse_version(): p._parse('VER,2 ') assert_equal(p.statements[1].version, 2) + def test_parse_format(): p = ExcellonParser(FileSettings()) p._parse('FMAT,1 ') @@ -128,6 +144,7 @@ def test_parse_format(): p._parse('FMAT,2 ') assert_equal(p.statements[1].format, 2) + def test_parse_units(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) @@ -138,6 +155,7 @@ def test_parse_units(): assert_equal(p.units, 'metric') assert_equal(p.zeros, 'leading') + def test_parse_incremental_mode(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) @@ -147,6 +165,7 @@ def test_parse_incremental_mode(): p._parse('ICI,OFF ') assert_equal(p.notation, 'absolute') + def test_parse_absolute_mode(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) @@ -156,18 +175,21 @@ def test_parse_absolute_mode(): p._parse('G90 ') assert_equal(p.notation, 'absolute') + def test_parse_repeat_hole(): p = ExcellonParser(FileSettings()) p.active_tool = ExcellonTool(FileSettings(), number=8) p._parse('R03X1.5Y1.5') assert_equal(p.statements[0].count, 3) + def test_parse_incremental_position(): p = ExcellonParser(FileSettings(notation='incremental')) p._parse('X01Y01') p._parse('X01Y01') assert_equal(p.pos, [2.,2.]) + def test_parse_unknown(): p = ExcellonParser(FileSettings()) p._parse('Not A Valid Statement') -- cgit From 6e29b9bcae8167dbb9c75e5a79e09886b952e988 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Sun, 15 Nov 2015 22:28:56 -0200 Subject: Use Python's universal newlines to open files --- gerber/tests/test_excellon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index b821649..705adc3 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -16,7 +16,7 @@ NCDRILL_FILE = os.path.join(os.path.dirname(__file__), def test_format_detection(): """ Test file type detection """ - with open(NCDRILL_FILE) as f: + with open(NCDRILL_FILE, "rU") as f: data = f.read() settings = detect_excellon_format(data) assert_equal(settings['format'], (2, 4)) @@ -35,9 +35,9 @@ def test_read(): def test_write(): ncdrill = read(NCDRILL_FILE) ncdrill.write('test.ncd') - with open(NCDRILL_FILE) as src: + with open(NCDRILL_FILE, "rU") as src: srclines = src.readlines() - with open('test.ncd') 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') -- cgit From 1cb269131bc52f0b1a1e69cef0466f2d994d52a8 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 19 Dec 2015 21:54:29 -0500 Subject: Allow negative render of soldermask per #50 Update example code and rendering to show change --- gerber/tests/test_excellon.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 705adc3..a9a33c7 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -98,60 +98,60 @@ def test_parser_hole_sizes(): def test_parse_whitespace(): p = ExcellonParser(FileSettings()) - assert_equal(p._parse(' '), None) + assert_equal(p._parse_line(' '), None) def test_parse_comment(): p = ExcellonParser(FileSettings()) - p._parse(';A comment') + p._parse_line(';A comment') assert_equal(p.statements[0].comment, 'A comment') def test_parse_format_comment(): p = ExcellonParser(FileSettings()) - p._parse('; FILE_FORMAT=9:9 ') + p._parse_line('; FILE_FORMAT=9:9 ') assert_equal(p.format, (9, 9)) def test_parse_header(): p = ExcellonParser(FileSettings()) - p._parse('M48 ') + p._parse_line('M48 ') assert_equal(p.state, 'HEADER') - p._parse('M95 ') + p._parse_line('M95 ') assert_equal(p.state, 'DRILL') def test_parse_rout(): p = ExcellonParser(FileSettings()) - p._parse('G00 ') + p._parse_line('G00 ') assert_equal(p.state, 'ROUT') - p._parse('G05 ') + p._parse_line('G05 ') assert_equal(p.state, 'DRILL') def test_parse_version(): p = ExcellonParser(FileSettings()) - p._parse('VER,1 ') + p._parse_line('VER,1 ') assert_equal(p.statements[0].version, 1) - p._parse('VER,2 ') + p._parse_line('VER,2 ') assert_equal(p.statements[1].version, 2) def test_parse_format(): p = ExcellonParser(FileSettings()) - p._parse('FMAT,1 ') + p._parse_line('FMAT,1 ') assert_equal(p.statements[0].format, 1) - p._parse('FMAT,2 ') + p._parse_line('FMAT,2 ') assert_equal(p.statements[1].format, 2) def test_parse_units(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) - p._parse(';METRIC,LZ') + p._parse_line(';METRIC,LZ') assert_equal(p.units, 'inch') assert_equal(p.zeros, 'trailing') - p._parse('METRIC,LZ') + p._parse_line('METRIC,LZ') assert_equal(p.units, 'metric') assert_equal(p.zeros, 'leading') @@ -160,9 +160,9 @@ def test_parse_incremental_mode(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) assert_equal(p.notation, 'absolute') - p._parse('ICI,ON ') + p._parse_line('ICI,ON ') assert_equal(p.notation, 'incremental') - p._parse('ICI,OFF ') + p._parse_line('ICI,OFF ') assert_equal(p.notation, 'absolute') @@ -170,29 +170,29 @@ def test_parse_absolute_mode(): settings = FileSettings(units='inch', zeros='trailing') p = ExcellonParser(settings) assert_equal(p.notation, 'absolute') - p._parse('ICI,ON ') + p._parse_line('ICI,ON ') assert_equal(p.notation, 'incremental') - p._parse('G90 ') + p._parse_line('G90 ') assert_equal(p.notation, 'absolute') def test_parse_repeat_hole(): p = ExcellonParser(FileSettings()) p.active_tool = ExcellonTool(FileSettings(), number=8) - p._parse('R03X1.5Y1.5') + p._parse_line('R03X1.5Y1.5') assert_equal(p.statements[0].count, 3) def test_parse_incremental_position(): p = ExcellonParser(FileSettings(notation='incremental')) - p._parse('X01Y01') - p._parse('X01Y01') + p._parse_line('X01Y01') + p._parse_line('X01Y01') assert_equal(p.pos, [2.,2.]) def test_parse_unknown(): p = ExcellonParser(FileSettings()) - p._parse('Not A Valid Statement') + p._parse_line('Not A Valid Statement') assert_equal(p.statements[0].stmt, 'Not A Valid Statement') -- cgit From 52c6d4928a1b5fc65b95cf5b0784a560cec2ca1d Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 16 Jul 2016 15:49:48 +0800 Subject: Fix most broken tests so that I can safely merge into changes with known expected test result --- gerber/tests/test_excellon.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 705adc3..afc2917 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -78,8 +78,9 @@ def test_conversion(): for m_tool, i_tool in zip(iter(ncdrill.tools.values()), iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) - for m, i in zip(ncdrill.primitives,inch_primitives): - assert_equal(m, i) + for m, i in zip(ncdrill.primitives, 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)) def test_parser_hole_count(): -- cgit From 8cd842a41a55ab3d8f558a2e3e198beba7da58a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Manually mere rendering changes --- gerber/tests/test_excellon.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index cd94b0f..1402938 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -13,6 +13,7 @@ from .tests import * NCDRILL_FILE = os.path.join(os.path.dirname(__file__), 'resources/ncdrill.DRD') + def test_format_detection(): """ Test file type detection """ @@ -75,7 +76,8 @@ def test_conversion(): 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())): + for m_tool, i_tool in zip(iter(ncdrill.tools.values()), + iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) for m, i in zip(ncdrill.primitives, inch_primitives): @@ -188,12 +190,10 @@ def test_parse_incremental_position(): p = ExcellonParser(FileSettings(notation='incremental')) p._parse_line('X01Y01') p._parse_line('X01Y01') - assert_equal(p.pos, [2.,2.]) + assert_equal(p.pos, [2., 2.]) def test_parse_unknown(): p = ExcellonParser(FileSettings()) p._parse_line('Not A Valid Statement') assert_equal(p.statements[0].stmt, 'Not A Valid Statement') - - -- cgit From 41a7b90dff19b69ef03fed4104ecfdcbfcb21641 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 18 Nov 2016 07:55:43 -0500 Subject: Excellon update --- gerber/tests/test_excellon.py | 154 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 7 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 1402938..6cddb60 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -6,6 +6,7 @@ import os from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser +from ..excellon import DrillHit, DrillSlot from ..excellon_statements import ExcellonTool from .tests import * @@ -50,29 +51,28 @@ def test_read_settings(): assert_equal(ncdrill.settings['zeros'], 'trailing') -def test_bounds(): +def test_bounding_box(): ncdrill = read(NCDRILL_FILE) - xbound, ybound = ncdrill.bounds + xbound, ybound = ncdrill.bounding_box assert_array_almost_equal(xbound, (0.1300, 2.1430)) assert_array_almost_equal(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') ncdrill_inch = copy.deepcopy(ncdrill) + ncdrill.to_metric() assert_equal(ncdrill.settings.units, 'metric') - inch_primitives = ncdrill_inch.primitives for tool in iter(ncdrill_inch.tools.values()): tool.to_metric() - for primitive in inch_primitives: - primitive.to_metric() + for statement in ncdrill_inch.statements: statement.to_metric() @@ -80,7 +80,8 @@ def test_conversion(): iter(ncdrill_inch.tools.values())): assert_equal(i_tool, m_tool) - for m, i in zip(ncdrill.primitives, inch_primitives): + 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)) @@ -197,3 +198,142 @@ def test_parse_unknown(): p = ExcellonParser(FileSettings()) p._parse_line('Not A Valid Statement') assert_equal(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') + 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)) + + # 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)) + + # 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)) + + # 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)) + + # 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)) + +def test_drill_hit_offset(): + TEST_VECTORS = [ + ((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') + tool = ExcellonTool(settings, diameter=1.0) + hit = DrillHit(tool, position) + + assert_equal(hit.position, position) + + hit.offset(offset[0], offset[1]) + + assert_equal(hit.position, expected) + + +def test_drill_slot_units_conversion(): + """ Test unit conversion for drill hits + """ + # Inch hit + 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)) + + # 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)) + + # 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)) + + # 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)) + + # 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)) + +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), (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') + tool = ExcellonTool(settings, diameter=1.0) + slot = DrillSlot(tool, start, end, DrillSlot.TYPE_ROUT) + + assert_equal(slot.start, start) + assert_equal(slot.end, end) + + slot.offset(offset[0], offset[1]) + + assert_equal(slot.start, expected_start) + assert_equal(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') + tool = ExcellonTool(settings, diameter=diameter) + slot = DrillSlot(tool, start, end, DrillSlot.TYPE_ROUT) + + assert_equal(slot.bounding_box, expected) + +#def test_exce -- cgit From 7ad6c3f6acfe1fe995c9f087e7ef7a51add60afe Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 4 Jul 2017 02:11:52 -0400 Subject: Fix handling of multi-line strings per #66 --- gerber/tests/test_excellon.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'gerber/tests/test_excellon.py') diff --git a/gerber/tests/test_excellon.py b/gerber/tests/test_excellon.py index 6cddb60..d17791c 100644 --- a/gerber/tests/test_excellon.py +++ b/gerber/tests/test_excellon.py @@ -7,7 +7,7 @@ import os from ..cam import FileSettings from ..excellon import read, detect_excellon_format, ExcellonFile, ExcellonParser from ..excellon import DrillHit, DrillSlot -from ..excellon_statements import ExcellonTool +from ..excellon_statements import ExcellonTool, RouteModeStmt from .tests import * @@ -127,7 +127,7 @@ def test_parse_header(): def test_parse_rout(): p = ExcellonParser(FileSettings()) - p._parse_line('G00 ') + p._parse_line('G00X040944Y019842') assert_equal(p.state, 'ROUT') p._parse_line('G05 ') assert_equal(p.state, 'DRILL') @@ -336,4 +336,25 @@ def test_drill_slot_bounds(): assert_equal(slot.bounding_box, expected) -#def test_exce +def test_handling_multi_line_g00_and_g1(): + """Route Mode statements with coordinates on separate line are handled + """ + test_data = """ +% +M48 +M72 +T01C0.0236 +% +T01 +G00 +X040944Y019842 +M15 +G01 +X040944Y020708 +M16 +""" + uut = ExcellonParser() + uut.parse_raw(test_data) + assert_equal(len([stmt for stmt in uut.statements + if isinstance(stmt, RouteModeStmt)]), 2) + -- cgit From ef589a064015de3a1ce6487dbb56b99332673e9d Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Tue, 26 Nov 2019 00:37:41 -0300 Subject: Migrate to pytest (#111) * Migrate to pytest All tests were update to use pytest. Tests were alse black formatted. Eventually all code will be black formatted but need to merge some PRs first. --- gerber/tests/test_excellon.py | 260 +++++++++++++++++++++--------------------- 1 file changed, 133 insertions(+), 127 deletions(-) (limited to 'gerber/tests/test_excellon.py') 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 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 + ) -- cgit