Exemplo n.º 1
0
 def test_from_device_number(self, a_context, device_datum):
     mode = os.stat(device_datum.device_node).st_mode
     typ = 'block' if stat.S_ISBLK(mode) else 'char'
     device = Devices.from_device_number(
         a_context, typ, device_datum.device_number)
     assert device.device_number == device_datum.device_number
     # make sure, we are really referring to the same device
     assert device.device_path == device_datum.device_path
Exemplo n.º 2
0
 def test_from_device_number(self, a_context, device_datum):
     mode = os.stat(device_datum.device_node).st_mode
     typ = 'block' if stat.S_ISBLK(mode) else 'char'
     device = Devices.from_device_number(
         a_context, typ, device_datum.device_number)
     assert device.device_number == device_datum.device_number
     # make sure, we are really referring to the same device
     assert device.device_path == device_datum.device_path
Exemplo n.º 3
0
 def test_from_device_number(self, a_context, a_device):
     """
     Verify that from_device_number() yields the correct device.
     """
     mode = os.stat(a_device.device_node).st_mode
     typ = 'block' if stat.S_ISBLK(mode) else 'char'
     device = \
        Devices.from_device_number(a_context, typ, a_device.device_number)
     assert a_device == device
Exemplo n.º 4
0
 def test_from_device_number_wrong_type(self, a_context, device_datum):
     mode = os.stat(device_datum.device_node).st_mode
     # deliberately use the wrong type here to cause either failure
     # or at least device mismatch
     typ = 'char' if stat.S_ISBLK(mode) else 'block'
     try:
         # this either fails, in which case the caught exception is
         # raised, or succeeds, but returns a wrong device
         # (device numbers are not unique across device types)
         device = Devices.from_device_number(a_context, typ,
                                             device_datum.device_number)
         # if it succeeds, the resulting device must not match the
         # one, we are actually looking for!
         assert device.device_path != device_datum.device_path
     except DeviceNotFoundByNumberError as error:
         # check the correctness of the exception attributes
         assert error.device_type == typ
         assert error.device_number == device_datum.device_number
Exemplo n.º 5
0
 def test_from_device_number_wrong_type(
     self,
     a_context,
     device_datum
 ):
     mode = os.stat(device_datum.device_node).st_mode
     # deliberately use the wrong type here to cause either failure
     # or at least device mismatch
     typ = 'char' if stat.S_ISBLK(mode) else 'block'
     try:
         # this either fails, in which case the caught exception is
         # raised, or succeeds, but returns a wrong device
         # (device numbers are not unique across device types)
         device = Devices.from_device_number(
             a_context, typ, device_datum.device_number)
         # if it succeeds, the resulting device must not match the
         # one, we are actually looking for!
         assert device.device_path != device_datum.device_path
     except DeviceNotFoundByNumberError as error:
         # check the correctness of the exception attributes
         assert error.device_type == typ
         assert error.device_number == device_datum.device_number
Exemplo n.º 6
0
 def test_from_device_number_wrong_type(self, a_context, a_device):
     """
     Verify appropriate behavior on real device number but swapped
     subsystems.
     """
     mode = os.stat(a_device.device_node).st_mode
     # deliberately use the wrong type here to cause either failure
     # or at least device mismatch
     typ = "char" if stat.S_ISBLK(mode) else "block"
     try:
         # this either fails, in which case the caught exception is
         # raised, or succeeds, but returns a wrong device
         # (device numbers are not unique across device types)
         device = Devices.from_device_number(a_context, typ,
                                             a_device.device_number)
         # if it succeeds, the resulting device must not match the
         # one, we are actually looking for!
         assert device != a_device
     except DeviceNotFoundByNumberError as error:
         # check the correctness of the exception attributes
         assert error.device_type == typ
         assert error.device_number == a_device.device_number
Exemplo n.º 7
0
 def test_from_device_number_invalid_type(self, a_context):
     with pytest.raises(DeviceNotFoundByNumberError):
         Devices.from_device_number(a_context, 'foobar', 100)
Exemplo n.º 8
0
 def test_from_device_number_invalid_type(self):
     """
     Verify that a non-existant subsystem always results in an exception.
     """
     with pytest.raises(DeviceNotFoundByNumberError):
         Devices.from_device_number(_CONTEXT, 'foobar', 100)
Exemplo n.º 9
0
 def test_from_device_number_invalid_type(self, a_context):
     with pytest.raises(DeviceNotFoundByNumberError):
         Devices.from_device_number(a_context, 'foobar', 100)