Skip to content

Commit 6c4b3c2

Browse files
committed
Complete code coverage
1 parent b493106 commit 6c4b3c2

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/briefcase/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def validate_document_type_config(document_type_id, document_type):
161161
macOS.setdefault("UTTypeConformsTo", ["public.data", "public.content"])
162162

163163
macOS.setdefault("CFBundleTypeRole", "Viewer")
164+
else: # pragma: no-cover-if-is-macos
165+
pass
164166

165167

166168
VALID_BUNDLE_RE = re.compile(r"[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$")

src/briefcase/platforms/macOS/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from briefcase.exceptions import BriefcaseCommandError
1212

13+
CORETYPES_PATH = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist"
14+
1315

1416
def sha256_file_digest(path: Path) -> str:
1517
"""Compute a sha256 checksum digest of a file.
@@ -289,9 +291,7 @@ def mime_type_to_UTI(mime_type: str) -> str | None: # pragma: no-cover-if-not-m
289291
The UTI for the MIME type, or None if the UTI cannot be determined.
290292
"""
291293
try:
292-
plist_data = pathlib.Path(
293-
"/System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist"
294-
).read_bytes()
294+
plist_data = pathlib.Path(CORETYPES_PATH).read_bytes()
295295
except FileNotFoundError:
296296
# If the file is not found, we assume that the system is not macOS
297297
# or the file has been moved in recent macOS versions.

tests/config/test_document_type_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from briefcase.config import validate_document_type_config
44
from briefcase.exceptions import BriefcaseConfigError
5+
from briefcase.platforms.macOS import utils
56

67

78
@pytest.fixture
@@ -195,3 +196,9 @@ def test_document_type_macOS_config_with_unknown_mimetype(valid_document):
195196
valid_document["mime_type"] = "custom/mytype"
196197
validate_document_type_config("ext", valid_document)
197198
assert "LSItemContentType" not in valid_document["macOS"].keys()
199+
200+
201+
def test_mime_type_to_uti_with_nonexisting_coretypes_file(monkeypatch):
202+
"""Test that mime_type_to_UTI returns None if the coretypes file doesn't exist."""
203+
monkeypatch.setattr(utils, "CORETYPES_PATH", "/does/not/exist")
204+
assert utils.mime_type_to_UTI("application/pdf") is None

0 commit comments

Comments
 (0)