File: test_export_netlist.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 (105 lines) | stat: -rw-r--r-- 4,471 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import params
import pytest

"""
Test command "open-project --export-netlist"
"""


@pytest.mark.parametrize("project", [params.EMPTY_PROJECT_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)')

    relpath = project.output_dir + '/netlist/netlist.d356'
    abspath = cli.abspath(relpath)
    assert not os.path.exists(abspath)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-netlist=' + relpath,
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export netlist to 'Empty Project/output/v1/netlist/netlist.d356'...\n" \
        "SUCCESS\n".format(project=project)
    assert code == 0
    assert not os.path.exists(abspath)  # nothing exported


@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)
    fp = project.output_dir + '/netlist/{{BOARD}}.d356'
    dir = cli.abspath(project.output_dir + '/netlist')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-netlist=' + fp,
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export netlist to '{project.output_dir}/netlist/{{{{BOARD}}}}.d356'...\n" \
        "  - 'default' => '{project.output_dir_native}//netlist//default.d356'\n" \
        "  - 'copy' => '{project.output_dir_native}//netlist//copy.d356'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert len(os.listdir(dir)) == 2


@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)
    fp = project.output_dir + '/netlist/{{BOARD}}.d356'
    dir = cli.abspath(project.output_dir + '/netlist')
    assert not os.path.exists(dir)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-netlist', fp,
                                   '--board=copy',
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export netlist to '{project.output_dir}/netlist/{{{{BOARD}}}}.d356'...\n" \
        "  - 'copy' => '{project.output_dir_native}//netlist//copy.d356'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(dir)
    assert os.listdir(dir) == ['copy.d356']


@pytest.mark.parametrize("project", [params.PROJECT_WITH_TWO_BOARDS_LPP])
def test_export_project_with_two_conflicting_boards_fails(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    fp = project.output_dir + '/netlist.d356'
    code, stdout, stderr = cli.run('open-project',
                                   '--export-netlist=' + fp,
                                   project.path)
    assert stderr == \
        "ERROR: The file '{project.output_dir_native}//netlist.d356' 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 netlist to '{project.output_dir}/netlist.d356'...\n" \
        "  - 'default' => '{project.output_dir_native}//netlist.d356'\n" \
        "  - 'copy' => '{project.output_dir_native}//netlist.d356'\n" \
        "Finished with errors!\n".format(project=project).replace('//', os.sep)
    assert code == 1