Add test cases
This commit is contained in:
parent
43988db4cc
commit
ac418caa59
1 changed files with 30 additions and 33 deletions
|
@ -1,17 +1,9 @@
|
||||||
# pylint: disable=C0103,C0111
|
# pylint: disable=C0103,C0111
|
||||||
|
|
||||||
import json
|
|
||||||
import unittest
|
import unittest
|
||||||
import mock
|
from mock import patch
|
||||||
|
|
||||||
try:
|
|
||||||
from StringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
import tests.mocks as mocks
|
import tests.mocks as mocks
|
||||||
|
|
||||||
from bumblebee.config import Config
|
|
||||||
from bumblebee.input import LEFT_MOUSE
|
from bumblebee.input import LEFT_MOUSE
|
||||||
from bumblebee.modules.caffeine import Module
|
from bumblebee.modules.caffeine import Module
|
||||||
|
|
||||||
|
@ -19,35 +11,40 @@ class TestCaffeineModule(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
mocks.setup_test(self, Module)
|
mocks.setup_test(self, Module)
|
||||||
|
|
||||||
self.xset_active = " timeout: 0 cycle: 123"
|
|
||||||
self.xset_inactive = " timeout: 600 cycle: 123"
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
mocks.teardown_test(self)
|
mocks.teardown_test(self)
|
||||||
|
|
||||||
def test_text(self):
|
def test_check_requirements(self):
|
||||||
self.assertEquals(self.module.caffeine(self.anyWidget), "")
|
with patch('bumblebee.util.which', side_effect=['', 'xprop', 'xdg-screensaver']):
|
||||||
|
self.assertTrue(['xdotool'] == self.module._check_requirements())
|
||||||
|
|
||||||
def test_active(self):
|
def test_get_i3bar_xid_returns_digit(self):
|
||||||
self.popen.mock.communicate.return_value = (self.xset_active, None)
|
self.popen.mock.communicate.return_value = ("8388614", None)
|
||||||
self.assertTrue(not "deactivated" in self.module.state(self.anyWidget))
|
self.assertTrue(self.module._get_i3bar_xid().isdigit())
|
||||||
self.assertTrue("activated" in self.module.state(self.anyWidget))
|
|
||||||
|
|
||||||
def test_inactive(self):
|
def test_get_i3bar_xid_returns_error_string(self):
|
||||||
self.popen.mock.communicate.return_value = (self.xset_inactive, None)
|
self.popen.mock.communicate.return_value = ("Some error message", None)
|
||||||
self.assertTrue("deactivated" in self.module.state(self.anyWidget))
|
self.assertTrue(self.module._get_i3bar_xid() is None)
|
||||||
self.popen.mock.communicate.return_value = ("no text", None)
|
|
||||||
self.assertTrue("deactivated" in self.module.state(self.anyWidget))
|
|
||||||
|
|
||||||
def test_toggle(self):
|
def test_get_i3bar_xid_returns_empty_string(self):
|
||||||
self.popen.mock.communicate.return_value = (self.xset_active, None)
|
self.popen.mock.communicate.return_value = ("", None)
|
||||||
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
self.assertTrue(self.module._get_i3bar_xid() is None)
|
||||||
self.popen.assert_call("xset s default")
|
|
||||||
self.popen.assert_call("notify-send \"Out of coffee\"")
|
def test_suspend_screensaver_success(self):
|
||||||
|
with patch.object(self.module, '_get_i3bar_xid', return_value=8388614):
|
||||||
self.popen.mock.communicate.return_value = (self.xset_inactive, None)
|
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
||||||
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
self.assertTrue(self.module._suspend_screensaver() is True)
|
||||||
self.popen.assert_call("xset s off")
|
|
||||||
self.popen.assert_call("notify-send \"Consuming caffeine\"")
|
def test_suspend_screensaver_fail(self):
|
||||||
|
with patch.object(self.module, '_get_i3bar_xid', return_value=None):
|
||||||
|
self.module._active = False
|
||||||
|
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
||||||
|
self.assertTrue(self.module._suspend_screensaver() is False)
|
||||||
|
|
||||||
|
def test_resume_screensaver(self):
|
||||||
|
with patch.object(self.module, '_check_requirements', return_value=[]):
|
||||||
|
self.module._active = True
|
||||||
|
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
||||||
|
self.assertTrue(self.module._resume_screensaver() is True)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue