File: test_Flatpak__run.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 (149 lines) | stat: -rw-r--r-- 4,287 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import subprocess
from unittest import mock

import pytest

from briefcase.console import LogLevel


@pytest.mark.parametrize("tool_debug_mode", (True, False))
def test_run(flatpak, tool_debug_mode):
    """A Flatpak project can be executed."""
    # Enable verbose tool logging
    if tool_debug_mode:
        flatpak.tools.console.verbosity = LogLevel.DEEP_DEBUG

    # Set up the log streamer to return a known stream
    log_popen = mock.MagicMock()
    flatpak.tools.subprocess.Popen.return_value = log_popen

    # Call run()
    result = flatpak.run(bundle_identifier="com.example.my-app")

    # The expected call was made
    flatpak.tools.subprocess.Popen.assert_called_once_with(
        [
            "flatpak",
            "run",
        ]
        + (["--verbose"] if tool_debug_mode else [])
        + ["com.example.my-app"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        bufsize=1,
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )

    # The popen object was returned.
    assert result == log_popen


@pytest.mark.parametrize("tool_debug_mode", (True, False))
def test_run_with_args(flatpak, tool_debug_mode):
    """A Flatpak project can be executed with additional arguments."""
    # Enable verbose tool logging
    if tool_debug_mode:
        flatpak.tools.console.verbosity = LogLevel.DEEP_DEBUG

    # Set up the log streamer to return a known stream
    log_popen = mock.MagicMock()
    flatpak.tools.subprocess.Popen.return_value = log_popen

    # Call run()
    result = flatpak.run(
        bundle_identifier="com.example.my-app",
        args=["foo", "bar"],
    )

    # The expected call was made
    flatpak.tools.subprocess.Popen.assert_called_once_with(
        [
            "flatpak",
            "run",
        ]
        + (["--verbose"] if tool_debug_mode else [])
        + ["com.example.my-app"]
        + ["foo", "bar"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        bufsize=1,
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )

    # The popen object was returned.
    assert result == log_popen


@pytest.mark.parametrize("tool_debug_mode", (True, False))
def test_run_non_streaming(flatpak, tool_debug_mode):
    """A Flatpak project can be executed in non-streaming mode."""
    # Enable verbose tool logging
    if tool_debug_mode:
        flatpak.tools.console.verbosity = LogLevel.DEEP_DEBUG

    # Call run()
    flatpak.run(
        bundle_identifier="com.example.my-app",
        args=["foo", "bar"],
        stream_output=False,
    )

    # The expected call was made
    flatpak.tools.subprocess.run.assert_called_once_with(
        [
            "flatpak",
            "run",
        ]
        + (["--verbose"] if tool_debug_mode else [])
        + ["com.example.my-app"]
        + ["foo", "bar"],
        bufsize=1,
        stream_output=False,
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )


@pytest.mark.parametrize("tool_debug_mode", (True, False))
def test_main_module_override(flatpak, tool_debug_mode):
    """The main module can be overridden."""
    # Enable verbose tool logging
    if tool_debug_mode:
        flatpak.tools.console.verbosity = LogLevel.DEEP_DEBUG

    # Set up the log streamer to return a known stream
    log_popen = mock.MagicMock()
    flatpak.tools.subprocess.Popen.return_value = log_popen

    # Call run()
    result = flatpak.run(
        bundle_identifier="com.example.my-app",
        main_module="org.beeware.test-case",
    )

    # The expected call was made
    flatpak.tools.subprocess.Popen.assert_called_once_with(
        [
            "flatpak",
            "run",
        ]
        + (["--verbose"] if tool_debug_mode else [])
        + [
            "com.example.my-app",
        ],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        bufsize=1,
        env=(
            {
                "BRIEFCASE_MAIN_MODULE": "org.beeware.test-case",
                "BRIEFCASE_DEBUG": "1",
            }
            if tool_debug_mode
            else {
                "BRIEFCASE_MAIN_MODULE": "org.beeware.test-case",
            }
        ),
    )

    # The popen object was returned.
    assert result == log_popen