Пример #1
0
class TestPseudoDevice(unittest.TestCase):
    """Fictitious device used for testing framework without actual hardware"""

    def setUp(self):
        self.device = PseudoDevice(port=4)        


    def test_instantiate_with_args(self):
        """Setup keyword argument appears as instance attribute"""
        assert self.device.port == 4


    def test_device_type(self):
        """Inherited 'type' method works on subclasses"""
        assert self.device.getDeviceType() == "PseudoDevice"


    def test_command_list(self):
        """Public callables exposed using zope.interface mechanism"""
        known_commands = ['getCommandList', 'getDeviceType', 'getState', 'setState',
                          'delay', 'getParameter', 'setParameter', 'raiseException']
        known_commands.sort()
        found_commands = self.device.getCommandList()
        found_commands.sort()
        self.assertEqual(known_commands, found_commands)


    def test_parameter(self):
        """Store and retrieve parameter value"""
        pi = 3.1415926
        self.device.setParameter(pi)
        self.assertAlmostEqual(self.device.getParameter(), pi)


    def test_raiseexception(self):
        """Raise an arbitrary Python exception"""

        try:
            self.device.raiseException()
        except DeviceError:
            return

        self.fail("Failed to raise expected exception")
Пример #2
0
 def setUp(self):
     self.device = PseudoDevice(port=4)