Ejemplo n.º 1
0
def test_init_modem_no_args(no_serial_port):
    modem = Modem()
    assert(modem.timeout == 1)
    assert(modem.socket_identifier == 0)
    assert(modem.chatscript_file.endswith('/chatscripts/default-script'))
    assert(modem._at_sockets_available == False)
    assert(modem.description == 'Modem')
Ejemplo n.º 2
0
def test_get_result_string(no_serial_port):
    modem = Modem()
    assert(modem.getResultString(0) == 'Modem returned OK')
    assert(modem.getResultString(-1) == 'Modem timeout')
    assert(modem.getResultString(-2) == 'Modem error')
    assert(modem.getResultString(-3) == 'Modem response doesn\'t match expected return value')
    assert(modem.getResultString(-99) == 'Unknown response code')
Ejemplo n.º 3
0
def test_debugwrite(no_serial_port):
    modem = Modem()
    assert(modem.debug_out == '')
    modem.debugwrite('test')
    assert(modem.debug_out == 'test')

    modem.debugwrite('test222', hide=True)
    assert(modem.debug_out == 'test') # debug_out shouldn't change since hide is enabled.
Ejemplo n.º 4
0
 def test_check_registered_long_list(self):
     result = ['+CREG: 5,"5585","404EF4D",6',
               '+CREG: 5,"5585","404C816",6',
               '+CREG: 5,"5585","404C790",6',
               '+CREG: 5,"5585","404C816",6',
               '+CREG: 5,"5585","404EF4D",6',
               '+CREG: 5,"5585","404C78A",6',
               '+CREG: 5,"5585","404C790",6',
               '+CREG: 5,"5585","404C816",6',
               '+CREG: 2',
               '+CREG: 5,"5585","404C790",6',
               '+CREG: 2,5,"5585","404C790",6']
     registered = Modem._check_registered_helper('+CREG', result)
     assert(registered)
Ejemplo n.º 5
0
def test_get_sms(no_serial_port, get_sms):
    modem = Modem()
    res = modem.popReceivedSMS()
    assert(res.sender == '447937405250')
    assert(res.timestamp == datetime.utcfromtimestamp(1498264009))
    assert(res.message == 'Test 123')
Ejemplo n.º 6
0
def test_get_location(no_serial_port):
    modem = Modem()
    with pytest.raises(NotImplementedError) as e:
        assert(modem.location == 'test location')
        assert('This modem does not support this property' in str(e))
Ejemplo n.º 7
0
def test_init_modem_chatscriptfileoverride(no_serial_port):
    modem = Modem(chatscript_file='test-chatscript')
    assert(modem.timeout == 1)
    assert(modem.socket_identifier == 0)
    assert(modem.chatscript_file == 'test-chatscript')
Ejemplo n.º 8
0
 def test_registered_empty_list(self):
     result = []
     with pytest.raises(SerialError) as e:
         registered = Modem._check_registered_helper('+CREG', result)
Ejemplo n.º 9
0
 def test_registered_basic_unregistered_string(self):
     # This should force strips left and right, but the return value will
     # still be false since 3 is elem 1 in [2, 3, 2]
     result = '2, 3, 2'
     registered = Modem._check_registered_helper('+CREG', result)
     assert(registered == False)
Ejemplo n.º 10
0
 def test_check_registered_string(self):
     result = '+CREG: 2,5,"5585","404C790",6'
     registered = Modem._check_registered_helper('+CREG', result)
     assert(registered)
Ejemplo n.º 11
0
def test_command_result(no_serial_port):

    modem = Modem()

    # OK with an empty response list.
    assert(modem.result == ModemResult.OK)
    result, resp = modem._command_result()

    assert(result == ModemResult.OK)
    assert(resp == [])

    # OK with a response list of one element.
    modem.result = ModemResult.OK
    modem.response = ['test1']
    result, resp = modem._command_result()

    assert(result == ModemResult.OK)
    assert(resp == 'test1') # should return just a string

    # INVALID
    modem.result = ModemResult.Invalid
    modem.response = ['test1', 'test2', 'test3']

    result, resp = modem._command_result()

    assert(result == ModemResult.Invalid)
    assert(resp == ['test1', 'test2', 'test3'])

    # NOMATCH
    modem.result = ModemResult.NoMatch
    # This should still be a list since it's not ModemResult.OK.
    modem.response = ['test1']
    result, resp = modem._command_result()

    assert(result == ModemResult.NoMatch)
    assert(resp == ['test1'])

    # ERROR
    modem.result = ModemResult.Error
    modem.response = []
    result, resp = modem._command_result()

    assert(result == ModemResult.Error)
    assert(resp == [])

    # TIMEOUT
    modem.result = ModemResult.Timeout
    result, resp = modem._command_result()

    assert(result == ModemResult.Timeout)
    assert(resp == [])
Ejemplo n.º 12
0
def test_modemwrite(no_serial_port):
    modem = Modem()
    assert(modem.debug_out == '')

    # use all method arg default values.
    modem.modemwrite('test-cmd')
    assert(modem.debug_out == 'test-cmd')

    modem.modemwrite('test2', start=True)
    assert(modem.debug_out == '[test2')

    modem.modemwrite('test3', start=True, hide=True)
    # This should be the same as the previous debug_out because hide is enabled.
    assert(modem.debug_out == '[test2')

    modem.modemwrite('test4', start=True, end=True)
    assert(modem.debug_out == '[test4]')

    modem.modemwrite('test5', start=True, at=True, seteq=True, read=True, end=True)
    assert(modem.debug_out == '[ATtest5=?]')
Ejemplo n.º 13
0
def test_socket_write_over_512(no_serial_port, override_command_result):
    modem = Modem()
    data = '{message:{fill}{align}{width}}'.format(message='Test-', fill='@', align='<', width=600)
    modem.write_socket(data.encode())