Example #1
0
 def test_unicode(self):
     "command objects return unicode from their __unicode__ method"
     # Python 2 only
     if sys.version_info[0] == 2:
         for fs, d, dt in _test_pattern():
             f = frame.ForwardFrame(fs, d)
             self.assertIsInstance(command.from_frame(f, dt).__unicode__(), unicode)
Example #2
0
 def test_test_coverage(self):
     "all command classes are covered by test pattern"
     seen = {}
     for fs, d, dt in _test_pattern():
         c = command.from_frame(frame.ForwardFrame(fs, d), devicetype=dt)
         seen[c.__class__] = True
     for cls in command.Command._commands:
         self.assertTrue(cls in seen, "class {} not covered by tests".format(cls.__name__))
Example #3
0
 def test_unicode(self):
     """command objects return unicode from their __unicode__ method"""
     # Python 2 only
     if sys.version_info[0] == 2:
         for fs, d, dt in _test_pattern():
             f = frame.ForwardFrame(fs, d)
             self.assertIsInstance(
                 command.from_frame(f, dt).__unicode__(), unicode)
Example #4
0
 def test_response(self):
     """responses act sensibly"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c.response:
             self.assertRaises(TypeError, lambda: c.response('wibble'))
             self.assertHasAttr(c.response(None), 'raw_value')
Example #5
0
 def test_roundtrip(self):
     "all frames survive command.from_frame()"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, "frame {} failed command round-trip; command {} "
             "became {}".format(unicode(f), unicode(c), unicode(nf)))
Example #6
0
 def test_unicode(self):
     "command objects return unicode from their __unicode__ method"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertTrue(
             isinstance(command.from_frame(f, dt).__unicode__(),
                        unicode),
             "command {} unicode method didn't return unicode".\
             format(unicode(f)))
Example #7
0
 def test_roundtrip(self):
     "all frames survive command.from_frame()"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, "frame {} failed command round-trip; command {} "
             "became {}".format(unicode(f), unicode(c), unicode(nf)))
Example #8
0
 def test_unicode(self):
     "command objects return unicode from their __unicode__ method"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertTrue(
             isinstance(command.from_frame(f, dt).__unicode__(),
                        unicode),
             "command {} unicode method didn't return unicode".\
             format(unicode(f)))
Example #9
0
 def test_roundtrip(self):
     """all frames survive command.from_frame()"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, 'frame {} failed command round-trip; command {} '
             'became {}'.format(str(f), str(c), str(nf)))
Example #10
0
 def test_roundtrip(self):
     """all frames survive command.from_frame()"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, 'frame {} failed command round-trip; command {} '
             'became {}'.format(str(f), str(c), str(nf)))
Example #11
0
 def _handle_dispatch(self, frame):
     command = from_frame(frame)
     if self.debug:
         self.logger.info(str(command))
     if self.dispatcher is None:
         if self.debug:
             msg = 'Ignore received command: {}'.format(command)
             self.logger.info(msg)
         return
     self.dispatcher(command)
Example #12
0
 def _handle_dispatch(self, frame):
     command = from_frame(frame)
     if self.debug:
         self.logger.info(str(command))
     if self.dispatcher is None:
         if self.debug:
             msg = 'Ignore received command: {}'.format(command)
             self.logger.info(msg)
         return
     self.dispatcher(command)
Example #13
0
 def test_test_coverage(self):
     """all command classes are covered by test pattern"""
     seen = {}
     for fs, d, dt in _test_pattern():
         c = command.from_frame(frame.ForwardFrame(fs, d), devicetype=dt)
         seen[c.__class__] = True
     for cls in command.Command._commands:
         self.assertTrue(
             cls in seen,
             'class {} not covered by tests'.format(cls.__name__))
Example #14
0
 def test_response(self):
     "responses act sensibly"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             if sys.version_info[0] == 2:
                 self.assertIsInstance(c._response(None).__unicode__(), unicode)
             self.assertRaises(TypeError, lambda: c._response("wibble"))
             if sys.version_info[0] == 2:
                 self.assertIsInstance(c._response(frame.BackwardFrame(0xFF)).__unicode__(), unicode)
Example #15
0
 def test_queryextendedversionnumber(self):
     """all gear types implement QueryExtendedVersionNumber"""
     # dali.gear.general.QueryExtendedVersionNumber is an oddity:
     # it is only used when preceded by EnableDeviceType with
     # devicetype != 0.  Ensure that there is an implementation of
     # this command for all supported device types.
     qevn_frame = generalgear.QueryExtendedVersionNumber(
         address.Broadcast()).frame
     for devicetype in command.Command._supported_devicetypes:
         qevn = command.from_frame(qevn_frame, devicetype=devicetype)
         self.assertIsNotNone(qevn)
         self.assertEqual(qevn.__class__.__name__,
                          'QueryExtendedVersionNumber')
         self.assertEqual(qevn.devicetype, devicetype)
Example #16
0
 def test_response(self):
     """responses act sensibly"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             if sys.version_info[0] == 2:
                 self.assertIsInstance(
                     c._response(None).__unicode__(), unicode)
             self.assertRaises(TypeError, lambda: c._response('wibble'))
             if sys.version_info[0] == 2:
                 self.assertIsInstance(
                     c._response(frame.BackwardFrame(0xff)).__unicode__(),
                     unicode)
Example #17
0
 def test_response(self):
     "responses act sensibly"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             self.assertTrue(
                 isinstance(c._response(None).__unicode__(), unicode),
                 "cmd {} unicode(response(None)) didn't return unicode".\
                 format(unicode(f)))
             self.assertRaises(TypeError, lambda: c._response("wibble"))
             self.assertTrue(
                 isinstance(c._response(frame.BackwardFrame(0xff)).\
                            __unicode__(), unicode),
                 "cmd {} unicode(response(0xff)) didn't return unicode".\
                 format(unicode(f)))
Example #18
0
 def test_response(self):
     "responses act sensibly"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             self.assertTrue(
                 isinstance(c._response(None).__unicode__(), unicode),
                 "cmd {} unicode(response(None)) didn't return unicode".\
                 format(unicode(f)))
             self.assertRaises(TypeError, lambda: c._response("wibble"))
             self.assertTrue(
                 isinstance(c._response(frame.BackwardFrame(0xff)).\
                            __unicode__(), unicode),
                 "cmd {} unicode(response(0xff)) didn't return unicode".\
                 format(unicode(f)))
Example #19
0
 def test_str(self):
     """command objects can be converted to strings"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertIsInstance(str(command.from_frame(f, dt)), str)
Example #20
0
 def test_str(self):
     """command objects can be converted to strings"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertIsInstance(str(command.from_frame(f, dt)),
                               str)