File: test_Flatpak__run.py

package info (click to toggle)
python-briefcase 0.3.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,596 kB
  • sloc: python: 62,519; makefile: 60
file content (108 lines) | stat: -rw-r--r-- 3,234 bytes parent folder | download
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
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",
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )

    # 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"],
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )

    # 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,
        **({"env": {"BRIEFCASE_DEBUG": "1"}} if tool_debug_mode else {}),
    )

    # 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 {}),
    )