diff options
author | jaseg <git@jaseg.de> | 2021-12-29 19:58:20 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-12-29 19:58:20 +0100 |
commit | 3fb26e6940b5ae752308d8a33f2608d266795153 (patch) | |
tree | a563b0cf512e5661b2a450ebf73eafe655ac18b2 /gerbonara/gerber/tests/test_rs274x.py | |
parent | 30dabef9ee83021067957854187b9bbf245c14cf (diff) | |
download | gerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.tar.gz gerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.tar.bz2 gerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.zip |
Basic round-trip works
Diffstat (limited to 'gerbonara/gerber/tests/test_rs274x.py')
-rw-r--r-- | gerbonara/gerber/tests/test_rs274x.py | 131 |
1 files changed, 83 insertions, 48 deletions
diff --git a/gerbonara/gerber/tests/test_rs274x.py b/gerbonara/gerber/tests/test_rs274x.py index e430f36..beaea11 100644 --- a/gerbonara/gerber/tests/test_rs274x.py +++ b/gerbonara/gerber/tests/test_rs274x.py @@ -4,52 +4,87 @@ # Author: Hamilton Kibbe <ham@hamiltonkib.be> import os import pytest +import functools +import tempfile +import shutil +from argparse import Namespace +from pathlib import Path + +from ..rs274x import GerberFile + +from .image_support import gerber_difference + + +fail_dir = Path('gerbonara_test_failures') +@pytest.fixture(scope='session', autouse=True) +def clear_failure_dir(request): + if fail_dir.is_dir(): + shutil.rmtree(fail_dir) + +@pytest.fixture +def tmp_gbr(request): + with tempfile.NamedTemporaryFile(suffix='.gbr') as tmp_out_gbr: + + yield Path(tmp_out_gbr.name) + + if request.node.rep_call.failed: + module, _, test_name = request.node.nodeid.rpartition('::') + _test, _, test_name = test_name.partition('_') + test_name = test_name.replace('[', '_').replace(']', '_') + fail_dir.mkdir(exist_ok=True) + perm_path = fail_dir / f'failure_{test_name}.gbr' + shutil.copy(tmp_out_gbr.name, perm_path) + print('Failing output saved to {perm_path}') + +@pytest.mark.parametrize('reference', [ l.strip() for l in ''' +board_outline.GKO +example_outline_with_arcs.gbr +''' +#example_two_square_boxes.gbr +#example_coincident_hole.gbr +#example_cutin.gbr +#example_cutin_multiple.gbr +#example_flash_circle.gbr +#example_flash_obround.gbr +#example_flash_polygon.gbr +#example_flash_rectangle.gbr +#example_fully_coincident.gbr +#example_guess_by_content.g0 +#example_holes_dont_clear.gbr +#example_level_holes.gbr +#example_not_overlapping_contour.gbr +#example_not_overlapping_touching.gbr +#example_overlapping_contour.gbr +#example_overlapping_touching.gbr +#example_simple_contour.gbr +#example_single_contour_1.gbr +#example_single_contour_2.gbr +#example_single_contour_3.gbr +#example_am_exposure_modifier.gbr +#bottom_copper.GBL +#bottom_mask.GBS +#bottom_silk.GBO +#eagle_files/copper_bottom_l4.gbr +#eagle_files/copper_inner_l2.gbr +#eagle_files/copper_inner_l3.gbr +#eagle_files/copper_top_l1.gbr +#eagle_files/profile.gbr +#eagle_files/silkscreen_bottom.gbr +#eagle_files/silkscreen_top.gbr +#eagle_files/soldermask_bottom.gbr +#eagle_files/soldermask_top.gbr +#eagle_files/solderpaste_bottom.gbr +#eagle_files/solderpaste_top.gbr +#multiline_read.ger +#test_fine_lines_x.gbr +#test_fine_lines_y.gbr +#top_copper.GTL +#top_mask.GTS +#top_silk.GTO +''' +'''.splitlines() if l ]) +def test_round_trip(tmp_gbr, reference): + ref = Path(__file__).parent / 'resources' / reference + GerberFile.open(ref).save(tmp_gbr) + assert gerber_difference(ref, tmp_gbr) < 0.02 -from ..rs274x import read, GerberFile - - -TOP_COPPER_FILE = os.path.join(os.path.dirname(__file__), "resources/top_copper.GTL") - -MULTILINE_READ_FILE = os.path.join( - os.path.dirname(__file__), "resources/multiline_read.ger" -) - - -def test_read(): - top_copper = read(TOP_COPPER_FILE) - assert isinstance(top_copper, GerberFile) - - -def test_multiline_read(): - multiline = read(MULTILINE_READ_FILE) - assert isinstance(multiline, GerberFile) - assert 11 == len(multiline.statements) - - -def test_comments_parameter(): - top_copper = read(TOP_COPPER_FILE) - assert top_copper.comments[0] == "This is a comment,:" - - -def test_size_parameter(): - top_copper = read(TOP_COPPER_FILE) - size = top_copper.size - pytest.approx(size[0], 2.256900, 6) - pytest.approx(size[1], 1.500000, 6) - - -def test_conversion(): - top_copper = read(TOP_COPPER_FILE) - assert top_copper.units == "inch" - top_copper_inch = read(TOP_COPPER_FILE) - top_copper.to_metric() - for statement in top_copper_inch.statements: - statement.to_metric() - for primitive in top_copper_inch.primitives: - primitive.to_metric() - assert top_copper.units == "metric" - for i, m in zip(top_copper.statements, top_copper_inch.statements): - assert i == m - - for i, m in zip(top_copper.primitives, top_copper_inch.primitives): - assert i == m |