First unit test
This commit is contained in:
+5
-7
@@ -3,12 +3,10 @@ python:
|
|||||||
- "3.3"
|
- "3.3"
|
||||||
- "3.4"
|
- "3.4"
|
||||||
install:
|
install:
|
||||||
# - "pip install -r requirements.txt"
|
- "pip install -r requirements.txt"
|
||||||
# - "pip install coveralls"
|
- "pip install coveralls"
|
||||||
- "sudo apt-get -yV install hddtemp hdparm"
|
- "sudo apt-get -yV install hddtemp hdparm"
|
||||||
script:
|
script:
|
||||||
# - "coverage run --source=hddfancontrol setup.py test"
|
- "coverage run --source=hddfancontrol setup.py test"
|
||||||
- "./setup.py install"
|
after_success:
|
||||||
- "hddfancontrol -h"
|
- "coveralls"
|
||||||
# after_success:
|
|
||||||
# - "coveralls"
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ setup(name="hddfancontrol",
|
|||||||
author="desbma",
|
author="desbma",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
entry_points={"console_scripts": ["hddfancontrol = hddfancontrol:cl_main"]},
|
entry_points={"console_scripts": ["hddfancontrol = hddfancontrol:cl_main"]},
|
||||||
|
test_suite="tests",
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
description="Control system fan speed by monitoring hard drive temperature",
|
description="Control system fan speed by monitoring hard drive temperature",
|
||||||
long_description=readme,
|
long_description=readme,
|
||||||
|
|||||||
Executable
+46
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import unittest
|
||||||
|
import unittest.mock
|
||||||
|
|
||||||
|
import hddfancontrol
|
||||||
|
|
||||||
|
|
||||||
|
class TestDrive(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
with unittest.mock.patch("hddfancontrol.stat") as stat_mock, \
|
||||||
|
unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
stat_mock.stat.S_IFBLK.return_value = True
|
||||||
|
subprocess_mock.check_call.side_effect = subprocess_mock.CalledProcessError(0, "")
|
||||||
|
self.drive = hddfancontrol.Drive("/dev/sda", "/dummy", None)
|
||||||
|
|
||||||
|
def test_getState(self):
|
||||||
|
with unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
subprocess_mock.check_output.return_value = "\n/dev/sda:\n drive state is: active/idle\n"
|
||||||
|
self.assertEqual(self.drive.getState(), hddfancontrol.Drive.DriveState.ACTIVE_IDLE)
|
||||||
|
with unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
subprocess_mock.check_output.return_value = "\n/dev/sda:\n drive state is: standby\n"
|
||||||
|
self.assertEqual(self.drive.getState(), hddfancontrol.Drive.DriveState.STANDBY)
|
||||||
|
with unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
subprocess_mock.check_output.return_value = "\n/dev/sda:\n drive state is: sleeping\n"
|
||||||
|
self.assertEqual(self.drive.getState(), hddfancontrol.Drive.DriveState.SLEEPING)
|
||||||
|
with unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
subprocess_mock.check_output.return_value = "/dev/sda: No such file or directory\n"
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.drive.getState()
|
||||||
|
with unittest.mock.patch("hddfancontrol.subprocess") as subprocess_mock:
|
||||||
|
subprocess_mock.check_output.side_effect = subprocess_mock.CalledProcessError(0, "")
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.drive.getState()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# disable logging
|
||||||
|
logging.basicConfig(level=logging.CRITICAL + 1)
|
||||||
|
|
||||||
|
# run tests
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user