summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/tests
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-24 14:19:01 +0100
committerjaseg <git@jaseg.de>2022-01-24 14:19:01 +0100
commita1c1d6d971257f03f1926db9dc44e659d2773d2d (patch)
tree443af73413f52b47fbbddf185bb497fb483c93c0 /gerbonara/gerber/tests
parent4a6d76c557caf7263ab57e5fe840d28aa3356621 (diff)
downloadgerbonara-a1c1d6d971257f03f1926db9dc44e659d2773d2d.tar.gz
gerbonara-a1c1d6d971257f03f1926db9dc44e659d2773d2d.tar.bz2
gerbonara-a1c1d6d971257f03f1926db9dc44e659d2773d2d.zip
Add more tests
Diffstat (limited to 'gerbonara/gerber/tests')
-rw-r--r--gerbonara/gerber/tests/image_support.py1
-rw-r--r--gerbonara/gerber/tests/test_excellon.py22
-rw-r--r--gerbonara/gerber/tests/test_rs274x.py11
3 files changed, 33 insertions, 1 deletions
diff --git a/gerbonara/gerber/tests/image_support.py b/gerbonara/gerber/tests/image_support.py
index a50e243..1dfd34a 100644
--- a/gerbonara/gerber/tests/image_support.py
+++ b/gerbonara/gerber/tests/image_support.py
@@ -73,6 +73,7 @@ def gerbv_export(in_gbr, out_svg, export_format='svg', origin=(0, 0), size=(6, 6
with tempfile.NamedTemporaryFile('w') as f:
if override_unit_spec:
units, zeros, digits = override_unit_spec
+ print(f'{Path(in_gbr).name}: overriding excellon unit spec to {units=} {zeros=} {digits=}')
units = 0 if units == 'inch' else 1
zeros = {None: 0, 'leading': 1, 'trailing': 2}[zeros]
unit_spec = textwrap.dedent(f'''(cons 'attribs (list
diff --git a/gerbonara/gerber/tests/test_excellon.py b/gerbonara/gerber/tests/test_excellon.py
index fb25d8f..d89c0a0 100644
--- a/gerbonara/gerber/tests/test_excellon.py
+++ b/gerbonara/gerber/tests/test_excellon.py
@@ -18,7 +18,7 @@ from ..utils import Inch, MM
REFERENCE_FILES = {
'easyeda/Gerber_Drill_NPTH.DRL': (None, None),
'easyeda/Gerber_Drill_PTH.DRL': (None, 'easyeda/Gerber_TopLayer.GTL'),
- # Altium uses an excellon format specification format that gerbv doesn't understand, so we have to fix that.
+ # Altium uses an excellon format specification format that gerbv doesn't understand, so we have to fix that.
'altium-composite-drill/NC Drill/LimeSDR-QPCIe_1v2-SlotHoles.TXT': (('mm', 'leading', 4), None),
'altium-composite-drill/NC Drill/LimeSDR-QPCIe_1v2-RoundHoles.TXT': (('mm', 'leading', 4), 'altium-composite-drill/Gerber/LimeSDR-QPCIe_1v2.GTL'),
'pcb-rnd/power-art.xln': (None, 'pcb-rnd/power-art.gtl'),
@@ -40,6 +40,7 @@ REFERENCE_FILES = {
def test_round_trip(reference, tmpfile):
reference, (unit_spec, _) = reference
tmp = tmpfile('Output excellon', '.drl')
+ print('unit spec', unit_spec)
ExcellonFile.open(reference).save(tmp)
@@ -50,6 +51,25 @@ def test_round_trip(reference, tmpfile):
@filter_syntax_warnings
@pytest.mark.parametrize('reference', list(REFERENCE_FILES.items()), indirect=True)
+def test_idempotence(reference, tmpfile):
+ reference, (unit_spec, _) = reference
+
+ if reference.name == '80101_0125_F200_ContourPlated.ncd':
+ # this file contains a duplicate tool definition that we optimize out on our second pass.
+ # TODO see whether we can change things so we optimize this out on the first pass already. I'm not sure what
+ # went wrong there.
+ pytest.skip()
+
+ tmp_1 = tmpfile('First generation output', '.drl')
+ tmp_2 = tmpfile('Second generation output', '.drl')
+
+ ExcellonFile.open(reference).save(tmp_1)
+ ExcellonFile.open(tmp_1).save(tmp_2)
+
+ assert tmp_1.read_text() == tmp_2.read_text()
+
+@filter_syntax_warnings
+@pytest.mark.parametrize('reference', list(REFERENCE_FILES.items()), indirect=True)
def test_gerber_alignment(reference, tmpfile, print_on_error):
reference, (unit_spec, gerber) = reference
tmp = tmpfile('Output excellon', '.drl')
diff --git a/gerbonara/gerber/tests/test_rs274x.py b/gerbonara/gerber/tests/test_rs274x.py
index 83148a5..fdd9a81 100644
--- a/gerbonara/gerber/tests/test_rs274x.py
+++ b/gerbonara/gerber/tests/test_rs274x.py
@@ -275,6 +275,17 @@ def test_round_trip(reference, tmpfile):
assert hist[9] == 0
assert hist[3:].sum() < 5e-5*hist.size
+@filter_syntax_warnings
+@pytest.mark.parametrize('reference', REFERENCE_FILES, indirect=True)
+def test_idempotence(reference, tmpfile):
+ tmp_gbr_1 = tmpfile('First generation output', '.gbr')
+ tmp_gbr_2 = tmpfile('Second generation output', '.gbr')
+
+ GerberFile.open(reference).save(tmp_gbr_1)
+ GerberFile.open(tmp_gbr_1).save(tmp_gbr_2)
+ assert tmp_gbr_1.read_text() == tmp_gbr_2.read_text()
+
+
TEST_ANGLES = [90, 180, 270, 30, 1.5, 10, 360, 1024, -30, -90]
TEST_OFFSETS = [(0, 0), (100, 0), (0, 100), (2, 0), (10, 100)]