[tests] black -t py34
This commit is contained in:
parent
e9e67ae375
commit
79fb28512f
10 changed files with 144 additions and 39 deletions
|
@ -1,4 +1,3 @@
|
||||||
import bumblebee_status.discover
|
import bumblebee_status.discover
|
||||||
|
|
||||||
bumblebee_status.discover.discover()
|
bumblebee_status.discover.discover()
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,12 @@ import pytest
|
||||||
|
|
||||||
import core.config
|
import core.config
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def defaultConfig():
|
def defaultConfig():
|
||||||
return core.config.Config([])
|
return core.config.Config([])
|
||||||
|
|
||||||
|
|
||||||
def test_module():
|
def test_module():
|
||||||
modules = ["module-1", "module-2", "module-3"]
|
modules = ["module-1", "module-2", "module-3"]
|
||||||
|
|
||||||
|
@ -14,6 +16,7 @@ def test_module():
|
||||||
|
|
||||||
assert cfg.modules() == modules
|
assert cfg.modules() == modules
|
||||||
|
|
||||||
|
|
||||||
def test_module_ordering_maintained():
|
def test_module_ordering_maintained():
|
||||||
modules = ["module-1", "module-5", "module-7"]
|
modules = ["module-1", "module-5", "module-7"]
|
||||||
more_modules = ["module-0", "module-2", "aaa"]
|
more_modules = ["module-0", "module-2", "aaa"]
|
||||||
|
@ -22,37 +25,45 @@ def test_module_ordering_maintained():
|
||||||
|
|
||||||
assert cfg.modules() == modules + more_modules
|
assert cfg.modules() == modules + more_modules
|
||||||
|
|
||||||
|
|
||||||
def test_default_interval(defaultConfig):
|
def test_default_interval(defaultConfig):
|
||||||
assert defaultConfig.interval() == 1
|
assert defaultConfig.interval() == 1
|
||||||
|
|
||||||
|
|
||||||
def test_interval():
|
def test_interval():
|
||||||
interval = 4
|
interval = 4
|
||||||
cfg = core.config.Config(["-p", "interval={}".format(interval)])
|
cfg = core.config.Config(["-p", "interval={}".format(interval)])
|
||||||
|
|
||||||
assert cfg.interval() == interval
|
assert cfg.interval() == interval
|
||||||
|
|
||||||
|
|
||||||
def test_floating_interval():
|
def test_floating_interval():
|
||||||
interval = 4.5
|
interval = 4.5
|
||||||
cfg = core.config.Config(["-p", "interval={}".format(interval)])
|
cfg = core.config.Config(["-p", "interval={}".format(interval)])
|
||||||
|
|
||||||
assert cfg.interval() == interval
|
assert cfg.interval() == interval
|
||||||
|
|
||||||
|
|
||||||
def test_default_theme(defaultConfig):
|
def test_default_theme(defaultConfig):
|
||||||
assert defaultConfig.theme() == "default"
|
assert defaultConfig.theme() == "default"
|
||||||
|
|
||||||
|
|
||||||
def test_theme():
|
def test_theme():
|
||||||
theme_name = "sample-theme"
|
theme_name = "sample-theme"
|
||||||
cfg = core.config.Config(["-t", theme_name])
|
cfg = core.config.Config(["-t", theme_name])
|
||||||
assert cfg.theme() == theme_name
|
assert cfg.theme() == theme_name
|
||||||
|
|
||||||
|
|
||||||
def test_default_iconset(defaultConfig):
|
def test_default_iconset(defaultConfig):
|
||||||
assert defaultConfig.iconset() == "auto"
|
assert defaultConfig.iconset() == "auto"
|
||||||
|
|
||||||
|
|
||||||
def test_iconset():
|
def test_iconset():
|
||||||
iconset_name = "random-iconset"
|
iconset_name = "random-iconset"
|
||||||
cfg = core.config.Config(["-i", iconset_name])
|
cfg = core.config.Config(["-i", iconset_name])
|
||||||
assert cfg.iconset() == iconset_name
|
assert cfg.iconset() == iconset_name
|
||||||
|
|
||||||
|
|
||||||
def test_reverse(defaultConfig):
|
def test_reverse(defaultConfig):
|
||||||
assert defaultConfig.reverse() == False
|
assert defaultConfig.reverse() == False
|
||||||
|
|
||||||
|
@ -60,6 +71,7 @@ def test_reverse(defaultConfig):
|
||||||
|
|
||||||
assert cfg.reverse() == True
|
assert cfg.reverse() == True
|
||||||
|
|
||||||
|
|
||||||
def test_logfile(defaultConfig):
|
def test_logfile(defaultConfig):
|
||||||
assert defaultConfig.logfile() is None
|
assert defaultConfig.logfile() is None
|
||||||
|
|
||||||
|
@ -68,7 +80,6 @@ def test_logfile(defaultConfig):
|
||||||
assert cfg.logfile() == logfile
|
assert cfg.logfile() == logfile
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_all_modules():
|
def test_all_modules():
|
||||||
modules = core.config.all_modules()
|
modules = core.config.all_modules()
|
||||||
assert len(modules) > 0
|
assert len(modules) > 0
|
||||||
|
@ -84,8 +95,10 @@ def test_all_modules():
|
||||||
"modules",
|
"modules",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assert os.path.exists(os.path.join(base, "contrib", pyname)) \
|
assert os.path.exists(os.path.join(base, "contrib", pyname)) or os.path.exists(
|
||||||
or os.path.exists(os.path.join(base, "core", pyname))
|
os.path.join(base, "core", pyname)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_list_output(mocker):
|
def test_list_output(mocker):
|
||||||
mocker.patch("core.config.sys")
|
mocker.patch("core.config.sys")
|
||||||
|
@ -93,10 +106,13 @@ def test_list_output(mocker):
|
||||||
cfg = core.config.Config(["-l", "modules"])
|
cfg = core.config.Config(["-l", "modules"])
|
||||||
cfg = core.config.Config(["-l", "modules-rst"])
|
cfg = core.config.Config(["-l", "modules-rst"])
|
||||||
|
|
||||||
|
|
||||||
def test_missing_parameter():
|
def test_missing_parameter():
|
||||||
cfg = core.config.Config(["-p", "test.key"])
|
cfg = core.config.Config(["-p", "test.key"])
|
||||||
|
|
||||||
assert cfg.get("test.key") == None
|
assert cfg.get("test.key") == None
|
||||||
assert cfg.get("test.key", "no-value-set") == "no-value-set"
|
assert cfg.get("test.key", "no-value-set") == "no-value-set"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -5,6 +5,7 @@ import core.widget
|
||||||
import core.module
|
import core.module
|
||||||
import core.config
|
import core.config
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def module():
|
def module():
|
||||||
class TestModule(core.module.Module):
|
class TestModule(core.module.Module):
|
||||||
|
@ -17,28 +18,34 @@ def module():
|
||||||
@core.decorators.scrollable
|
@core.decorators.scrollable
|
||||||
def get(self, widget):
|
def get(self, widget):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
module = TestModule()
|
module = TestModule()
|
||||||
module.set("scrolling.width", 10)
|
module.set("scrolling.width", 10)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
def test_never(module):
|
def test_never(module):
|
||||||
assert module.parameter("interval") == "never"
|
assert module.parameter("interval") == "never"
|
||||||
|
|
||||||
|
|
||||||
def test_no_text(module):
|
def test_no_text(module):
|
||||||
assert module.text == ""
|
assert module.text == ""
|
||||||
assert module.get(module.widget()) == ""
|
assert module.get(module.widget()) == ""
|
||||||
|
|
||||||
|
|
||||||
def test_smaller(module):
|
def test_smaller(module):
|
||||||
module.text = "test"
|
module.text = "test"
|
||||||
assert module.parameter("scrolling.width") > len(module.text)
|
assert module.parameter("scrolling.width") > len(module.text)
|
||||||
assert module.get(module.widget()) == module.text
|
assert module.get(module.widget()) == module.text
|
||||||
|
|
||||||
|
|
||||||
def test_bigger(module):
|
def test_bigger(module):
|
||||||
module.text = "this is a really really long sample text"
|
module.text = "this is a really really long sample text"
|
||||||
maxwidth = module.parameter("scrolling.width")
|
maxwidth = module.parameter("scrolling.width")
|
||||||
assert maxwidth < len(module.text)
|
assert maxwidth < len(module.text)
|
||||||
assert module.get(module.widget()) == module.text[:maxwidth]
|
assert module.get(module.widget()) == module.text[:maxwidth]
|
||||||
|
|
||||||
|
|
||||||
def test_bounce(module):
|
def test_bounce(module):
|
||||||
module.text = "abcd"
|
module.text = "abcd"
|
||||||
module.set("scrolling.width", 2)
|
module.set("scrolling.width", 2)
|
||||||
|
@ -52,6 +59,7 @@ def test_bounce(module):
|
||||||
assert module.get(module.widget()) == "bc"
|
assert module.get(module.widget()) == "bc"
|
||||||
assert module.get(module.widget()) == "ab"
|
assert module.get(module.widget()) == "ab"
|
||||||
|
|
||||||
|
|
||||||
def test_nobounce(module):
|
def test_nobounce(module):
|
||||||
module.set("scrolling.bounce", False)
|
module.set("scrolling.bounce", False)
|
||||||
module.set("scrolling.width", 2)
|
module.set("scrolling.width", 2)
|
||||||
|
@ -64,6 +72,7 @@ def test_nobounce(module):
|
||||||
assert module.get(module.widget()) == "bc"
|
assert module.get(module.widget()) == "bc"
|
||||||
assert module.get(module.widget()) == "cd"
|
assert module.get(module.widget()) == "cd"
|
||||||
|
|
||||||
|
|
||||||
def test_completely_changed_data(module):
|
def test_completely_changed_data(module):
|
||||||
module.text = "abcd"
|
module.text = "abcd"
|
||||||
module.set("scrolling.width", 2)
|
module.set("scrolling.width", 2)
|
||||||
|
@ -75,6 +84,7 @@ def test_completely_changed_data(module):
|
||||||
assert module.get(module.widget()) == "wx"
|
assert module.get(module.widget()) == "wx"
|
||||||
assert module.get(module.widget()) == "xy"
|
assert module.get(module.widget()) == "xy"
|
||||||
|
|
||||||
|
|
||||||
def test_slightly_changed_data(module):
|
def test_slightly_changed_data(module):
|
||||||
module.text = "this is a sample song (0:00)"
|
module.text = "this is a sample song (0:00)"
|
||||||
module.set("scrolling.width", 10)
|
module.set("scrolling.width", 10)
|
||||||
|
@ -89,6 +99,7 @@ def test_slightly_changed_data(module):
|
||||||
module.text = "this is a different song (0:13)"
|
module.text = "this is a different song (0:13)"
|
||||||
assert module.get(module.widget()) == module.text[0:10]
|
assert module.get(module.widget()) == module.text[0:10]
|
||||||
|
|
||||||
|
|
||||||
def test_n_plus_one(module):
|
def test_n_plus_one(module):
|
||||||
module.text = "10 letters"
|
module.text = "10 letters"
|
||||||
module.set("scrolling.width", 9)
|
module.set("scrolling.width", 9)
|
||||||
|
|
|
@ -2,9 +2,10 @@ import pytest
|
||||||
|
|
||||||
import core.event
|
import core.event
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def someEvent():
|
def someEvent():
|
||||||
class Event():
|
class Event:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
core.event.clear()
|
core.event.clear()
|
||||||
self.id = "some event"
|
self.id = "some event"
|
||||||
|
@ -32,6 +33,7 @@ def test_simple_callback(someEvent):
|
||||||
|
|
||||||
assert someEvent.called == 2
|
assert someEvent.called == 2
|
||||||
|
|
||||||
|
|
||||||
def test_args_callback(someEvent):
|
def test_args_callback(someEvent):
|
||||||
core.event.register(someEvent.id, someEvent.callback, "a", "b")
|
core.event.register(someEvent.id, someEvent.callback, "a", "b")
|
||||||
core.event.trigger(someEvent.id)
|
core.event.trigger(someEvent.id)
|
||||||
|
@ -40,6 +42,7 @@ def test_args_callback(someEvent):
|
||||||
assert len(someEvent.call_args) == 1
|
assert len(someEvent.call_args) == 1
|
||||||
assert someEvent.call_args[0] == ["a", "b"]
|
assert someEvent.call_args[0] == ["a", "b"]
|
||||||
|
|
||||||
|
|
||||||
def test_kwargs_callback(someEvent):
|
def test_kwargs_callback(someEvent):
|
||||||
core.event.register(
|
core.event.register(
|
||||||
someEvent.id, someEvent.callback, "a", "b", key1="test", key2="another"
|
someEvent.id, someEvent.callback, "a", "b", key1="test", key2="another"
|
||||||
|
@ -52,6 +55,7 @@ def test_kwargs_callback(someEvent):
|
||||||
assert len(someEvent.call_kwargs) == 1
|
assert len(someEvent.call_kwargs) == 1
|
||||||
assert someEvent.call_kwargs[0] == {"key1": "test", "key2": "another"}
|
assert someEvent.call_kwargs[0] == {"key1": "test", "key2": "another"}
|
||||||
|
|
||||||
|
|
||||||
def test_arg_trigger(someEvent):
|
def test_arg_trigger(someEvent):
|
||||||
core.event.register(someEvent.id, someEvent.callback)
|
core.event.register(someEvent.id, someEvent.callback)
|
||||||
core.event.trigger(someEvent.id, "a", "b")
|
core.event.trigger(someEvent.id, "a", "b")
|
||||||
|
@ -60,6 +64,7 @@ def test_arg_trigger(someEvent):
|
||||||
assert len(someEvent.call_args) == 1
|
assert len(someEvent.call_args) == 1
|
||||||
assert someEvent.call_args[0] == ["a", "b"]
|
assert someEvent.call_args[0] == ["a", "b"]
|
||||||
|
|
||||||
|
|
||||||
def test_kwargs_trigger(someEvent):
|
def test_kwargs_trigger(someEvent):
|
||||||
core.event.register(someEvent.id, someEvent.callback)
|
core.event.register(someEvent.id, someEvent.callback)
|
||||||
core.event.trigger(someEvent.id, "a", "c", key1="test", key2="something")
|
core.event.trigger(someEvent.id, "a", "c", key1="test", key2="something")
|
||||||
|
@ -70,4 +75,5 @@ def test_kwargs_trigger(someEvent):
|
||||||
assert len(someEvent.call_kwargs) == 1
|
assert len(someEvent.call_kwargs) == 1
|
||||||
assert someEvent.call_kwargs[0] == {"key1": "test", "key2": "something"}
|
assert someEvent.call_kwargs[0] == {"key1": "test", "key2": "something"}
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -10,42 +10,43 @@ import core.module
|
||||||
class SampleModule(core.module.Module):
|
class SampleModule(core.module.Module):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def clear_events():
|
def clear_events():
|
||||||
core.event.clear()
|
core.event.clear()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def i3():
|
def i3():
|
||||||
return core.output.i3()
|
return core.output.i3()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def module_a(mocker):
|
def module_a(mocker):
|
||||||
widget = mocker.MagicMock()
|
widget = mocker.MagicMock()
|
||||||
widget.full_text.return_value = "test"
|
widget.full_text.return_value = "test"
|
||||||
return SampleModule(
|
return SampleModule(config=core.config.Config([]), widgets=[widget, widget, widget])
|
||||||
config=core.config.Config([]), widgets=[widget, widget, widget]
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def paddedTheme():
|
def paddedTheme():
|
||||||
return core.theme.Theme(raw_data={"defaults": {"padding": " "}})
|
return core.theme.Theme(raw_data={"defaults": {"padding": " "}})
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def separatorTheme():
|
def separatorTheme():
|
||||||
return core.theme.Theme(
|
return core.theme.Theme(
|
||||||
raw_data={
|
raw_data={"defaults": {"separator": "***", "fg": "red", "bg": "blue"}}
|
||||||
"defaults": {"separator": "***", "fg": "red", "bg": "blue"}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def block_a(separatorTheme, module_a):
|
def block_a(separatorTheme, module_a):
|
||||||
return core.output.block(
|
return core.output.block(
|
||||||
theme=separatorTheme,
|
theme=separatorTheme, module=module_a, widget=module_a.widget(),
|
||||||
module=module_a,
|
|
||||||
widget=module_a.widget(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# def setUp(self):
|
# def setUp(self):
|
||||||
# self.i3 = core.output.i3()
|
# self.i3 = core.output.i3()
|
||||||
# widget = unittest.mock.MagicMock()
|
# widget = unittest.mock.MagicMock()
|
||||||
|
@ -63,21 +64,26 @@ def test_start(i3):
|
||||||
assert data["click_events"] == True
|
assert data["click_events"] == True
|
||||||
assert all_data["suffix"] == "\n["
|
assert all_data["suffix"] == "\n["
|
||||||
|
|
||||||
|
|
||||||
def test_stop(i3):
|
def test_stop(i3):
|
||||||
assert i3.stop()["suffix"] == "\n]"
|
assert i3.stop()["suffix"] == "\n]"
|
||||||
|
|
||||||
|
|
||||||
def test_no_modules_by_default(i3):
|
def test_no_modules_by_default(i3):
|
||||||
assert i3.modules() == []
|
assert i3.modules() == []
|
||||||
|
|
||||||
|
|
||||||
def test_register_single_module(i3, module_a):
|
def test_register_single_module(i3, module_a):
|
||||||
i3.modules(module_a)
|
i3.modules(module_a)
|
||||||
|
|
||||||
assert i3.modules() == [module_a]
|
assert i3.modules() == [module_a]
|
||||||
|
|
||||||
|
|
||||||
def test_register_multiple_modules(i3, module_a):
|
def test_register_multiple_modules(i3, module_a):
|
||||||
i3.modules([module_a, module_a, module_a])
|
i3.modules([module_a, module_a, module_a])
|
||||||
assert i3.modules() == [module_a, module_a, module_a]
|
assert i3.modules() == [module_a, module_a, module_a]
|
||||||
|
|
||||||
|
|
||||||
def test_draw_existing_module(mocker, i3):
|
def test_draw_existing_module(mocker, i3):
|
||||||
i3.test_draw = mocker.MagicMock(
|
i3.test_draw = mocker.MagicMock(
|
||||||
return_value={"blocks": {"test": True}, "suffix": "end"}
|
return_value={"blocks": {"test": True}, "suffix": "end"}
|
||||||
|
@ -85,31 +91,34 @@ def test_draw_existing_module(mocker, i3):
|
||||||
i3.draw("test_draw")
|
i3.draw("test_draw")
|
||||||
i3.test_draw.assert_called_once_with()
|
i3.test_draw.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
def test_empty_status_line(i3):
|
def test_empty_status_line(i3):
|
||||||
data = i3.statusline()
|
data = i3.statusline()
|
||||||
|
|
||||||
assert data["blocks"] == []
|
assert data["blocks"] == []
|
||||||
assert data["suffix"] == ","
|
assert data["suffix"] == ","
|
||||||
|
|
||||||
|
|
||||||
def test_statusline(i3, module_a):
|
def test_statusline(i3, module_a):
|
||||||
i3.modules([module_a, module_a, module_a])
|
i3.modules([module_a, module_a, module_a])
|
||||||
i3.update()
|
i3.update()
|
||||||
data = i3.statusline()
|
data = i3.statusline()
|
||||||
assert len(data["blocks"]) == len(module_a.widgets()) * 3
|
assert len(data["blocks"]) == len(module_a.widgets()) * 3
|
||||||
|
|
||||||
|
|
||||||
def test_padding(i3, paddedTheme, module_a):
|
def test_padding(i3, paddedTheme, module_a):
|
||||||
i3.theme(paddedTheme)
|
i3.theme(paddedTheme)
|
||||||
blk = core.output.block(
|
blk = core.output.block(i3.theme(), module_a, module_a.widget())
|
||||||
i3.theme(), module_a, module_a.widget()
|
|
||||||
)
|
|
||||||
blk.set("full_text", "abc")
|
blk.set("full_text", "abc")
|
||||||
result = blk.dict()["full_text"]
|
result = blk.dict()["full_text"]
|
||||||
assert result == " abc "
|
assert result == " abc "
|
||||||
|
|
||||||
|
|
||||||
def test_no_separator(i3, module_a):
|
def test_no_separator(i3, module_a):
|
||||||
result = i3.separator_block(module_a, module_a.widget())
|
result = i3.separator_block(module_a, module_a.widget())
|
||||||
assert result == []
|
assert result == []
|
||||||
|
|
||||||
|
|
||||||
def test_separator(i3, separatorTheme, module_a):
|
def test_separator(i3, separatorTheme, module_a):
|
||||||
i3.theme(separatorTheme)
|
i3.theme(separatorTheme)
|
||||||
result = i3.separator_block(module_a, module_a.widget())
|
result = i3.separator_block(module_a, module_a.widget())
|
||||||
|
@ -119,12 +128,14 @@ def test_separator(i3, separatorTheme, module_a):
|
||||||
assert result[0].dict().get("_decorator") == True
|
assert result[0].dict().get("_decorator") == True
|
||||||
assert result[0].dict()["color"] == separatorTheme.get("bg", module_a.widget())
|
assert result[0].dict()["color"] == separatorTheme.get("bg", module_a.widget())
|
||||||
|
|
||||||
|
|
||||||
def test_dump_json(mocker):
|
def test_dump_json(mocker):
|
||||||
obj = mocker.MagicMock()
|
obj = mocker.MagicMock()
|
||||||
obj.dict = mocker.MagicMock()
|
obj.dict = mocker.MagicMock()
|
||||||
core.output.dump_json(obj)
|
core.output.dump_json(obj)
|
||||||
obj.dict_assert_called_once_with()
|
obj.dict_assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
def test_assign():
|
def test_assign():
|
||||||
src = {"a": "x", "b": "y", "c": "z"}
|
src = {"a": "x", "b": "y", "c": "z"}
|
||||||
dst = {}
|
dst = {}
|
||||||
|
@ -138,29 +149,31 @@ def test_assign():
|
||||||
core.output.assign(src, dst, "blub", default="def")
|
core.output.assign(src, dst, "blub", default="def")
|
||||||
assert dst["blub"] == "def"
|
assert dst["blub"] == "def"
|
||||||
|
|
||||||
|
|
||||||
def test_pango_detection(block_a):
|
def test_pango_detection(block_a):
|
||||||
assert block_a.is_pango({}) == False
|
assert block_a.is_pango({}) == False
|
||||||
assert block_a.is_pango({"pango": {}}) == True
|
assert block_a.is_pango({"pango": {}}) == True
|
||||||
|
|
||||||
|
|
||||||
def test_pangoize(block_a):
|
def test_pangoize(block_a):
|
||||||
assert block_a.pangoize("test") == "test"
|
assert block_a.pangoize("test") == "test"
|
||||||
assert not "markup" in block_a.dict()
|
assert not "markup" in block_a.dict()
|
||||||
|
|
||||||
pango = block_a.pangoize(
|
pango = block_a.pangoize({"pango": {"attr": "blub", "x": "y", "full_text": "test"}})
|
||||||
{"pango": {"attr": "blub", "x": "y", "full_text": "test"}}
|
|
||||||
)
|
|
||||||
assert 'attr="blub"' in pango
|
assert 'attr="blub"' in pango
|
||||||
assert 'x="y"' in pango
|
assert 'x="y"' in pango
|
||||||
assert "<span " in pango
|
assert "<span " in pango
|
||||||
assert ">test</span>" in pango
|
assert ">test</span>" in pango
|
||||||
assert block_a.dict()["markup"] == "pango"
|
assert block_a.dict()["markup"] == "pango"
|
||||||
|
|
||||||
|
|
||||||
def test_padding(block_a):
|
def test_padding(block_a):
|
||||||
block_a.set("padding", "***")
|
block_a.set("padding", "***")
|
||||||
block_a.set("full_text", "test")
|
block_a.set("full_text", "test")
|
||||||
|
|
||||||
assert block_a.dict()["full_text"] == "***test***"
|
assert block_a.dict()["full_text"] == "***test***"
|
||||||
|
|
||||||
|
|
||||||
def test_pre_suffix(block_a):
|
def test_pre_suffix(block_a):
|
||||||
block_a.set("padding", "*")
|
block_a.set("padding", "*")
|
||||||
block_a.set("prefix", "pre")
|
block_a.set("prefix", "pre")
|
||||||
|
|
|
@ -12,14 +12,17 @@ class SampleModule(core.module.Module):
|
||||||
super().__init__(config, theme, widgets)
|
super().__init__(config, theme, widgets)
|
||||||
self.name = "test"
|
self.name = "test"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def clear_events():
|
def clear_events():
|
||||||
core.event.clear()
|
core.event.clear()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def defaultsTheme():
|
def defaultsTheme():
|
||||||
return {"defaults": {"fg": "red", "bg": "black"}}
|
return {"defaults": {"fg": "red", "bg": "black"}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cycleTheme():
|
def cycleTheme():
|
||||||
return {
|
return {
|
||||||
|
@ -30,22 +33,27 @@ def cycleTheme():
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def colorTheme():
|
def colorTheme():
|
||||||
return {"colors": [{"red": "#ff0000", "blue": "#0000ff"}]}
|
return {"colors": [{"red": "#ff0000", "blue": "#0000ff"}]}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def walTheme():
|
def walTheme():
|
||||||
return {"colors": ["wal"]}
|
return {"colors": ["wal"]}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cycleValueTheme():
|
def cycleValueTheme():
|
||||||
return {"defaults": {"fg": ["red", "green", "blue"]}}
|
return {"defaults": {"fg": ["red", "green", "blue"]}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def stateTheme():
|
def stateTheme():
|
||||||
return {"warning": {"fg": "yellow"}, "critical": {"fg": "red"}}
|
return {"warning": {"fg": "yellow"}, "critical": {"fg": "red"}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def overlayTheme():
|
def overlayTheme():
|
||||||
return {
|
return {
|
||||||
|
@ -53,20 +61,24 @@ def overlayTheme():
|
||||||
"test": {"load": {"prefix": "b"}, "prefix": "x"},
|
"test": {"load": {"prefix": "b"}, "prefix": "x"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_theme():
|
def test_invalid_theme():
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
core.theme.Theme("this-theme-does-not-exist")
|
core.theme.Theme("this-theme-does-not-exist")
|
||||||
|
|
||||||
|
|
||||||
def test_valid_theme():
|
def test_valid_theme():
|
||||||
theme = core.theme.Theme("default")
|
theme = core.theme.Theme("default")
|
||||||
assert theme.name == "default"
|
assert theme.name == "default"
|
||||||
|
|
||||||
|
|
||||||
def test_defaults(defaultsTheme):
|
def test_defaults(defaultsTheme):
|
||||||
theme = core.theme.Theme(raw_data=defaultsTheme)
|
theme = core.theme.Theme(raw_data=defaultsTheme)
|
||||||
|
|
||||||
assert theme.get("fg") == defaultsTheme["defaults"]["fg"]
|
assert theme.get("fg") == defaultsTheme["defaults"]["fg"]
|
||||||
assert theme.get("bg") == defaultsTheme["defaults"]["bg"]
|
assert theme.get("bg") == defaultsTheme["defaults"]["bg"]
|
||||||
|
|
||||||
|
|
||||||
def test_cycle(mocker, cycleTheme):
|
def test_cycle(mocker, cycleTheme):
|
||||||
theme = core.theme.Theme(raw_data=cycleTheme)
|
theme = core.theme.Theme(raw_data=cycleTheme)
|
||||||
|
|
||||||
|
@ -90,6 +102,7 @@ def test_cycle(mocker, cycleTheme):
|
||||||
assert theme.get("fg") == cycleTheme["cycle"][0]["fg"]
|
assert theme.get("fg") == cycleTheme["cycle"][0]["fg"]
|
||||||
assert theme.get("bg") == cycleTheme["cycle"][0]["bg"]
|
assert theme.get("bg") == cycleTheme["cycle"][0]["bg"]
|
||||||
|
|
||||||
|
|
||||||
def test_custom_iconset(defaultsTheme):
|
def test_custom_iconset(defaultsTheme):
|
||||||
theme = core.theme.Theme(raw_data=defaultsTheme)
|
theme = core.theme.Theme(raw_data=defaultsTheme)
|
||||||
|
|
||||||
|
@ -103,6 +116,7 @@ def test_custom_iconset(defaultsTheme):
|
||||||
assert theme.get("padding") == "aaa"
|
assert theme.get("padding") == "aaa"
|
||||||
assert theme.get("fg") == "blue" # test override
|
assert theme.get("fg") == "blue" # test override
|
||||||
|
|
||||||
|
|
||||||
def test_colors(defaultsTheme, colorTheme):
|
def test_colors(defaultsTheme, colorTheme):
|
||||||
theme = core.theme.Theme(raw_data=defaultsTheme)
|
theme = core.theme.Theme(raw_data=defaultsTheme)
|
||||||
assert theme.keywords() == {}
|
assert theme.keywords() == {}
|
||||||
|
@ -110,6 +124,7 @@ def test_colors(defaultsTheme, colorTheme):
|
||||||
theme = core.theme.Theme(raw_data=colorTheme)
|
theme = core.theme.Theme(raw_data=colorTheme)
|
||||||
assert theme.keywords() == colorTheme["colors"][0]
|
assert theme.keywords() == colorTheme["colors"][0]
|
||||||
|
|
||||||
|
|
||||||
def test_wal_colors(mocker, walTheme):
|
def test_wal_colors(mocker, walTheme):
|
||||||
io = mocker.patch("core.theme.io")
|
io = mocker.patch("core.theme.io")
|
||||||
os = mocker.patch("core.theme.os")
|
os = mocker.patch("core.theme.os")
|
||||||
|
@ -124,6 +139,7 @@ def test_wal_colors(mocker, walTheme):
|
||||||
|
|
||||||
assert theme.keywords() == {"red": "#ff0000"}
|
assert theme.keywords() == {"red": "#ff0000"}
|
||||||
|
|
||||||
|
|
||||||
def test_wal_special(mocker, walTheme):
|
def test_wal_special(mocker, walTheme):
|
||||||
io = mocker.patch("core.theme.io")
|
io = mocker.patch("core.theme.io")
|
||||||
os = mocker.patch("core.theme.os")
|
os = mocker.patch("core.theme.os")
|
||||||
|
@ -137,6 +153,7 @@ def test_wal_special(mocker, walTheme):
|
||||||
|
|
||||||
assert theme.keywords() == {"background": "#ff0000"}
|
assert theme.keywords() == {"background": "#ff0000"}
|
||||||
|
|
||||||
|
|
||||||
def test_cycle_value(cycleValueTheme):
|
def test_cycle_value(cycleValueTheme):
|
||||||
widget = core.widget.Widget()
|
widget = core.widget.Widget()
|
||||||
expected = cycleValueTheme["defaults"]["fg"]
|
expected = cycleValueTheme["defaults"]["fg"]
|
||||||
|
@ -148,6 +165,7 @@ def test_cycle_value(cycleValueTheme):
|
||||||
assert theme.get("fg", widget) == expected[i % len(expected)]
|
assert theme.get("fg", widget) == expected[i % len(expected)]
|
||||||
core.event.trigger("draw")
|
core.event.trigger("draw")
|
||||||
|
|
||||||
|
|
||||||
def test_state(stateTheme):
|
def test_state(stateTheme):
|
||||||
widget = core.widget.Widget()
|
widget = core.widget.Widget()
|
||||||
theme = core.theme.Theme(raw_data=stateTheme)
|
theme = core.theme.Theme(raw_data=stateTheme)
|
||||||
|
@ -160,6 +178,7 @@ def test_state(stateTheme):
|
||||||
widget.state = types.MethodType(lambda self: ["critical"], widget)
|
widget.state = types.MethodType(lambda self: ["critical"], widget)
|
||||||
assert theme.get("fg", widget) == stateTheme["critical"]["fg"]
|
assert theme.get("fg", widget) == stateTheme["critical"]["fg"]
|
||||||
|
|
||||||
|
|
||||||
def test_overlay(overlayTheme):
|
def test_overlay(overlayTheme):
|
||||||
widget = core.widget.Widget()
|
widget = core.widget.Widget()
|
||||||
module = SampleModule(widget)
|
module = SampleModule(widget)
|
||||||
|
|
|
@ -18,10 +18,12 @@ class SampleModule(core.module.Module):
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
return self.states
|
return self.states
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def widget_a():
|
def widget_a():
|
||||||
return core.widget.Widget("some random value")
|
return core.widget.Widget("some random value")
|
||||||
|
|
||||||
|
|
||||||
# class widget(unittest.TestCase):
|
# class widget(unittest.TestCase):
|
||||||
# def setUp(self):
|
# def setUp(self):
|
||||||
# self.someValue = "some random value"
|
# self.someValue = "some random value"
|
||||||
|
@ -34,38 +36,46 @@ def widget_a():
|
||||||
#
|
#
|
||||||
# self.assertNotEqual(self.someValue, self.someOtherValue)
|
# self.assertNotEqual(self.someValue, self.someOtherValue)
|
||||||
|
|
||||||
|
|
||||||
def test_text_fulltext():
|
def test_text_fulltext():
|
||||||
widget = core.widget.Widget(full_text="this is some value")
|
widget = core.widget.Widget(full_text="this is some value")
|
||||||
assert widget.full_text() == "this is some value"
|
assert widget.full_text() == "this is some value"
|
||||||
|
|
||||||
|
|
||||||
def test_set_fulltext(widget_a):
|
def test_set_fulltext(widget_a):
|
||||||
assert widget_a.full_text() != "new value"
|
assert widget_a.full_text() != "new value"
|
||||||
widget_a.full_text("new value")
|
widget_a.full_text("new value")
|
||||||
assert widget_a.full_text() == "new value"
|
assert widget_a.full_text() == "new value"
|
||||||
|
|
||||||
|
|
||||||
def test_callable_fulltext(mocker):
|
def test_callable_fulltext(mocker):
|
||||||
callback = mocker.MagicMock(return_value="callback returns")
|
callback = mocker.MagicMock(return_value="callback returns")
|
||||||
widget = core.widget.Widget(full_text=callback)
|
widget = core.widget.Widget(full_text=callback)
|
||||||
assert widget.full_text() == "callback returns"
|
assert widget.full_text() == "callback returns"
|
||||||
callback.assert_called_once_with(widget)
|
callback.assert_called_once_with(widget)
|
||||||
|
|
||||||
|
|
||||||
def test_set_callable_fulltext(mocker, widget_a):
|
def test_set_callable_fulltext(mocker, widget_a):
|
||||||
callback = mocker.MagicMock(return_value="this is a test")
|
callback = mocker.MagicMock(return_value="this is a test")
|
||||||
widget_a.full_text(callback)
|
widget_a.full_text(callback)
|
||||||
assert widget_a.full_text() == "this is a test"
|
assert widget_a.full_text() == "this is a test"
|
||||||
callback.assert_called_once_with(widget_a)
|
callback.assert_called_once_with(widget_a)
|
||||||
|
|
||||||
|
|
||||||
def test_state_defaults_to_empty(widget_a):
|
def test_state_defaults_to_empty(widget_a):
|
||||||
assert widget_a.state() == []
|
assert widget_a.state() == []
|
||||||
|
|
||||||
|
|
||||||
def test_single_widget_state(widget_a):
|
def test_single_widget_state(widget_a):
|
||||||
widget_a.set("state", "state1")
|
widget_a.set("state", "state1")
|
||||||
assert widget_a.state() == ["state1"]
|
assert widget_a.state() == ["state1"]
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_widget_states(widget_a):
|
def test_multiple_widget_states(widget_a):
|
||||||
widget_a.set("state", ["state1", "state2"])
|
widget_a.set("state", ["state1", "state2"])
|
||||||
assert widget_a.state() == ["state1", "state2"]
|
assert widget_a.state() == ["state1", "state2"]
|
||||||
|
|
||||||
|
|
||||||
def test_widget_module_state(widget_a):
|
def test_widget_module_state(widget_a):
|
||||||
module = SampleModule(widgets=widget_a)
|
module = SampleModule(widgets=widget_a)
|
||||||
widget_a.set("state", ["state1", "state2"])
|
widget_a.set("state", ["state1", "state2"])
|
||||||
|
@ -76,6 +86,7 @@ def test_widget_module_state(widget_a):
|
||||||
module.states = ["a", "b"]
|
module.states = ["a", "b"]
|
||||||
assert widget_a.state() == ["state1", "state2", "a", "b"]
|
assert widget_a.state() == ["state1", "state2", "a", "b"]
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_widget_themes():
|
def test_multiple_widget_themes():
|
||||||
widget1 = core.widget.Widget(full_text="a")
|
widget1 = core.widget.Widget(full_text="a")
|
||||||
widget2 = core.widget.Widget(full_text="b")
|
widget2 = core.widget.Widget(full_text="b")
|
||||||
|
|
|
@ -3,46 +3,65 @@ import pytest
|
||||||
import core.config
|
import core.config
|
||||||
import modules.contrib.mpd
|
import modules.contrib.mpd
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mpd_module():
|
def mpd_module():
|
||||||
return modules.contrib.mpd.Module(config=core.config.Config([]), theme=None)
|
return modules.contrib.mpd.Module(config=core.config.Config([]), theme=None)
|
||||||
|
|
||||||
|
|
||||||
def _test_state(mocker, mpd_module, widget_name, expected_output):
|
def _test_state(mocker, mpd_module, widget_name, expected_output):
|
||||||
widget = mocker.Mock()
|
widget = mocker.Mock()
|
||||||
widget.name = widget_name
|
widget.name = widget_name
|
||||||
return mpd_module.state(widget) == expected_output
|
return mpd_module.state(widget) == expected_output
|
||||||
|
|
||||||
|
|
||||||
def test_states(mocker, mpd_module):
|
def test_states(mocker, mpd_module):
|
||||||
assert _test_state(mocker, mpd_module, 'mpd.repeat', 'repeat-off')
|
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.shuffle", "shuffle-off")
|
||||||
assert _test_state(mocker, mpd_module, 'mpd.prev', 'prev')
|
assert _test_state(mocker, mpd_module, "mpd.prev", "prev")
|
||||||
assert _test_state(mocker, mpd_module, 'mpd.next', 'next')
|
assert _test_state(mocker, mpd_module, "mpd.next", "next")
|
||||||
|
|
||||||
|
|
||||||
def test_no_host(mpd_module):
|
def test_no_host(mpd_module):
|
||||||
assert mpd_module._hostcmd == ''
|
assert mpd_module._hostcmd == ""
|
||||||
|
|
||||||
|
|
||||||
def test_host():
|
def test_host():
|
||||||
module_with_host = modules.contrib.mpd.Module(config=core.config.Config(['-p', 'mpd.host=sample-host']), theme=None)
|
module_with_host = modules.contrib.mpd.Module(
|
||||||
assert module_with_host._hostcmd == ' -h sample-host'
|
config=core.config.Config(["-p", "mpd.host=sample-host"]), theme=None
|
||||||
|
)
|
||||||
|
assert module_with_host._hostcmd == " -h sample-host"
|
||||||
|
|
||||||
|
|
||||||
def test_host2(mocker):
|
def test_host2(mocker):
|
||||||
cli = mocker.patch("modules.contrib.mpd.util.cli")
|
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 = modules.contrib.mpd.Module(
|
||||||
|
config=core.config.Config(["-p", "mpd.host=sample-host"]), theme=None
|
||||||
|
)
|
||||||
module_with_host.update()
|
module_with_host.update()
|
||||||
args, kwargs = cli.execute.call_args
|
args, kwargs = cli.execute.call_args
|
||||||
|
|
||||||
assert " -h sample-host" in args[0] and "mpc" in args[0]
|
assert " -h sample-host" in args[0] and "mpc" in args[0]
|
||||||
|
|
||||||
|
|
||||||
def test_bad_layout():
|
def test_bad_layout():
|
||||||
pytest.raises(KeyError, modules.contrib.mpd.Module, config=core.config.Config(['-p', 'mpd.layout="mpd.inexistent"']), theme=None)
|
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):
|
def test_hidden_on_creation(mpd_module):
|
||||||
assert mpd_module.hidden()
|
assert mpd_module.hidden()
|
||||||
|
|
||||||
|
|
||||||
def test_update_calls_load_song(mocker, mpd_module):
|
def test_update_calls_load_song(mocker, mpd_module):
|
||||||
mocker.patch.object(mpd_module, '_load_song')
|
mocker.patch.object(mpd_module, "_load_song")
|
||||||
mpd_module.update()
|
mpd_module.update()
|
||||||
mpd_module._load_song.assert_called_with()
|
mpd_module._load_song.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
def test_default_layout(mpd_module):
|
def test_default_layout(mpd_module):
|
||||||
assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"
|
assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"
|
||||||
|
|
|
@ -2,22 +2,27 @@ import pytest
|
||||||
|
|
||||||
from util.algorithm import *
|
from util.algorithm import *
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def someData():
|
def someData():
|
||||||
return {"a": 100, "b": 200, "c": [1, 2, 3]}
|
return {"a": 100, "b": 200, "c": [1, 2, 3]}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def differentData():
|
def differentData():
|
||||||
return {"x": 20, "y": "bla", "z": ["a", "b"]}
|
return {"x": 20, "y": "bla", "z": ["a", "b"]}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def moreData():
|
def moreData():
|
||||||
return {"n": 100}
|
return {"n": 100}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def overlapData():
|
def overlapData():
|
||||||
return {"a": 200, "c": [1, 2, 4]}
|
return {"a": 200, "c": [1, 2, 4]}
|
||||||
|
|
||||||
|
|
||||||
def test_merge_with_empty(someData):
|
def test_merge_with_empty(someData):
|
||||||
assert merge(someData, {}) == someData
|
assert merge(someData, {}) == someData
|
||||||
assert merge(someData, None) == None
|
assert merge(someData, None) == None
|
||||||
|
|
|
@ -2,24 +2,30 @@ import pytest
|
||||||
|
|
||||||
import util.cli
|
import util.cli
|
||||||
|
|
||||||
|
|
||||||
def test_valid_command():
|
def test_valid_command():
|
||||||
assert util.cli.execute("echo test") == "test\n"
|
assert util.cli.execute("echo test") == "test\n"
|
||||||
|
|
||||||
|
|
||||||
def test_utf_command():
|
def test_utf_command():
|
||||||
rv = util.cli.execute("echo ÖPmŧß")
|
rv = util.cli.execute("echo ÖPmŧß")
|
||||||
assert util.cli.execute("echo ÖPmŧß") == "ÖPmŧß\n"
|
assert util.cli.execute("echo ÖPmŧß") == "ÖPmŧß\n"
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_command():
|
def test_invalid_command():
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
util.cli.execute("i-do-not-exist")
|
util.cli.execute("i-do-not-exist")
|
||||||
|
|
||||||
|
|
||||||
def test_command_exit_code():
|
def test_command_exit_code():
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
util.cli.execute("cat i-do-not-exist")
|
util.cli.execute("cat i-do-not-exist")
|
||||||
|
|
||||||
|
|
||||||
def test_command_exit_code_no_error():
|
def test_command_exit_code_no_error():
|
||||||
util.cli.execute("cat i-do-not-exist", ignore_errors=True)
|
util.cli.execute("cat i-do-not-exist", ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
def test_async():
|
def test_async():
|
||||||
assert util.cli.execute("echo test", wait=False) == ""
|
assert util.cli.execute("echo test", wait=False) == ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue