[tests] switch to pytest
This commit is contained in:
parent
b2e92d816d
commit
39fa7788b4
37 changed files with 1009 additions and 2259 deletions
0
tests/modules/contrib/__init__.py
Normal file
0
tests/modules/contrib/__init__.py
Normal file
24
tests/modules/contrib/test_kernel.py
Normal file
24
tests/modules/contrib/test_kernel.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import pytest
|
||||
|
||||
import core.config
|
||||
import modules.contrib.kernel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def some_kernel():
|
||||
return "this-is-my-kernel"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def kernel_module():
|
||||
return modules.contrib.kernel.Module(config=core.config.Config([]), theme=None)
|
||||
|
||||
|
||||
def test_full_text(mocker, kernel_module):
|
||||
platform = mocker.patch("modules.contrib.kernel.platform")
|
||||
platform.release.return_value = some_kernel
|
||||
assert len(kernel_module.widgets()) == 1
|
||||
assert some_kernel == kernel_module.widget().full_text()
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
48
tests/modules/contrib/test_mpd.py
Normal file
48
tests/modules/contrib/test_mpd.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import pytest
|
||||
|
||||
import core.config
|
||||
import modules.contrib.mpd
|
||||
|
||||
@pytest.fixture
|
||||
def mpd_module():
|
||||
return modules.contrib.mpd.Module(config=core.config.Config([]), theme=None)
|
||||
|
||||
def _test_state(mocker, mpd_module, widget_name, expected_output):
|
||||
widget = mocker.Mock()
|
||||
widget.name = widget_name
|
||||
return mpd_module.state(widget) == expected_output
|
||||
|
||||
def test_states(mocker, mpd_module):
|
||||
assert _test_state(mocker, mpd_module, 'mpd.repeat', 'repeat-off')
|
||||
assert _test_state(mocker, mpd_module, 'mpd.shuffle', 'shuffle-off')
|
||||
assert _test_state(mocker, mpd_module, 'mpd.prev', 'prev')
|
||||
assert _test_state(mocker, mpd_module, 'mpd.next', 'next')
|
||||
|
||||
def test_no_host(mpd_module):
|
||||
assert mpd_module._hostcmd == ''
|
||||
|
||||
def test_host():
|
||||
module_with_host = modules.contrib.mpd.Module(config=core.config.Config(['-p', 'mpd.host=sample-host']), theme=None)
|
||||
assert module_with_host._hostcmd == ' -h sample-host'
|
||||
|
||||
def test_host2(mocker):
|
||||
cli = mocker.patch("modules.contrib.mpd.util.cli")
|
||||
module_with_host = modules.contrib.mpd.Module(config=core.config.Config(['-p', 'mpd.host=sample-host']), theme=None)
|
||||
module_with_host.update()
|
||||
args, kwargs = cli.execute.call_args
|
||||
|
||||
assert " -h sample-host" in args[0] and "mpc" in args[0]
|
||||
|
||||
def test_bad_layout():
|
||||
pytest.raises(KeyError, modules.contrib.mpd.Module, config=core.config.Config(['-p', 'mpd.layout="mpd.inexistent"']), theme=None)
|
||||
|
||||
def test_hidden_on_creation(mpd_module):
|
||||
assert mpd_module.hidden()
|
||||
|
||||
def test_update_calls_load_song(mocker, mpd_module):
|
||||
mocker.patch.object(mpd_module, '_load_song')
|
||||
mpd_module.update()
|
||||
mpd_module._load_song.assert_called_once()
|
||||
|
||||
def test_default_layout(mpd_module):
|
||||
assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"
|
|
@ -1,21 +0,0 @@
|
|||
import unittest
|
||||
|
||||
import core.config
|
||||
import modules.contrib.kernel
|
||||
|
||||
|
||||
class kernel(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.someKernel = "this-is-my-kernel"
|
||||
self.module = modules.contrib.kernel.Module(
|
||||
config=core.config.Config([]), theme=None
|
||||
)
|
||||
|
||||
def test_full_text(self):
|
||||
with unittest.mock.patch("modules.contrib.kernel.platform") as platform:
|
||||
platform.release.return_value = self.someKernel
|
||||
self.assertEqual(1, len(self.module.widgets()))
|
||||
self.assertEqual(self.someKernel, self.module.widget().full_text())
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue