File: test_ditto.py

package info (click to toggle)
python-briefcase 0.3.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,596 kB
  • sloc: python: 62,519; makefile: 60
file content (109 lines) | stat: -rw-r--r-- 4,472 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
import platform
import subprocess
from zipfile import ZipFile

import pytest

from briefcase.exceptions import BriefcaseCommandError


@pytest.mark.skipif(
    platform.system() != "Darwin",
    reason="ditto tests can only be performed on macOS",
)
def test_ditto(
    package_command,
    first_app_with_binaries,
    tmp_path,
):
    """An app archive can be built with ditto."""
    app_path = (
        tmp_path
        / "base_path"
        / "build"
        / "first-app"
        / "macos"
        / "app"
        / "First App.app"
    )
    archive_path = tmp_path / "base_path/build/first-app/macos/app/archive.zip"

    # Reconnect the subprocess.run with its live implementation
    package_command.tools.subprocess.run.side_effect = subprocess.run

    # Build the ditto archive
    package_command.ditto_archive(app_path, archive_path)

    # The archive contains the app as the only top level element.
    with ZipFile(archive_path) as archive:
        # zip file can include a “__MACOSX” folder for each document that contains information about
        # the file useful for Finder and will not be in the unzipped set of files
        archived_files = [
            fn for fn in archive.namelist() if not fn.startswith("__MACOSX/")
        ]

        assert sorted(archived_files) == [
            "First App.app/",
            "First App.app/Contents/",
            "First App.app/Contents/Frameworks/",
            "First App.app/Contents/Frameworks/Extras.framework/",
            "First App.app/Contents/Frameworks/Extras.framework/Extras",
            "First App.app/Contents/Frameworks/Extras.framework/Resources/",
            "First App.app/Contents/Frameworks/Extras.framework/Resources/Info.plist",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/1.2/",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/1.2/Extras",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/1.2/libs/",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/1.2/libs/extras.dylib",
            "First App.app/Contents/Frameworks/Extras.framework/Versions/Current",
            "First App.app/Contents/Info.plist",
            "First App.app/Contents/MacOS/",
            "First App.app/Contents/MacOS/First App",
            "First App.app/Contents/Resources/",
            "First App.app/Contents/Resources/app_packages/",
            "First App.app/Contents/Resources/app_packages/Extras.app/",
            "First App.app/Contents/Resources/app_packages/Extras.app/Contents/",
            "First App.app/Contents/Resources/app_packages/Extras.app/Contents/MacOS/",
            "First App.app/Contents/Resources/app_packages/Extras.app/Contents/MacOS/Extras",
            "First App.app/Contents/Resources/app_packages/first.other",
            "First App.app/Contents/Resources/app_packages/first_dylib.dylib",
            "First App.app/Contents/Resources/app_packages/first_so.so",
            "First App.app/Contents/Resources/app_packages/other_binary",
            "First App.app/Contents/Resources/app_packages/second.other",
            "First App.app/Contents/Resources/app_packages/special.binary",
            "First App.app/Contents/Resources/app_packages/subfolder/",
            "First App.app/Contents/Resources/app_packages/subfolder/second_dylib.dylib",
            "First App.app/Contents/Resources/app_packages/subfolder/second_so.so",
            "First App.app/Contents/Resources/app_packages/unknown.binary",
        ]


@pytest.mark.skipif(
    platform.system() != "Darwin",
    reason="ditto tests can only be performed on macOS",
)
def test_ditto_failure(
    package_command,
    first_app_with_binaries,
    tmp_path,
):
    """If ditto fails, an error is raised."""
    app_path = (
        tmp_path
        / "base_path"
        / "build"
        / "first-app"
        / "macos"
        / "app"
        / "First App.app"
    )
    archive_path = tmp_path / "base_path/build/first-app/macos/app/archive.zip"

    # Reconnect the subprocess.run with its live implementation
    package_command.tools.subprocess.run.side_effect = subprocess.CalledProcessError(
        1, cmd=["ditto"]
    )

    # Build the ditto archive
    with pytest.raises(BriefcaseCommandError, match=r"Unable to archive First App.app"):
        package_command.ditto_archive(app_path, archive_path)