Пример #1
0
class SetCommandTest(TestCase):
    """
    Support for set commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = ExtendedCommandHandler()
        self.parser.register('+AAAA', a)

    def test_strings(self):
        result = self.parser.process('AT+AAAA=1')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+AAAA=1,2,3')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+AAAA=3,0,0,1')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=\"foo\",1,\"b,ar")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,,,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,1,,\"foo\",")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #2
0
class SetCommandTest(TestCase):
    """
    Support for set commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = ExtendedCommandHandler()
        self.parser.register('+AAAA', a)

    def test_strings(self):
        result = self.parser.process('AT+AAAA=1')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+AAAA=1,2,3')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+AAAA=3,0,0,1')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=\"foo\",1,\"b,ar")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,,,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+AAAA=,1,,\"foo\",")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #3
0
class ChainedCommandTest(TestCase):
    """
    Support for chained commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        b = ExtendedCommandHandler()
        c = ExtendedCommandHandler()
        self.parser.register('A', a)
        self.parser.register('+B', b)
        self.parser.register('+C', c)

    def test_strings(self):
        result = self.parser.process('AT+B100;+C')
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        result = self.parser.process('AT+C;+B')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #4
0
class ChainedCommandTest(TestCase):
    """
    Support for chained commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        b = ExtendedCommandHandler()
        c = ExtendedCommandHandler()
        self.parser.register('A', a)
        self.parser.register('+B', b)
        self.parser.register('+C', c)

    def test_strings(self):
        result = self.parser.process('AT+B100;+C')
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        result = self.parser.process('AT+C;+B')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #5
0
class RepeatCommandTest(TestCase):
    """
    Support for repeat commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        self.parser.register('A', a)

    def test_strings(self):
        result = self.parser.process('A/')
        self.assertEqual(result.toString(), '')

        result = self.parser.process('ATA')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('A/')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('A/')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #6
0
class RepeatCommandTest(TestCase):
    """
    Support for repeat commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        self.parser.register('A', a)

    def test_strings(self):
        result = self.parser.process('A/')
        self.assertEqual(result.toString(), '')

        result = self.parser.process('ATA')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('A/')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('A/')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #7
0
class BasicTest(TestCase):
    """
    The right method is being called.
    """
    def setUp(self):
        self.parser = ATParser()

    def test_basic(self):
        d = BasicCommandHandler()
        a = BasicCommandHandler()
        self.parser.register('D', d);
        self.parser.register('A', a);

        result = self.parser.process('  A T D = ? T 1 2 3  4   ')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #8
