-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_platform.py
More file actions
63 lines (43 loc) · 1.85 KB
/
test_platform.py
File metadata and controls
63 lines (43 loc) · 1.85 KB
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
"""Unit tests for the Platform module."""
from __future__ import annotations
from typing import Generator
import pytest
from pythonnative.platform import Platform, _set_platform_for_test, get_platform
@pytest.fixture(autouse=True)
def _reset_platform() -> Generator[None, None, None]:
"""Reset Platform after each test so suite order doesn't matter."""
yield
_set_platform_for_test(None)
def test_default_platform_is_test() -> None:
assert Platform.OS == "test"
assert Platform.is_test is True
assert Platform.is_ios is False
assert Platform.is_android is False
def test_get_platform_matches_os() -> None:
assert get_platform() == Platform.OS
def test_version_string_present() -> None:
assert isinstance(Platform.Version, str)
assert len(Platform.Version) > 0
def test_select_picks_current_platform() -> None:
_set_platform_for_test("ios")
assert Platform.select({"ios": "A", "android": "B"}) == "A"
_set_platform_for_test("android")
assert Platform.select({"ios": "A", "android": "B"}) == "B"
def test_select_falls_back_to_native() -> None:
_set_platform_for_test("ios")
assert Platform.select({"native": "X", "default": "Y"}) == "X"
_set_platform_for_test("test")
# 'test' doesn't match 'native', so falls back to 'default'.
assert Platform.select({"native": "X", "default": "Y"}) == "Y"
def test_select_default_then_explicit() -> None:
_set_platform_for_test("test")
assert Platform.select({"default": "D"}) == "D"
assert Platform.select({}, default="E") == "E"
assert Platform.select({}) is None
def test_set_platform_for_test_toggles_flags() -> None:
_set_platform_for_test("ios")
assert Platform.is_ios is True
assert Platform.is_android is False
_set_platform_for_test("android")
assert Platform.is_ios is False
assert Platform.is_android is True