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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
import os
def test_dmg_with_installer_icon(package_command, first_app_with_binaries, tmp_path):
"""An installer icon can be specified for a DMG."""
# Specify an installer icon, and create the matching file.
first_app_with_binaries.installer_icon = "pretty"
with open(tmp_path / "base_path/pretty.icns", "wb") as f:
f.write(b"A pretty installer icon")
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
"icon": os.fsdecode(tmp_path / "base_path/pretty.icns"),
},
)
def test_dmg_with_missing_installer_icon(
package_command,
first_app_with_binaries,
tmp_path,
capsys,
):
"""If an installer icon is specified, but the specific file is missing, there is a
warning."""
# Specify an installer icon, but don't create the matching file.
first_app_with_binaries.installer_icon = "pretty"
first_app_with_binaries.packaging_format = "dmg"
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
},
)
# The warning about a missing icon was output
assert (
"Can't find pretty.icns to use as DMG installer icon\n"
in capsys.readouterr().out
)
def test_dmg_with_app_installer_icon(
package_command,
first_app_with_binaries,
tmp_path,
):
"""An installer will fall back to an app icon for a DMG."""
# Specify an app icon, and create the matching file.
first_app_with_binaries.icon = "pretty_app"
with open(tmp_path / "base_path/pretty_app.icns", "wb") as f:
f.write(b"A pretty app icon")
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
"icon": os.fsdecode(tmp_path / "base_path/pretty_app.icns"),
},
)
def test_dmg_with_missing_app_installer_icon(
package_command,
first_app_with_binaries,
tmp_path,
capsys,
):
"""If an app icon is specified, but the specific file is missing, there is a
warning."""
# Specify an app icon, but don't create the matching file.
first_app_with_binaries.icon = "pretty_app"
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
},
)
# The warning about a missing icon was output
assert (
"Can't find pretty_app.icns to use as fallback DMG installer icon\n"
in capsys.readouterr().out
)
def test_dmg_with_installer_background(
package_command,
first_app_with_binaries,
tmp_path,
):
"""An installer can be built with an installer background."""
# Specify an installer background, and create the matching file.
first_app_with_binaries.installer_background = "pretty_background"
with open(tmp_path / "base_path/pretty_background.png", "wb") as f:
f.write(b"A pretty background")
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
"background": os.fsdecode(tmp_path / "base_path/pretty_background.png"),
},
)
def test_dmg_with_missing_installer_background(
package_command,
first_app_with_binaries,
tmp_path,
capsys,
):
"""If an installer image is specified, but the specific file is missing, there is a
warning."""
# Specify an installer background, but don't create the matching file.
first_app_with_binaries.installer_background = "pretty_background"
first_app_with_binaries.packaging_format = "dmg"
# Package the app without signing or notarization
package_command.package_app(
first_app_with_binaries,
notarize_app=False,
adhoc_sign=True,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(
tmp_path
/ "base_path"
/ "build"
/ "first-app"
/ "macos"
/ "app"
/ "First App.app"
)
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
},
)
# The warning about a missing background was output
assert (
"Can't find pretty_background.png to use as DMG background\n"
in capsys.readouterr().out
)
def test_dmg_external_app(
package_command,
external_first_app,
sekrit_identity,
tmp_path,
capsys,
):
"""An external macOS App can be packaged as a signed, notarized DMG by default."""
# Select a codesigning identity
package_command.select_identity.return_value = sekrit_identity
# Package the app. Sign and notarize by default. Use the base command's interface to
# ensure the full cleanup process is tested.
package_command._package_app(
external_first_app,
update=False,
packaging_format="dmg",
)
# A request has been made to sign the app
package_command.sign_app.assert_called_once_with(
app=external_first_app,
identity=sekrit_identity,
)
# The DMG has been built as expected
package_command.dmgbuild.build_dmg.assert_called_once_with(
filename=os.fsdecode(tmp_path / "base_path/dist/First App-0.0.1.dmg"),
volume_name="First App 0.0.1",
settings={
"files": [
os.fsdecode(tmp_path / "base_path" / "external" / "First App.app")
],
"symlinks": {"Applications": "/Applications"},
"icon_locations": {
"First App.app": (75, 75),
"Applications": (225, 75),
},
"window_rect": ((600, 600), (350, 150)),
"icon_size": 64,
"text_size": 12,
},
)
# A request was made to sign the DMG as well.
# This ignores the calls that would have been made transitively
# by calling sign_app()
package_command.sign_file.assert_called_once_with(
tmp_path / "base_path/dist/First App-0.0.1.dmg",
identity=sekrit_identity,
)
# A request was made to notarize the DMG
package_command.notarize.assert_called_once_with(
external_first_app,
identity=sekrit_identity,
)
# The app doesn't specify an app icon or installer icon, so there's no
# mention about the DMG installer icon in the console log.
assert "DMG installer icon" not in capsys.readouterr().out
|