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)
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__))
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)
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')
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)))
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)))
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)))
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)
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__))
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)
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)
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)
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)))
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)