File: test_colormode_imports.py

package info (click to toggle)
pyswitchbot 0.72.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 876 kB
  • sloc: python: 12,717; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 3,137 bytes parent folder | download
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
"""Test ColorMode imports for backward compatibility."""


def test_colormode_import_from_main_module():
    """Test that ColorMode can be imported from the main switchbot module."""
    from switchbot import ColorMode  # noqa: PLC0415

    # Verify it's the enum we expect
    assert hasattr(ColorMode, "OFF")
    assert hasattr(ColorMode, "COLOR_TEMP")
    assert hasattr(ColorMode, "RGB")
    assert hasattr(ColorMode, "EFFECT")

    # Verify the values
    assert ColorMode.OFF.value == 0
    assert ColorMode.COLOR_TEMP.value == 1
    assert ColorMode.RGB.value == 2
    assert ColorMode.EFFECT.value == 3


def test_colormode_import_from_device_module():
    """Test that ColorMode can be imported from switchbot.devices.device for backward compatibility."""
    from switchbot.devices.device import ColorMode  # noqa: PLC0415

    # Verify it's the enum we expect
    assert hasattr(ColorMode, "OFF")
    assert hasattr(ColorMode, "COLOR_TEMP")
    assert hasattr(ColorMode, "RGB")
    assert hasattr(ColorMode, "EFFECT")

    # Verify the values
    assert ColorMode.OFF.value == 0
    assert ColorMode.COLOR_TEMP.value == 1
    assert ColorMode.RGB.value == 2
    assert ColorMode.EFFECT.value == 3


def test_colormode_import_from_const():
    """Test that ColorMode can be imported from switchbot.const."""
    from switchbot.const import ColorMode  # noqa: PLC0415

    # Verify it's the enum we expect
    assert hasattr(ColorMode, "OFF")
    assert hasattr(ColorMode, "COLOR_TEMP")
    assert hasattr(ColorMode, "RGB")
    assert hasattr(ColorMode, "EFFECT")

    # Verify the values
    assert ColorMode.OFF.value == 0
    assert ColorMode.COLOR_TEMP.value == 1
    assert ColorMode.RGB.value == 2
    assert ColorMode.EFFECT.value == 3


def test_colormode_import_from_const_light():
    """Test that ColorMode can be imported from switchbot.const.light."""
    from switchbot.const.light import ColorMode  # noqa: PLC0415

    # Verify it's the enum we expect
    assert hasattr(ColorMode, "OFF")
    assert hasattr(ColorMode, "COLOR_TEMP")
    assert hasattr(ColorMode, "RGB")
    assert hasattr(ColorMode, "EFFECT")

    # Verify the values
    assert ColorMode.OFF.value == 0
    assert ColorMode.COLOR_TEMP.value == 1
    assert ColorMode.RGB.value == 2
    assert ColorMode.EFFECT.value == 3


def test_all_colormode_imports_are_same_object():
    """Test that all ColorMode imports reference the same enum object."""
    from switchbot import ColorMode as ColorMode1  # noqa: PLC0415
    from switchbot.const import ColorMode as ColorMode3  # noqa: PLC0415
    from switchbot.const.light import ColorMode as ColorMode4  # noqa: PLC0415
    from switchbot.devices.device import ColorMode as ColorMode2  # noqa: PLC0415

    # They should all be the exact same object
    assert ColorMode1 is ColorMode2
    assert ColorMode2 is ColorMode3
    assert ColorMode3 is ColorMode4

    # And their members should be the same
    assert ColorMode1.OFF is ColorMode2.OFF
    assert ColorMode1.COLOR_TEMP is ColorMode3.COLOR_TEMP
    assert ColorMode1.RGB is ColorMode4.RGB
    assert ColorMode1.EFFECT is ColorMode2.EFFECT