File: test_convert_app.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 (93 lines) | stat: -rw-r--r-- 3,254 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
import os
from unittest import mock

import pytest
from cookiecutter.main import cookiecutter

import briefcase
from briefcase.commands import ConvertCommand
from briefcase.console import Console


@pytest.fixture
def convert_command(tmp_path):
    return ConvertCommand(
        base_path=tmp_path / "project",
        data_path=tmp_path / "data",
        console=Console(),
    )


def test_convert_app_unused_project_overrides(
    monkeypatch,
    convert_command,
    tmp_path,
    capsys,
):
    """The user is informed of unused project configuration overrides."""
    monkeypatch.setattr(briefcase, "__version__", "37.42.7")
    app_context = {
        "formal_name": "My Application",
        "class_name": "MyApplication",
        "app_name": "myapplication",
        "module_name": "mymodule",
        "test_source_dir": "test_files",
    }
    convert_command.build_app_context = mock.MagicMock(return_value=app_context)
    convert_command.build_gui_context = mock.MagicMock(
        return_value={"gui_framework": "None"}
    )
    convert_command.update_cookiecutter_cache = mock.MagicMock(
        return_value="~/.cookiecutters/briefcase-template"
    )
    convert_command.tools.cookiecutter = mock.MagicMock(spec_set=cookiecutter)
    convert_command.migrate_necessary_files = mock.MagicMock()

    # Create the new app, using the default template.
    convert_command.convert_app(
        tmp_path=tmp_path / "working",
        project_overrides={"unused": "override"},
    )

    # App context is constructed
    convert_command.build_app_context.assert_called_once_with({"unused": "override"})
    convert_command.build_gui_context.assert_called_once_with(
        mock.ANY, {"unused": "override"}
    )
    # Template is updated
    convert_command.update_cookiecutter_cache.assert_called_once_with(
        template="https://github.com/beeware/briefcase-template",
        branch="v37.42.7",
    )
    # Cookiecutter is invoked
    convert_command.tools.cookiecutter.assert_called_once_with(
        "~/.cookiecutters/briefcase-template",
        no_input=True,
        output_dir=os.fsdecode(tmp_path / "working"),
        checkout="v37.42.7",
        extra_context={
            "formal_name": "My Application",
            "class_name": "MyApplication",
            "app_name": "myapplication",
            "module_name": "mymodule",
            "test_source_dir": "test_files",
            # The expected app context should now also contain the default template,
            # branch, and Briefcase version.
            "template_source": "https://github.com/beeware/briefcase-template",
            "template_branch": "v37.42.7",
            "briefcase_version": "37.42.7",
            "gui_framework": "None",
        },
        default_config={"replay_dir": str(tmp_path / "data/templates/.replay")},
    )
    convert_command.migrate_necessary_files.assert_called_once_with(
        tmp_path / "working" / app_context["app_name"],
        app_context["test_source_dir"],
        "mymodule",
    )

    unused_project_override_warning = (
        "WARNING: These project configuration overrides were not used:\n\n"
        "    unused = override"
    )
    assert unused_project_override_warning in capsys.readouterr().out