Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
combined = command1 + command2
assert combined._data == DATA_DICT_INT
command1 = Command('method', 'path', DATA_DICT_INT)
command2 = Command('method', 'path', DATA_DICT_STRING)
combined = command1 + command2
assert combined._data == DATA_DICT_INTSTRING
command1 = Command('method', 'path', DATA_DICT_STRING)
command2 = Command('method', 'path', DATA_DICT_STRING2)
combined = command1 + command2
assert combined._data == DATA_DICT_STRING2
command1 = Command('method', 'path', DATA_DICT_INT)
command2 = Command('method', 'path', DATA_DICT_STRING2)
command3 = Command('method', 'path', DATA_DICT_STRING)
combined = command1 + command2 + command3
assert combined._data == DATA_DICT_INTSTRING
def test_property_access():
def pr():
pass
def ec():
pass
command = Command(method='method',
path='path',
data='data',
parse_json=True,
observe=False,
observe_duration=0,
process_result=pr,
err_callback=ec)
assert command.method == 'method'
assert command.path == 'path'
assert command.parse_json is True
assert command.observe is False
assert command.observe_duration == 0
assert command.process_result == pr
assert command.err_callback == ec
async def test_request_returns_single(monkeypatch):
monkeypatch.setattr('aiocoap.Context.create_client_context',
mock_create_context)
api = APIFactory('127.0.0.1').request
command = Command('', '')
response = await api(command)
assert type(response) != list
def test_combining_list_keys():
DATA_EMPTY_LIST = {'key_list': []}
DATA_INT_LIST1 = {'key_list': [0, 1, 2]}
DATA_INT_LIST2 = {'key_list': [10, 11, 12]}
command1 = Command('method', 'path', DATA_EMPTY_LIST)
command2 = Command('method', 'path', DATA_INT_LIST1)
combined = command1 + command2
assert combined._data == DATA_INT_LIST1
# Duplicated keys are replaced if not dicts
command1 = Command('method', 'path', DATA_INT_LIST1)
command2 = Command('method', 'path', DATA_INT_LIST2)
combined = command1 + command2
assert combined._data == DATA_INT_LIST2
command1 = Command('method', 'path', DATA_EMPTY_DICT)
command2 = Command('method', 'path', DATA_DICT_INT)
combined = command1 + command2
assert combined._data == DATA_DICT_INT
command1 = Command('method', 'path', DATA_DICT_INT)
command2 = Command('method', 'path', DATA_DICT_STRING)
combined = command1 + command2
assert combined._data == DATA_DICT_INTSTRING
command1 = Command('method', 'path', DATA_DICT_STRING)
command2 = Command('method', 'path', DATA_DICT_STRING2)
combined = command1 + command2
assert combined._data == DATA_DICT_STRING2
command1 = Command('method', 'path', DATA_DICT_INT)
command2 = Command('method', 'path', DATA_DICT_STRING2)
command3 = Command('method', 'path', DATA_DICT_STRING)
combined = command1 + command2 + command3
assert combined._data == DATA_DICT_INTSTRING
def light(raw):
return Device(raw).light_control.lights[0]
def test_binary_division():
dev_ws = Device(LIGHT_WS).light_control.lights[0]
dev_color = Device(LIGHT_CWS).light_control.lights[0]
assert dev_ws.dimmer == 254
assert dev_ws.color_temp == 400
assert dev_color.hex_color == 'f1e0b5'
assert dev_color.xy_color == (30015, 26870)
from pytradfri.device import Device
from devices import (
LIGHT_W, LIGHT_WS, LIGHT_CWS, LIGHT_PHILIPS, REMOTE_CONTROL,
MOTION_SENSOR, OUTLET, BLIND)
@pytest.fixture
def device():
return Device(LIGHT_WS)
input_devices = (
("comment", "device"),
[
("Remote control", Device(REMOTE_CONTROL)),
("Motion sensor", Device(MOTION_SENSOR)),
]
)
output_devices = (
("comment", "device"),
[
("White fixed color bulb", Device(LIGHT_W)),
("White spectrum bulb", Device(LIGHT_WS)),
("Full color bulb", Device(LIGHT_CWS)),
("Philips Hue bulb", Device(LIGHT_PHILIPS)),
]
)
wall_plugs = (
("comment", "device"),
[
def test_socket_state_on(device):
if device.has_socket_control:
socket = Device(device.raw.copy()).socket_control.socket[0]
socket.raw[ATTR_DEVICE_STATE] = 1
assert socket.state is True
def test_light_state_mangled(device):
light = Device(device.raw.copy()).light_control.lights[0]
light.raw[ATTR_DEVICE_STATE] = "RandomString"
assert light.state is False