File: test_cli_args.py

package info (click to toggle)
python-schema-salad 8.9.20250408123006-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,056 kB
  • sloc: python: 19,177; cpp: 2,631; cs: 1,869; java: 1,341; makefile: 187; xml: 184; sh: 103; javascript: 46
file content (39 lines) | stat: -rw-r--r-- 1,142 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
""" test different sets of command line arguments"""

import sys  # for capturing print() output
from collections.abc import Iterator
from contextlib import contextmanager
from io import StringIO

import schema_salad.main as cli_parser


@contextmanager
def captured_output() -> Iterator[tuple[StringIO, StringIO]]:
    new_out, new_err = StringIO(), StringIO()
    old_out, old_err = sys.stdout, sys.stderr
    try:
        sys.stdout, sys.stderr = new_out, new_err
        yield sys.stdout, sys.stderr
    finally:
        sys.stdout, sys.stderr = old_out, old_err


def test_version() -> None:
    args: list[list[str]] = [["--version"], ["-v"]]
    for arg in args:
        with captured_output() as (out, err):
            cli_parser.main(arg)

        response = out.getvalue().strip()  # capture output and strip newline
        assert "Current version" in response


def test_empty_input() -> None:
    # running schema_salad tool without any args
    args: list[str] = []
    with captured_output() as (out, err):
        cli_parser.main(args)

    response = out.getvalue().strip()
    assert "error: too few arguments" in response