File: test_mixin.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 (146 lines) | stat: -rw-r--r-- 5,454 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
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
from unittest.mock import MagicMock

import pytest

import briefcase.platforms.linux.flatpak
from briefcase.exceptions import BriefcaseConfigError
from briefcase.integrations.flatpak import Flatpak
from briefcase.integrations.subprocess import Subprocess
from briefcase.platforms.linux.flatpak import LinuxFlatpakCreateCommand


@pytest.fixture
def create_command(dummy_console, tmp_path):
    return LinuxFlatpakCreateCommand(
        console=dummy_console,
        base_path=tmp_path / "base_path",
        data_path=tmp_path / "briefcase",
    )


def test_binary_path(create_command, first_app_config, tmp_path):
    """The binary path is the marker file."""
    binary_path = create_command.binary_path(first_app_config)

    expected_path = (
        tmp_path
        / "base_path"
        / "build"
        / "first-app"
        / "linux"
        / "flatpak"
        / "com.example.first-app"
    )
    assert binary_path == expected_path


def test_project_path(create_command, first_app_config, tmp_path):
    """The project path is the bundle path."""
    project_path = create_command.project_path(first_app_config)
    bundle_path = create_command.bundle_path(first_app_config)

    expected_path = tmp_path / "base_path/build/first-app/linux/flatpak"
    assert expected_path == project_path == bundle_path


def test_distribution_path(create_command, first_app_config, tmp_path):
    """The distribution path is a flatpak bundle."""
    # Force the architecture to something odd for test purposes.
    create_command.tools.host_arch = "gothic"
    distribution_path = create_command.distribution_path(first_app_config)

    expected_path = tmp_path / "base_path/dist/First_App-0.0.1-gothic.flatpak"
    assert distribution_path == expected_path


def test_default_runtime_repo(create_command, first_app_config):
    """The flathub repository is the default runtime repository."""
    expected_repo = ("flathub", "https://flathub.org/repo/flathub.flatpakrepo")
    assert create_command.flatpak_runtime_repo(first_app_config) == expected_repo


def test_custom_runtime_repo(create_command, first_app_config):
    """A custom runtime repo can be specified."""
    first_app_config.flatpak_runtime_repo_alias = "custom_repo"
    first_app_config.flatpak_runtime_repo_url = "https://example.com/flatpak/runtime"

    expected_repo = ("custom_repo", "https://example.com/flatpak/runtime")
    assert create_command.flatpak_runtime_repo(first_app_config) == expected_repo


def test_custom_runtime_repo_no_alias(create_command, first_app_config):
    """If a custom runtime repo URL is specified, an alias must be specified as well."""
    first_app_config.flatpak_runtime_repo_url = "https://example.com/flatpak/runtime"

    with pytest.raises(
        BriefcaseConfigError,
        match="If you specify a custom Flatpak runtime repository",
    ):
        create_command.flatpak_runtime_repo(first_app_config)


def test_custom_runtime(create_command, first_app_config):
    """A custom runtime can be specified."""
    first_app_config.flatpak_runtime = "org.beeware.Platform"
    first_app_config.flatpak_runtime_version = "37.42"
    first_app_config.flatpak_sdk = "org.beeware.SDK"

    assert create_command.flatpak_runtime(first_app_config) == "org.beeware.Platform"
    assert create_command.flatpak_runtime_version(first_app_config) == "37.42"
    assert create_command.flatpak_sdk(first_app_config) == "org.beeware.SDK"


def test_missing_runtime(create_command, first_app_config):
    """Error if App config is missing the runtime."""
    first_app_config.flatpak_runtime_version = "37.42"
    first_app_config.flatpak_sdk = "org.beeware.SDK"

    with pytest.raises(
        BriefcaseConfigError,
        match="Briefcase configuration error: The App does not specify the Flatpak runtime to use",
    ):
        create_command.flatpak_runtime(first_app_config)


def test_missing_sdk(create_command, first_app_config):
    """Error if App config is missing the SDK."""
    first_app_config.flatpak_runtime = "org.beeware.Platform"
    first_app_config.flatpak_runtime_version = "37.42"

    with pytest.raises(
        BriefcaseConfigError,
        match="Briefcase configuration error: The App does not specify the Flatpak SDK to use",
    ):
        create_command.flatpak_sdk(first_app_config)


def test_missing_runtime_version(create_command, first_app_config):
    """Error if App config is missing the runtime version."""
    first_app_config.flatpak_runtime = "org.beeware.Platform"
    first_app_config.flatpak_sdk = "org.beeware.SDK"

    with pytest.raises(
        BriefcaseConfigError,
        match="Briefcase configuration error: The App does not specify the version of the Flatpak runtime to use",
    ):
        create_command.flatpak_runtime_version(first_app_config)


def test_verify_linux(create_command, monkeypatch, tmp_path):
    """Verifying on Linux creates an SDK wrapper."""
    create_command.tools.host_os = "Linux"
    create_command.tools.subprocess = MagicMock(spec_set=Subprocess)

    mock_flatpak_verify = MagicMock(wraps=Flatpak.verify)
    monkeypatch.setattr(
        briefcase.platforms.linux.flatpak.Flatpak,
        "verify",
        mock_flatpak_verify,
    )

    # Verify the tools
    create_command.verify_tools()

    # Flatpak tool was verified
    mock_flatpak_verify.assert_called_once_with(tools=create_command.tools)
    assert isinstance(create_command.tools.flatpak, Flatpak)