Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_config_invalid(runner, mock_rak811):
mock_rak811.return_value.set_config.side_effect = Rak811ResponseError(-1)
result = runner.invoke(cli, ['-v', 'set-config', 'dr=0', 'adr=out'])
mock_rak811.return_value.set_config.assert_called_once_with(dr='0',
adr='out')
assert result.output == 'RAK811 response error -1: Invalid argument\n'
def test_join_abp_response(runner, mock_rak811):
mock_rak811.return_value.join_abp.side_effect = Rak811ResponseError(-3)
result = runner.invoke(cli, ['-v', 'join-abp'])
mock_rak811.return_value.join_abp.assert_called_once()
assert result.output == 'RAK811 response error -3: ABP join error\n'
def test_send_command(lora):
"""Test _send_command."""
# Successful command
lora._serial.get_response.return_value = 'OK0'
assert lora._send_command('dr') == '0'
lora._serial.send_command.assert_called_with('dr')
# Error
lora._serial.get_response.return_value = 'ERROR-1'
with raises(Rak811ResponseError,
match='-1'):
lora._send_command('mode=2')
# Unknown error
lora._serial.get_response.return_value = 'Unexpected'
with raises(Rak811ResponseError,
match='Unexpected'):
lora._send_command('mode=2')
# Events in response queue
lora._serial.get_response.side_effect = [
'at+recv=2,0,0',
'OK0'
]
assert lora._send_command('dr') == '0'
def test_send_command(lora):
"""Test _send_command."""
# Successful command
lora._serial.get_response.return_value = 'OK0'
assert lora._send_command('dr') == '0'
lora._serial.send_command.assert_called_with('dr')
# Error
lora._serial.get_response.return_value = 'ERROR-1'
with raises(Rak811ResponseError,
match='-1'):
lora._send_command('mode=2')
# Unknown error
lora._serial.get_response.return_value = 'Unexpected'
with raises(Rak811ResponseError,
match='Unexpected'):
lora._send_command('mode=2')
# Events in response queue
lora._serial.get_response.side_effect = [
'at+recv=2,0,0',
'OK0'
]
assert lora._send_command('dr') == '0'
def test_get_config_error(runner, mock_rak811):
mock_rak811.return_value.get_config.side_effect = Rak811ResponseError(-1)
result = runner.invoke(cli, ['-v', 'get-config', 'nwks_key'])
mock_rak811.return_value.get_config.assert_called_once()
assert result.output == 'RAK811 response error -1: Invalid argument\n'
def print_exception(e):
"""Print exception raised by the Rak811 library."""
if isinstance(e, Rak811ResponseError):
click.echo('RAK811 response error {}: {}'.format(e.errno, e.strerror))
elif isinstance(e, Rak811EventError):
click.echo('RAK811 event error {}: {}'.format(e.errno, e.strerror))
elif isinstance(e, Rak811TimeoutError):
click.echo('RAK811 timeout: {}'.format(e))
else:
click.echo('RAK811 unexpected exception {}'.format(e))