From 9bbd7ce50861e04b4907cab033340298703f3af8 Mon Sep 17 00:00:00 2001 From: desbma Date: Sat, 25 Feb 2017 14:03:51 +0100 Subject: [PATCH] Improve hdparm error handling - 3 --- hddfancontrol/__init__.py | 1 + tests/__init__.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/hddfancontrol/__init__.py b/hddfancontrol/__init__.py index 6013da1..20761cc 100755 --- a/hddfancontrol/__init__.py +++ b/hddfancontrol/__init__.py @@ -97,6 +97,7 @@ class Drive: try: output = subprocess.check_output(cmd, stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, universal_newlines=True) except subprocess.CalledProcessError: supported = False diff --git a/tests/__init__.py b/tests/__init__.py index bd44fbe..a84906e 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -66,24 +66,28 @@ class TestDrive(unittest.TestCase): self.assertEqual(self.drive.supportsHitachiTempQuery(), True) subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"), stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, universal_newlines=True) 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" self.assertEqual(self.drive.supportsHitachiTempQuery(), False) subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"), stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, universal_newlines=True) 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" self.assertEqual(self.drive.supportsHitachiTempQuery(), False) subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"), stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, universal_newlines=True) 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" self.assertEqual(self.drive.supportsHitachiTempQuery(), False) subprocess_check_output_mock.assert_called_once_with(("hdparm", "-H", "/dev/sdz"), stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, universal_newlines=True) def test_getState(self):