def testShorthandForm(self):
     panel_client._validate_controls([{
         'id':
         'Froomulator',
         'state':
         '0',
         'actions': [['0', '1', '2'], 'Set Froomulator to %s!']
     }])
 def testRequireControlKeys(self):
     with self.assertRaisesRegexp(Exception, '`state` is missing'):
         panel_client._validate_controls([{
             'id': 'defenestrator',
             'actions': {
                 '0': '',
                 '1': 'Defenestrate the aristocracy!'
             }
         }])
 def testLonghandForm(self):
     panel_client._validate_controls([{
         'id': 'defenestrator',
         'state': '0',
         'actions': {
             '0': '',
             '1': 'Defenestrate the aristocracy!'
         }
     }])
 def testStatesDontHaveToBeNumeric(self):
     panel_client._validate_controls([{
         'id': 'octo',
         'state': 'nothing',
         'actions': {
             'nothing': '',
             'nipple': 'Octo bite raven girl nipple!',
             'mouth': 'Octo kiss raven girl mouth!'
         }
     }])
 def testIgnoreUnknownControlKeys(self):
     panel_client._validate_controls([{
         'id': 'defenestrator',
         'state': '0',
         'actions': {
             '0': '',
             '1': 'Defenestrate the aristocracy!'
         },
         'type': 'button'
     }])
 def formatStringRequiredInShorthandForm(self):
     with self.assertRaisesRegexp(Exception,
                                  'Shorthand `actions` is malformed'):
         panel_client._validate_controls([{
             'id':
             'Froomulator',
             'state':
             '0',
             'actions': [['0', '1', '2'], 'Set Froomulator!']
         }])
 def formatStringsOnlySupportedInShorthandForm(self):
     with self.assertRaisesRegexp(
             Exception,
             'Format strings are only supported in the shorthand form of `actions`'
     ):
         panel_client._validate_controls([{
             'id': 'defenestrator',
             'state': '0',
             'actions': {
                 '0': '',
                 '1': 'Defenestrate %s!'
             }
         }])
 def testIdsMustBeUnique(self):
     with self.assertRaisesRegexp(Exception, 'Control ids are not unique'):
         panel_client._validate_controls([{
             'id': 'defenestrator',
             'state': '0',
             'actions': {
                 '0': '',
                 '1': 'Defenestrate the aristocracy!'
             }
         }, {
             'id': 'defenestrator',
             'state': '0',
             'actions': {
                 '0': '',
                 '1': 'Defenestrate the aristocracy!'
             }
         }])
    def testStateMustBeString(self):
        with self.assertRaisesRegexp(Exception, '`state` is not a string'):
            panel_client._validate_controls([{
                'id': 'defenestrator',
                'state': 0,
                'actions': {
                    0: '',
                    1: 'Defenestrate the aristocracy!'
                }
            }])

        with self.assertRaisesRegexp(Exception,
                                     'State in `actions` is not a string'):
            panel_client._validate_controls([{
                'id': 'defenestrator',
                'state': '0',
                'actions': {
                    '0': '',
                    1: 'Defenestrate the aristocracy!'
                }
            }])

        with self.assertRaisesRegexp(Exception,
                                     'State in `actions` is not a string'):
            panel_client._validate_controls([{
                'id':
                'Froomulator',
                'state':
                '0',
                'actions': [['0', 1], 'Set Froomulator to %s!']
            }])
    def testStateMustBeInActions(self):
        with self.assertRaisesRegexp(Exception,
                                     '`state` not present in `actions`'):
            panel_client._validate_controls([{
                'id': 'defenestrator',
                'state': '2',
                'actions': {
                    '0': '',
                    '1': 'Defenestrate the aristocracy!'
                },
                'type': 'button'
            }])

        with self.assertRaisesRegexp(Exception,
                                     '`state` not present in `actions`'):
            panel_client._validate_controls([{
                'id':
                'Froomulator',
                'state':
                '3',
                'actions': [['0', '1', '2'], 'Set Froomulator to %s!']
            }])