FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test(utils): cover desktop platform detection by glenlouis8 · Pull Request #68 · pythonnative/pythonnative · GitHub

test(utils): cover desktop platform detection - #68

Merged
owenthcarey merged 2 commits into
pythonnative:mainfrom
glenlouis8:test/utils-desktop-detection
Sep 8, 2026
Merged

owenthcarey merged 2 commits into
pythonnative:mainfrom
glenlouis8:test/utils-desktop-detection

Conversation

Copy link
Copy Markdown
Contributor

What

  • Add unit tests for _detect_desktop() and for the mutual exclusion between IS_ANDROID, IS_IOS and IS_DESKTOP.

Why

  • tests/test_utils.py covered _detect_ios() thoroughly but nothing exercised the desktop backend or the precedence logic at utils.py:105, so a regression there would have gone unnoticed. That logic is what keeps a component from falling through every platform branch during pn preview (the confusion described in FAQ on platform-specific code omits the browser preview (IS_WEB) #59).

How (brief)

  • TestDesktopDetection follows the existing _detect_ios monkeypatch pattern: PN_PLATFORM=desktop returns True; unset, empty, another value, or a bare host platform returns False.
  • TestPlatformFlagPrecedence covers _is_desktop = (not _is_android) and (not _is_ios) and _detect_desktop(). A _redetect() helper clears the cached _is_* globals and swaps in forced detectors, since all three flags are computed once at import time and there is no public seam to re-run detection through. monkeypatch restores both the caches and the real detectors at teardown. A parametrized sweep over all eight signal combinations asserts at most one flag is ever True.
  • TestPlatformFlagsConsistency widened from two flags to three, including the PN_PLATFORM skip guard so the suite still passes when run under pn preview.

Testing

  • pytest -q tests/test_utils.py passes (27 tests, up from 9); ./scripts/check.sh passes.

Risks/Impact

  • Tests only, no source changes, no behavior change.

Docs/Follow-ups

Closes #40

Merge current main and preserve the contributed platform precedence coverage. Use the web preview detection API introduced in pythonnative#74 and verify that the retired desktop override is ignored.
owenthcarey merged commit fd831c9 into pythonnative:main Sep 8, 2026
25 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for desktop platform detection in utils

2 participants


Back | FazBrowse Home | New Git URL