File: test_install_dev_requirements.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 (167 lines) | stat: -rw-r--r-- 4,670 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import sys
from subprocess import CalledProcessError

import pytest

from briefcase.console import LogLevel
from briefcase.exceptions import RequirementsInstallError


@pytest.mark.parametrize("logging_level", [LogLevel.INFO, LogLevel.DEEP_DEBUG])
def test_install_requirements_no_error(dev_command, first_app, logging_level):
    """Ensure run is executed properly to install requirements."""
    # Configure logging level
    dev_command.console.verbosity = logging_level

    first_app.requires = ["package-one", "package_two", "packagethree"]

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_called_once_with(
        [
            sys.executable,
            "-u",
            "-X",
            "utf8",
            "-m",
            "pip",
            "install",
            "--upgrade",
        ]
        + (["-vv"] if logging_level == LogLevel.DEEP_DEBUG else [])
        + ["package-one", "package_two", "packagethree"],
        check=True,
        encoding="UTF-8",
    )


def test_install_requirements_error(dev_command, first_app):
    """Ensure RequirementsInstallError exception is raised for install errors."""
    first_app.requires = ["package-one", "package_two", "packagethree"]

    dev_command.tools.subprocess.run.side_effect = CalledProcessError(
        returncode=-1, cmd="pip"
    )

    with pytest.raises(
        RequirementsInstallError,
        match="Unable to install requirements.",
    ):
        dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_called_once_with(
        [
            sys.executable,
            "-u",
            "-X",
            "utf8",
            "-m",
            "pip",
            "install",
            "--upgrade",
            "package-one",
            "package_two",
            "packagethree",
        ],
        check=True,
        encoding="UTF-8",
    )


def test_no_requirements(dev_command, first_app):
    """Ensure dependency installation is not attempted when nothing to install."""
    first_app.requires = []

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_not_called()


def test_no_requirements_with_requirement_installer_Args(dev_command, first_app):
    """Ensure dependency installation is not attempted when nothing to install,
    even if requirement installer args are defined."""
    first_app.requires = []
    first_app.requirement_installer_args = ["--no-cache"]

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_not_called()


def test_install_requirements_test_mode(dev_command, first_app):
    """If an app has test requirements, they are also installed."""
    first_app.requires = ["package-one", "package_two", "packagethree"]
    first_app.test_requires = ["test-one", "test_two"]

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_called_once_with(
        [
            sys.executable,
            "-u",
            "-X",
            "utf8",
            "-m",
            "pip",
            "install",
            "--upgrade",
            "package-one",
            "package_two",
            "packagethree",
            "test-one",
            "test_two",
        ],
        check=True,
        encoding="UTF-8",
    )


def test_only_test_requirements(dev_command, first_app):
    """If an app only has test requirements, they're installed correctly."""
    first_app.requires = None
    first_app.test_requires = ["test-one", "test_two"]

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_called_once_with(
        [
            sys.executable,
            "-u",
            "-X",
            "utf8",
            "-m",
            "pip",
            "install",
            "--upgrade",
            "test-one",
            "test_two",
        ],
        check=True,
        encoding="UTF-8",
    )


def test_requirement_installer_args(dev_command, first_app):
    """If an app has requirement installer args, they're used correctly."""
    first_app.requires = ["one", "two"]
    first_app.requirement_installer_args = ["--no-cache"]

    dev_command.install_dev_requirements(app=first_app)

    dev_command.tools.subprocess.run.assert_called_once_with(
        [
            sys.executable,
            "-u",
            "-X",
            "utf8",
            "-m",
            "pip",
            "install",
            "--upgrade",
            "one",
            "two",
            "--no-cache",
        ],
        check=True,
        encoding="UTF-8",
    )