File: test_DockerAppContext__check_output.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (81 lines) | stat: -rw-r--r-- 2,651 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
import subprocess
from unittest.mock import ANY

import pytest

from briefcase.console import LogLevel

# These tests ignore the elsewhere-tested complexities of Dockerizing
# the arguments and just focuses on the semantics of a check_output() call.


@pytest.mark.usefixtures("mock_docker")
@pytest.mark.usefixtures("mock_docker_app_context")
def test_simple_call(mock_tools, my_app, tmp_path, sub_check_output_kw, capsys):
    """A simple call will be invoked."""
    output = mock_tools[my_app].app_context.check_output(["hello", "world"])

    assert output == "goodbye\n"
    mock_tools[my_app].app_context._dockerize_args.assert_called_once_with(
        ["hello", "world"]
    )
    mock_tools.subprocess._subprocess.check_output.assert_called_with(
        ANY,
        env={"DOCKER_CLI_HINTS": "false", "PROCESS_ENV_VAR": "VALUE"},
        **sub_check_output_kw,
    )
    assert capsys.readouterr().out == ""


@pytest.mark.usefixtures("mock_docker")
@pytest.mark.usefixtures("mock_docker_app_context")
def test_call_with_extra_kwargs(mock_tools, my_app, tmp_path, capsys):
    """Extra keyword arguments are passed through to subprocess."""
    output = mock_tools[my_app].app_context.check_output(
        ["hello", "world"],
        encoding="ISO-42",
        extra="extra",
    )

    assert output == "goodbye\n"
    mock_tools[my_app].app_context._dockerize_args.assert_called_once_with(
        ["hello", "world"],
        encoding="ISO-42",
        extra="extra",
    )
    mock_tools.subprocess._subprocess.check_output.assert_called_once_with(
        ANY,
        extra="extra",
        encoding="ISO-42",
        stderr=subprocess.STDOUT,
        text=True,
        errors="backslashreplace",
        env={"DOCKER_CLI_HINTS": "false", "PROCESS_ENV_VAR": "VALUE"},
    )
    assert capsys.readouterr().out == ""


@pytest.mark.usefixtures("mock_docker")
@pytest.mark.usefixtures("mock_docker_app_context")
def test_simple_verbose_call(
    mock_tools,
    my_app,
    tmp_path,
    sub_check_output_kw,
    capsys,
):
    """If verbosity is turned out, there is output."""
    mock_tools[my_app].app_context.tools.console.verbosity = LogLevel.DEBUG

    output = mock_tools[my_app].app_context.check_output(["hello", "world"])

    assert output == "goodbye\n"
    mock_tools[my_app].app_context._dockerize_args.assert_called_once_with(
        ["hello", "world"]
    )
    mock_tools.subprocess._subprocess.check_output.assert_called_once_with(
        ANY,
        env={"DOCKER_CLI_HINTS": "false", "PROCESS_ENV_VAR": "VALUE"},
        **sub_check_output_kw,
    )
    assert ">>> Running Command:\n" in capsys.readouterr().out