File: test_export_pcb_fabrication_data.py

package info (click to toggle)
librepcb 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 58,484 kB
  • sloc: cpp: 267,986; python: 12,100; ansic: 6,899; xml: 234; sh: 215; makefile: 115; perl: 73
file content (454 lines) | stat: -rw-r--r-- 23,564 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import fileinput
import params
import pytest

"""
Test command "open-project --export-pcb-fabrication-data"
"""


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
])
def test_if_project_without_boards_succeeds(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)

    # remove all boards first
    with open(cli.abspath(project.dir + '/boards/boards.lp'), 'w') as f:
        f.write('(librepcb_boards)')

    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "SUCCESS\n".format(project=project)
    assert code == 0
    assert not os.path.exists(dir)  # nothing was exported ;)


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.EMPTY_PROJECT_LPPZ_PARAM,
])
def test_export_project_with_one_board_implicit(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'default':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 9


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.EMPTY_PROJECT_LPPZ_PARAM,
])
def test_export_project_with_one_board_explicit(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--board=default',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'default':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 9


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_if_exporting_invalid_board_fails(cli, project):
    """
    Note: Test with passing the argument as "--arg <value>".
    """
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--board', 'foo',
                                   project.path)
    assert stderr == "ERROR: No board with the name 'foo' found.\n"
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "Finished with errors!\n".format(project=project)
    assert code == 1
    assert not os.path.exists(dir)


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_export_project_with_two_boards_implicit(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'default':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "  Board 'copy':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 18


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_export_project_with_two_boards_explicit_one(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--board=copy',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'copy':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 9


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_export_project_with_two_boards_explicit_two(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--board=copy',
                                   '--board=default',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'copy':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_copy_SILKSCREEN-BOTTOM.gbr'\n" \
        "  Board 'default':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 18


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
])
def test_export_project_with_two_conflicting_boards_fails(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)

    # change gerber output path to the same for both boards
    boardfile = cli.abspath(project.dir + '/boards/copy/board.lp')
    for line in fileinput.input(boardfile, inplace=1):
        print(line.replace("_copy", ""))

    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   project.path)
    assert stderr == \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr' was written multiple times!\n" \
        "ERROR: The file '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr' was written multiple times!\n" \
        "NOTE: To avoid writing files multiple times, make sure to pass " \
        "unique filepaths to all export functions. For board output files, " \
        "you could either add the placeholder '{{{{BOARD}}}}' to the path or " \
        "specify the boards to export with the '--board' argument.\n"\
        .format(project=project).replace('//', os.sep)
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'default':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "  Board 'copy':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "Finished with errors!\n".format(project=project).replace('//', os.sep)
    assert code == 1


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
])
def test_export_project_with_two_conflicting_boards_succeeds_explicit(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)

    # change gerber output path to the same for both boards
    boardfile = cli.abspath(project.dir + '/boards/copy/board.lp')
    for line in fileinput.input(boardfile, inplace=1):
        print(line.replace("_copy", ""))

    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--board=copy',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'copy':\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-NPTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_DRILLS-PTH.drl'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_OUTLINES.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_COPPER-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-TOP.gbr'\n" \
        "    => '{project.output_dir_native}//gerber//Empty_Project_SILKSCREEN-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 9


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.EMPTY_PROJECT_LPPZ_PARAM,
])
def test_export_with_custom_settings(cli, project):
    """
    Notes:
      - Test with passing the argument as "--arg <value>".
      - Test attributes '{{BOARD_INDEX}}' and '{{BOARD_DIRNAME}}' in path.
    """
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    settings = """
      (fabrication_output_settings
        (base_path "./out/{{BOARD_INDEX}}_{{BOARD_DIRNAME}}/")
        (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")
          (suffix_buried "_DRILLS-{{START_LAYER}}-{{END_LAYER}}.drl")
          (g85_slots false)
        )
        (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 = os.path.dirname(cli.abspath(project.path)) + '/out/0_default'
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--pcb-fabrication-settings', 'settings.lp',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "  Board 'default':\n" \
        "    => '{output_prefix}out//0_default//DRILLS.drl'\n" \
        "    => '{output_prefix}out//0_default//OUTLINES.gbr'\n" \
        "    => '{output_prefix}out//0_default//COPPER-TOP.gbr'\n" \
        "    => '{output_prefix}out//0_default//COPPER-BOTTOM.gbr'\n" \
        "    => '{output_prefix}out//0_default//SOLDERMASK-TOP.gbr'\n" \
        "    => '{output_prefix}out//0_default//SOLDERMASK-BOTTOM.gbr'\n" \
        "    => '{output_prefix}out//0_default//SILKSCREEN-TOP.gbr'\n" \
        "    => '{output_prefix}out//0_default//SILKSCREEN-BOTTOM.gbr'\n" \
        "    => '{output_prefix}out//0_default//SOLDERPASTE-TOP.gbr'\n" \
        "    => '{output_prefix}out//0_default//SOLDERPASTE-BOTTOM.gbr'\n" \
        "SUCCESS\n".format(
            project=project,
            output_prefix=('' if project.is_lppz else (project.dir + os.sep)),
        ).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 10


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_if_export_with_nonexistent_settings_fails(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--pcb-fabrication-settings=nonexistent.lp',
                                   project.path)
    assert stderr == \
        "ERROR: Failed to load custom settings: " \
        "The file \"{file}\" does not exist.\n" \
        .format(file=cli.abspath('nonexistent.lp'))
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "Finished with errors!\n".format(project=project)
    assert code == 1
    assert not os.path.exists(dir)


@pytest.mark.parametrize("project", [
    params.EMPTY_PROJECT_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_if_export_with_invalid_settings_fails(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    with open(cli.abspath('settings.lp'), mode='w') as f:
        f.write('foobar')
    dir = cli.abspath(project.output_dir + '/gerber')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-pcb-fabrication-data',
                                   '--pcb-fabrication-settings=settings.lp',
                                   project.path)
    assert stderr == \
        "ERROR: Failed to load custom settings: File parse error: " \
        "Child not found: base_path/@0\n" \
        "File: \n" \
        "Invalid Content: ''\n"
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export PCB fabrication data...\n" \
        "Finished with errors!\n".format(project=project)
    assert code == 1
    assert not os.path.exists(dir)