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
|
"""Tests for projector module."""
from unittest.mock import AsyncMock
import pytest
from jvcprojector import command
from jvcprojector.error import JvcProjectorError
from jvcprojector.projector import JvcProjector
from . import IP, PORT
# pylint: disable=unused-argument
@pytest.mark.asyncio
async def test_init(dev: AsyncMock):
"""Test init succeeds."""
p = JvcProjector(IP, port=PORT)
assert p.host == IP
assert p.port == PORT
with pytest.raises(JvcProjectorError):
assert p.model
with pytest.raises(JvcProjectorError):
assert p.spec
@pytest.mark.asyncio
async def test_connect(dev: AsyncMock):
"""Test connect succeeds."""
p = JvcProjector(IP, port=PORT)
await p.connect()
assert p.host == IP
await p.disconnect()
assert dev.disconnect.call_count == 1
@pytest.mark.asyncio
@pytest.mark.parametrize("dev", [{command.ModelName: "ABCD"}], indirect=True)
async def test_connect_unknown_model(dev: AsyncMock):
"""Test connect with an unknown model succeeds."""
p = JvcProjector(IP, port=PORT)
await p.connect()
assert p.host == IP
assert p.model == "ABCD"
assert p.spec == "UNKOWN"
await p.disconnect()
@pytest.mark.asyncio
@pytest.mark.parametrize("dev", [{command.ModelName: "B2A9"}], indirect=True)
async def test_connect_partial_model_match(dev: AsyncMock):
"""Test connect with a partial model match succeeds."""
p = JvcProjector(IP, port=PORT)
await p.connect()
assert p.host == IP
assert p.model == "B2A9"
assert p.spec == "CS20191-B2A3"
await p.disconnect()
@pytest.mark.asyncio
async def test_get(dev: AsyncMock):
"""Test get method."""
p = JvcProjector(IP, port=PORT)
await p.connect()
# succeeds
assert await p.get(command.Power) == command.Power.ON
assert await p.get("Power") == command.Power.ON
assert await p.get("PW") == command.Power.ON
# fails
with pytest.raises(JvcProjectorError):
await p.get("BAD")
with pytest.raises(JvcProjectorError):
await p.get(command.EShift)
@pytest.mark.asyncio
async def test_set(dev: AsyncMock):
"""Test set method."""
p = JvcProjector(IP, port=PORT)
await p.connect()
# succeeds
await p.set(command.Power, command.Power.ON)
await p.set("Power", command.Power.ON)
await p.set("PW", command.Power.ON)
# fails
with pytest.raises(JvcProjectorError):
await p.set(command.Power, "bad")
with pytest.raises(JvcProjectorError):
await p.set("BAD", "")
with pytest.raises(JvcProjectorError):
await p.set(command.EShift, command.EShift.ON)
@pytest.mark.asyncio
async def test_supports(dev: AsyncMock):
"""Test support method."""
p = JvcProjector(IP, port=PORT)
await p.connect()
# succeeds
assert p.supports(command.Power)
assert p.supports(command.ColorProfile)
# fails
assert not p.supports(command.LaserPower)
with pytest.raises(JvcProjectorError):
p.supports("BAD")
@pytest.mark.asyncio
async def test_describe(dev: AsyncMock):
"""Test describe method."""
p = JvcProjector(IP, port=PORT)
await p.connect()
# succeeds
info = p.describe(command.Power)
assert info["name"] == "Power"
assert info["code"] == "PW"
assert info["reference"] is True
assert info["operation"] is True
assert info["category"] == "System"
assert info["parameter"]["read"]["0"] == "standby"
assert info["parameter"]["read"]["1"] == "on"
assert info["parameter"]["write"]["0"] == "off"
assert info["parameter"]["write"]["1"] == "on"
# fails
with pytest.raises(JvcProjectorError):
p.describe(command.LaserPower)
with pytest.raises(JvcProjectorError):
p.describe("BAD")
@pytest.mark.asyncio
@pytest.mark.parametrize("dev", [{command.ModelName: "B2A3"}], indirect=True)
async def test_capabilities(dev: AsyncMock):
"""Test describe method."""
p = JvcProjector(IP, port=PORT)
await p.connect()
caps = p.capabilities()
assert "Power" in caps
assert "ColorProfile" in caps
assert "03" in caps["ColorProfile"]["parameter"]["read"]
assert "01" not in caps["ColorProfile"]["parameter"]["read"]
assert "LaserPower" not in caps
|