File: test_help.py

package info (click to toggle)
librepcb 1.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 58,488 kB
  • sloc: cpp: 267,986; python: 12,100; ansic: 6,899; xml: 234; sh: 215; makefile: 115; perl: 73
file content (71 lines) | stat: -rw-r--r-- 1,889 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Test "--help"

Note: It might look a bit picky to compare the CLI output with *exact* values,
but in the end it's very easy to update the expected values after each change
and it heavily increases test coverage.
"""

HELP_TEXT = """\
Usage: {executable} [options] command
LibrePCB Command Line Interface

Options:
  -h, --help     Print this message.
  -V, --version  Displays version information.
  -v, --verbose  Verbose output.

Arguments:
  command        The command to execute (see list below).

Commands:
  open-library   Open a library to execute library-related tasks.
  open-project   Open a project to execute project-related tasks.
  open-step      Open a STEP model to execute STEP-related tasks outside of a library.

List command-specific options:
  {executable} <command> --help
"""

ERROR_TEXT = """\
{error}
Usage: {executable} [options] command
Help: {executable} --help
"""


def test_explicit(cli):
    code, stdout, stderr = cli.run('--help')
    assert stderr == ''
    assert stdout == HELP_TEXT.format(executable=cli.executable)
    assert code == 0


def test_implicit_if_no_arguments(cli):
    code, stdout, stderr = cli.run()
    assert stderr == ''
    assert stdout == HELP_TEXT.format(executable=cli.executable)
    assert code == 0


def test_implicit_if_passing_invalid_command(cli):
    code, stdout, stderr = cli.run('invalid-command')
    assert stderr == ERROR_TEXT.format(
        executable=cli.executable,
        error="Unknown command 'invalid-command'.",
    )
    assert stdout == ''
    assert code == 1


def test_implicit_if_passing_invalid_argument(cli):
    code, stdout, stderr = cli.run('--invalid-argument')
    assert stderr == ERROR_TEXT.format(
        executable=cli.executable,
        error="Unknown option 'invalid-argument'.",
    )
    assert stdout == ''
    assert code == 1