Skip to content

Commit

Permalink
CLI: Add functional tests for custom fab. output settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ubruhin committed Mar 25, 2019
1 parent bea4c20 commit ca184e9
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/cli/open-project/test_export_pcb_fabrication_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,97 @@ def test_export_project_with_two_conflicting_boards_succeeds_explicit(cli):
assert stdout[-1] == 'SUCCESS'
assert os.path.exists(dir)
assert len(os.listdir(dir)) == 8


@pytest.mark.parametrize("project,output_dir", [
(PROJECT_PATH_1_LPP, 'data/Empty Project/custom_output'),
(PROJECT_PATH_1_LPPZ, 'data/custom_output'),
], ids=[
'EmptyProject.lpp',
'EmptyProject.lppz',
])
def test_export_with_custom_settings(cli, project, output_dir):
settings = """
(fabrication_output_settings
(base_path "./custom_output/")
(outlines (suffix "OUTLINES.gbr"))
(copper_top (suffix "COPPER-TOP.gbr"))
(copper_inner (suffix "COPPER-IN{{CU_LAYER}}.gbr"))
(copper_bot (suffix "COPPER-BOTTOM.gbr"))
(soldermask_top (suffix "SOLDERMASK-TOP.gbr"))
(soldermask_bot (suffix "SOLDERMASK-BOTTOM.gbr"))
(silkscreen_top (suffix "SILKSCREEN-TOP.gbr")
(layers top_placement top_names)
)
(silkscreen_bot (suffix "SILKSCREEN-BOTTOM.gbr")
(layers bot_placement bot_names)
)
(drills (merge true)
(suffix_pth "DRILLS-PTH.drl")
(suffix_npth "DRILLS-NPTH.drl")
(suffix_merged "DRILLS.drl")
)
(solderpaste_top (create true) (suffix "SOLDERPASTE-TOP.gbr"))
(solderpaste_bot (create true) (suffix "SOLDERPASTE-BOTTOM.gbr"))
)
"""
with open(cli.abspath('settings.lp'), mode='w') as f:
f.write(settings)
dir = cli.abspath(output_dir)
assert not os.path.exists(dir)
code, stdout, stderr = cli.run('open-project',
'--export-pcb-fabrication-data',
'--pcb-fabrication-settings=settings.lp',
project)
assert code == 0
assert len(stderr) == 0
assert len(stdout) > 0
assert stdout[-1] == 'SUCCESS'
assert os.path.exists(dir)
assert len(os.listdir(dir)) == 10


@pytest.mark.parametrize("project,output_dir", [
(PROJECT_PATH_1_LPP, OUTPUT_DIR_1_LPP),
(PROJECT_PATH_2_LPPZ, OUTPUT_DIR_2_LPPZ),
], ids=[
'EmptyProject.lpp',
'ProjectWithTwoBoards.lppz',
])
def test_if_export_with_nonexistent_settings_fails(cli, project, output_dir):
dir = cli.abspath(output_dir)
assert not os.path.exists(dir)
code, stdout, stderr = cli.run('open-project',
'--export-pcb-fabrication-data',
'--pcb-fabrication-settings=nonexistent.lp',
project)
assert code == 1
assert len(stderr) == 1
assert "Failed to load custom settings:" in stderr[0]
assert len(stdout) > 0
assert stdout[-1] == 'Finished with errors!'
assert not os.path.exists(dir)


@pytest.mark.parametrize("project,output_dir", [
(PROJECT_PATH_1_LPP, OUTPUT_DIR_1_LPP),
(PROJECT_PATH_2_LPPZ, OUTPUT_DIR_2_LPPZ),
], ids=[
'EmptyProject.lpp',
'ProjectWithTwoBoards.lppz',
])
def test_if_export_with_invalid_settings_fails(cli, project, output_dir):
with open(cli.abspath('settings.lp'), mode='w') as f:
f.write('foobar')
dir = cli.abspath(output_dir)
assert not os.path.exists(dir)
code, stdout, stderr = cli.run('open-project',
'--export-pcb-fabrication-data',
'--pcb-fabrication-settings=settings.lp',
project)
assert code == 1
assert len(stderr) > 0
assert "Failed to load custom settings: File parse error:" in stderr[0]
assert len(stdout) > 0
assert stdout[-1] == 'Finished with errors!'
assert not os.path.exists(dir)

0 comments on commit ca184e9

Please sign in to comment.