0
class SimpleExtendedTest(TestCase):
    """
    Support for simple extended commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = ExtendedCommandHandler()
        self.parser.register('+A', a);

    def test_strings(self):
        result = self.parser.process('AT+B')
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        result = self.parser.process('AT+A')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A=')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A=?')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A?')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #9
0
class BasicTest(TestCase):
    """
    The right method is being called.
    """
    def setUp(self):
        self.parser = ATParser()

    def test_basic(self):
        d = BasicCommandHandler()
        a = BasicCommandHandler()
        self.parser.register('D', d)
        self.parser.register('A', a)

        result = self.parser.process('  A T D = ? T 1 2 3  4   ')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #10
0
class SimpleExtendedTest(TestCase):
    """
    Support for simple extended commands.
    """
    def setUp(self):
        self.parser = ATParser()
        a = ExtendedCommandHandler()
        self.parser.register('+A', a)

    def test_strings(self):
        result = self.parser.process('AT+B')
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        result = self.parser.process('AT+A')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A=')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A=?')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process('AT+A?')
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)
Пример #11
0
    def test_strings(self):
        result = self.parser.process('     ')
        self.assertEqual(result.toString(), '')

        result = self.parser.process("  a T a t \"\"  1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("  a T a t  \"foo BaR12Z\" 1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"a")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA  \"one \" two \"t hr ee ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # legal extended command names
        result = self.parser.process("AT+0")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+:")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # non-AT
        result = self.parser.process("BF+A")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # no handler
        parser = ATParser()
        result = parser.process("ATZ")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # fallback action commandType
        result = self.parser.process("AT+0,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # error result code
        result = self.parser.process("AT+4,")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)
Пример #12
0
    def test_strings(self):
        result = self.parser.process('     ')
        self.assertEqual(result.toString(), '')

        result = self.parser.process("  a T a t \"\"  1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("  a T a t  \"foo BaR12Z\" 1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"a")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA  \"one \" two \"t hr ee ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # legal extended command names
        result = self.parser.process("AT+0")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+:")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # non-AT
        result = self.parser.process("BF+A")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # no handler
        parser = ATParser()
        result = parser.process("ATZ")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # fallback action commandType
        result = self.parser.process("AT+0,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # error result code
        result = self.parser.process("AT+4,")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)
Пример #13
0
class ReturnValueTest(TestCase):
    """
    """
    def test_strings(self):
        self.parser = ATParser()

        commandResponseValue = 120
        commandName = 'F'
        commandArg = '100'

        a = ATCommandHandler()
        a.handleBasicCommand = MagicMock(return_value=ATCommandResult(
            ATCommandResult.OK, commandResponseValue))
        self.parser.register(commandName, a)

        result = self.parser.process('AT{}{}'.format(commandName, commandArg))
        a.handleBasicCommand.assert_called_with(commandArg)
        self.assertEqual(result.toString(), '120\r\n\r\nOK')
Пример #14
0
class ReturnValueTest(TestCase):
    """
    """
    def test_strings(self):
        self.parser = ATParser()

        commandResponseValue = 120
        commandName = 'F'
        commandArg = '100'

        a = ATCommandHandler()
        a.handleBasicCommand = MagicMock(return_value=ATCommandResult(
            ATCommandResult.OK, commandResponseValue))
        self.parser.register(commandName, a)

        result = self.parser.process('AT{}{}'.format(commandName, commandArg))
        a.handleBasicCommand.assert_called_with(commandArg)
        self.assertEqual(result.toString(), '120\r\n\r\nOK')
Пример #15
0
class CrazyStringsTest(TestCase):
    """
    Can handle all types of crazy strings.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        b = ExtendedCommandHandler()
        c= ExtendedCommandHandler2()
        self.parser.register('A', a);
        self.parser.register('+0', b);
        self.parser.register('+:', b);
        self.parser.register('+4', c)

    def test_strings(self):
        result = self.parser.process('     ')
        self.assertEqual(result.toString(), '')

        result = self.parser.process("  a T a t \"\"  1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("  a T a t  \"foo BaR12Z\" 1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"a")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA  \"one \" two \"t hr ee ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # legal extended command names
        result = self.parser.process("AT+0")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+:")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # non-AT
        result = self.parser.process("BF+A")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # no handler
        parser = ATParser()
        result = parser.process("ATZ")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # fallback action commandType
        result = self.parser.process("AT+0,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # error result code
        result = self.parser.process("AT+4,")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)
Пример #16
0
class CrazyStringsTest(TestCase):
    """
    Can handle all types of crazy strings.
    """
    def setUp(self):
        self.parser = ATParser()
        a = BasicCommandHandler()
        b = ExtendedCommandHandler()
        c = ExtendedCommandHandler2()
        self.parser.register('A', a)
        self.parser.register('+0', b)
        self.parser.register('+:', b)
        self.parser.register('+4', c)

    def test_strings(self):
        result = self.parser.process('     ')
        self.assertEqual(result.toString(), '')

        result = self.parser.process("  a T a t \"\"  1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("  a T a t  \"foo BaR12Z\" 1 2 3 a 4   ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA\"a")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATa\" ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("ATA  \"one \" two \"t hr ee ")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # legal extended command names
        result = self.parser.process("AT+0")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        result = self.parser.process("AT+:")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # non-AT
        result = self.parser.process("BF+A")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # no handler
        parser = ATParser()
        result = parser.process("ATZ")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)

        # fallback action commandType
        result = self.parser.process("AT+0,")
        self.assertEqual(result.toString(), ATCommandResult.OK_STRING)

        # error result code
        result = self.parser.process("AT+4,")
        self.assertEqual(result.toString(), ATCommandResult.ERROR_STRING)