File: conftest.py

package info (click to toggle)
python-check-jsonschema 0.34.0-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 3,560 kB
  • sloc: python: 5,527; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 934 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
import textwrap

import pytest

from check_jsonschema import main as cli_main


def _render_result(result):
    return f"""
output:
{textwrap.indent(result.output, "  ")}

stderr:
{textwrap.indent(result.stderr, "  ")}
"""


@pytest.fixture
def run_line(cli_runner):
    def func(cli_args, *args, **kwargs):
        assert cli_args[0] == "check-jsonschema"
        if "catch_exceptions" not in kwargs:
            kwargs["catch_exceptions"] = False
        return cli_runner.invoke(cli_main, cli_args[1:], *args, **kwargs)

    return func


@pytest.fixture
def run_line_simple(run_line):
    def func(cli_args, *args, full_traceback: bool = True, **kwargs):
        res = run_line(
            ["check-jsonschema"]
            + (["--traceback-mode", "full"] if full_traceback else [])
            + cli_args,
            *args,
            **kwargs,
        )
        assert res.exit_code == 0, _render_result(res)

    return func