Improve hdparm error handling - 3
This commit is contained in:
@@ -97,6 +97,7 @@ class Drive:
|
|||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd,
|
output = subprocess.check_output(cmd,
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
supported = False
|
supported = False
|
||||||
|
|||||||
@@ -66,24 +66,28 @@ class TestDrive(unittest.TestCase):
|
|||||||
self.assertEqual(self.drive.supportsHitachiTempQuery(), True)
|
self.assertEqual(self.drive.supportsHitachiTempQuery(), True)
|
||||||
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
||||||
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: questionable sense data, results may be incorrect\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: questionable sense data, results may be incorrect\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
||||||
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
||||||
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
||||||
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: missing sense data, results may be incorrect\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: missing sense data, results may be incorrect\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
||||||
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
||||||
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
with unittest.mock.patch("hddfancontrol.subprocess.check_output") as subprocess_check_output_mock:
|
||||||
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 04 51 40 00 21 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
subprocess_check_output_mock.return_value = "\n/dev/sdz:\nSG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 04 51 40 00 21 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n drive temperature (celsius) is: -18\n drive temperature in range: yes"
|
||||||
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
self.assertEqual(self.drive.supportsHitachiTempQuery(), False)
|
||||||
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"),
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
|
|
||||||
def test_getState(self):
|
def test_getState(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user