summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/tests
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-30 15:07:55 +0100
committerjaseg <git@jaseg.de>2022-01-30 15:07:55 +0100
commitc8bf837a4b5dcc6242b7dac383f09e9390deca35 (patch)
tree1c6d5f407e3276aad8304ef61fd81967c97a95b2 /gerbonara/gerber/tests
parent8bf6420cb4c8696487fe0fef5b5e154d262041b2 (diff)
downloadgerbonara-c8bf837a4b5dcc6242b7dac383f09e9390deca35.tar.gz
gerbonara-c8bf837a4b5dcc6242b7dac383f09e9390deca35.tar.bz2
gerbonara-c8bf837a4b5dcc6242b7dac383f09e9390deca35.zip
Fix some more testcases
* Fix Excellon export among others
Diffstat (limited to 'gerbonara/gerber/tests')
-rw-r--r--gerbonara/gerber/tests/image_support.py12
-rw-r--r--gerbonara/gerber/tests/test_excellon.py33
-rw-r--r--gerbonara/gerber/tests/test_layers.py4
-rw-r--r--gerbonara/gerber/tests/test_rs274x.py17
4 files changed, 42 insertions, 24 deletions
diff --git a/gerbonara/gerber/tests/image_support.py b/gerbonara/gerber/tests/image_support.py
index 1dfd34a..913a4bf 100644
--- a/gerbonara/gerber/tests/image_support.py
+++ b/gerbonara/gerber/tests/image_support.py
@@ -61,7 +61,8 @@ def run_cargo_cmd(cmd, args, **kwargs):
except FileNotFoundError:
return subprocess.run([str(Path.home() / '.cargo' / 'bin' / cmd), *args], **kwargs)
-def svg_to_png(in_svg, out_png, dpi=100, bg='black'):
+def svg_to_png(in_svg, out_png, dpi=100, bg=None):
+ bg = 'black' if bg is None else bg
run_cargo_cmd('resvg', ['--background', bg, '--dpi', str(dpi), in_svg, out_png], check=True, stdout=subprocess.DEVNULL)
to_gerbv_svg_units = lambda val, unit='mm': val*72 if unit == 'inch' else val/25.4*72
@@ -89,6 +90,9 @@ def gerbv_export(in_gbr, out_svg, export_format='svg', origin=(0, 0), size=(6, 6
color = f"(cons 'color #({r*257} {g*257} {b*257}))"
f.write(f'''(gerbv-file-version! "2.0A")(define-layer! 0 (cons 'filename "{in_gbr}"){unit_spec}{color})''')
f.flush()
+ if override_unit_spec:
+ import shutil
+ shutil.copy(f.name, '/tmp/foo.gbv')
x, y = origin
w, h = size
@@ -194,12 +198,12 @@ def gerber_difference_merge(ref1, ref2, actual, diff_out=None, composite_out=Non
return svg_difference(ref1_svg.name, act_svg.name, diff_out=diff_out)
-def svg_difference(reference, actual, diff_out=None):
+def svg_difference(reference, actual, diff_out=None, background=None):
with tempfile.NamedTemporaryFile(suffix='-ref.png') as ref_png,\
tempfile.NamedTemporaryFile(suffix='-act.png') as act_png:
- svg_to_png(reference, ref_png.name)
- svg_to_png(actual, act_png.name)
+ svg_to_png(reference, ref_png.name, bg=background)
+ svg_to_png(actual, act_png.name, bg=background)
return image_difference(ref_png.name, act_png.name, diff_out=diff_out)
diff --git a/gerbonara/gerber/tests/test_excellon.py b/gerbonara/gerber/tests/test_excellon.py
index d89c0a0..6267f65 100644
--- a/gerbonara/gerber/tests/test_excellon.py
+++ b/gerbonara/gerber/tests/test_excellon.py
@@ -19,8 +19,8 @@ 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-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'),
+ 'altium-composite-drill/NC Drill/LimeSDR-QPCIe_1v2-SlotHoles.TXT': (('mm', 'trailing', 4), None),
+ 'altium-composite-drill/NC Drill/LimeSDR-QPCIe_1v2-RoundHoles.TXT': (('mm', 'trailing', 4), 'altium-composite-drill/Gerber/LimeSDR-QPCIe_1v2.GTL'),
'pcb-rnd/power-art.xln': (None, 'pcb-rnd/power-art.gtl'),
'siemens/80101_0125_F200_ThruHoleNonPlated.ncd': (None, None),
'siemens/80101_0125_F200_ThruHolePlated.ncd': (None, 'siemens/80101_0125_F200_L01_Top.gdo'),
@@ -42,7 +42,13 @@ def test_round_trip(reference, tmpfile):
tmp = tmpfile('Output excellon', '.drl')
print('unit spec', unit_spec)
- ExcellonFile.open(reference).save(tmp)
+ f = ExcellonFile.open(reference)
+ f.save(tmp)
+
+ if reference.name == '80101_0125_F200_ContourPlated.ncd':
+ # gerbv does not support routed slots in excellon files at all and renders garbage for the reference file here
+ # due to its use of bare coordinates for routed slots. Thus, we skip this test (for now).
+ return
mean, _max, hist = gerber_difference(reference, tmp, diff_out=tmpfile('Difference', '.png'), ref_unit_spec=unit_spec)
assert mean < 5e-5
@@ -51,6 +57,27 @@ def test_round_trip(reference, tmpfile):
@filter_syntax_warnings
@pytest.mark.parametrize('reference', list(REFERENCE_FILES.items()), indirect=True)
+def test_first_level_idempotence_svg(reference, tmpfile):
+ reference, (unit_spec, _) = reference
+ tmp = tmpfile('Output excellon', '.drl')
+ ref_svg = tmpfile('Reference SVG render', '.svg')
+ out_svg = tmpfile('Output SVG render', '.svg')
+ print('unit spec', unit_spec)
+
+ a = ExcellonFile.open(reference)
+ a.save(tmp)
+ b = ExcellonFile.open(tmp)
+
+ ref_svg.write_text(str(a.to_svg(fg='black', bg='white')))
+ out_svg.write_text(str(b.to_svg(fg='black', bg='white')))
+
+ mean, _max, hist = svg_difference(ref_svg, out_svg, diff_out=tmpfile('Difference', '.png'), background='white')
+ assert mean < 5e-5
+ assert hist[9] == 0
+ assert hist[3:].sum() < 5e-5*hist.size
+
+@filter_syntax_warnings
+@pytest.mark.parametrize('reference', list(REFERENCE_FILES.items()), indirect=True)
def test_idempotence(reference, tmpfile):
reference, (unit_spec, _) = reference
diff --git a/gerbonara/gerber/tests/test_layers.py b/gerbonara/gerber/tests/test_layers.py
index 792316f..3f72cd8 100644
--- a/gerbonara/gerber/tests/test_layers.py
+++ b/gerbonara/gerber/tests/test_layers.py
@@ -44,7 +44,7 @@ REFERENCE_DIRS = {
},
'allegro': {
- '08_057494d-ipc356.ipc': None,
+ '08_057494d-ipc356.ipc': 'other netlist',
'08_057494d.rou': 'mechanical outline',
'Read_Me.1': None,
'art_param.txt': None,
@@ -71,7 +71,7 @@ REFERENCE_DIRS = {
'allegro-2': {
'MINNOWMAX_REVA2_PUBLIC_BOTTOMSIDE.pdf': None,
'MINNOWMAX_REVA2_PUBLIC_TOPSIDE.pdf': None,
- 'MinnowMax_RevA1_IPC356A.ipc': None,
+ 'MinnowMax_RevA1_IPC356A.ipc': 'other netlist',
'MinnowMax_RevA1_DRILL/MinnowMax_RevA1_NCDRILL.drl': 'drill unknown',
'MinnowMax_RevA1_DRILL/MinnowMax_RevA1_NCROUTE.rou': 'drill unknown',
'MinnowMax_RevA1_DRILL/nc_param.txt': None,
diff --git a/gerbonara/gerber/tests/test_rs274x.py b/gerbonara/gerber/tests/test_rs274x.py
index fdd9a81..13192a3 100644
--- a/gerbonara/gerber/tests/test_rs274x.py
+++ b/gerbonara/gerber/tests/test_rs274x.py
@@ -116,19 +116,6 @@ REFERENCE_FILES = [ l.strip() for l in '''
altium-composite-drill/Gerber/LimeSDR-QPCIe_1v2.GBO
altium-composite-drill/Gerber/LimeSDR-QPCIe_1v2.G8
altium-composite-drill/Gerber/LimeSDR-QPCIe_1v2.GPT
- allegro/mask_prm.art
- allegro/paste_sec.art
- allegro/assy2.art
- allegro/l3_vcc.art
- allegro/l1_primary.art
- allegro/silk_prm.art
- allegro/l2_gnd.art
- allegro/assy1.art
- allegro/fab1.art
- allegro/l4_secondary.art
- allegro/mask_sec.art
- allegro/paste_prm.art
- allegro/silk_sec.art
geda/driver.topmask.gbr
geda/controller.top.gbr
geda/controller.bottom.gbr
@@ -456,10 +443,10 @@ def test_svg_export(reference, tmpfile):
ref_svg = tmpfile('Reference export', '.svg')
ref_png = tmpfile('Reference render', '.png')
gerbv_export(reference, ref_svg, origin=bounds[0], size=bounds[1], fg='#000000', bg='#ffffff')
- svg_to_png(ref_svg, ref_png, dpi=72) # make dpi match Cairo's default
+ svg_to_png(ref_svg, ref_png, dpi=72, bg='white') # make dpi match Cairo's default
out_png = tmpfile('Output render', '.png')
- svg_to_png(out_svg, out_png, dpi=72) # make dpi match Cairo's default
+ svg_to_png(out_svg, out_png, dpi=72, bg='white') # make dpi match Cairo's default
mean, _max, hist = image_difference(ref_png, out_png, diff_out=tmpfile('Difference', '.png'))
assert mean < 1.2e-3