File: test_export_generic_bom.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 (63 lines) | stat: -rw-r--r-- 2,366 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import params
import pytest

"""
Test command "open-project --export-bom"
"""


@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 + '/bom/bom.csv'
    abspath = cli.abspath(relpath)
    assert not os.path.exists(abspath)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-bom=' + relpath,
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export generic BOM to '{project.output_dir}/bom/bom.csv'...\n" \
        "  => '{project.output_dir_native}//bom//bom.csv'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(abspath)


@pytest.mark.parametrize("project", [
    params.PROJECT_WITH_TWO_BOARDS_LPP_PARAM,
    params.PROJECT_WITH_TWO_BOARDS_LPPZ_PARAM,
])
def test_export_multiple_files(cli, project):
    cli.add_project(project.dir, as_lppz=project.is_lppz)
    relpath1 = project.output_dir + '/bom1.csv'
    abspath1 = cli.abspath(relpath1)
    assert not os.path.exists(abspath1)
    relpath2 = project.output_dir + '/bom2.csv'
    abspath2 = cli.abspath(relpath2)
    assert not os.path.exists(abspath2)
    code, stdout, stderr = cli.run('open-project',
                                   '--export-bom=' + relpath1,  # --arg="value"
                                   '--export-bom', relpath2,  # --arg "value"
                                   project.path)
    assert stderr == ''
    assert stdout == \
        "Open project '{project.path}'...\n" \
        "Export generic BOM to '{project.output_dir}/bom1.csv'...\n" \
        "  => '{project.output_dir_native}//bom1.csv'\n" \
        "Export generic BOM to '{project.output_dir}/bom2.csv'...\n" \
        "  => '{project.output_dir_native}//bom2.csv'\n" \
        "SUCCESS\n".format(project=project).replace('//', os.sep)
    assert code == 0
    assert os.path.exists(abspath1)
    assert os.path.exists(abspath2)