bumblebee-status/tests/core/test_config.py

125 lines
2.9 KiB
Python
Raw Permalink Normal View History

2020-05-02 14:09:30 +02:00
import os
2020-06-20 14:53:44 +02:00
import pytest
import core.config
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
@pytest.fixture
def defaultConfig():
return core.config.Config([])
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_module():
modules = ["module-1", "module-2", "module-3"]
cfg = core.config.Config(["-m"] + modules)
assert cfg.modules() == modules
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_module_ordering_maintained():
modules = ["module-1", "module-5", "module-7"]
more_modules = ["module-0", "module-2", "aaa"]
cfg = core.config.Config(["-m"] + modules + ["-m"] + more_modules)
assert cfg.modules() == modules + more_modules
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_default_interval(defaultConfig):
assert defaultConfig.interval() == 1
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_interval():
interval = 4
cfg = core.config.Config(["-p", "interval={}".format(interval)])
assert cfg.interval() == interval
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_floating_interval():
interval = 4.5
cfg = core.config.Config(["-p", "interval={}".format(interval)])
2020-05-02 14:09:30 +02:00
2020-06-20 14:53:44 +02:00
assert cfg.interval() == interval
2020-05-02 14:09:30 +02:00
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_default_theme(defaultConfig):
assert defaultConfig.theme() == "default"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_theme():
theme_name = "sample-theme"
cfg = core.config.Config(["-t", theme_name])
assert cfg.theme() == theme_name
2020-05-02 14:09:30 +02:00
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_default_iconset(defaultConfig):
assert defaultConfig.iconset() == "auto"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_iconset():
iconset_name = "random-iconset"
cfg = core.config.Config(["-i", iconset_name])
assert cfg.iconset() == iconset_name
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_reverse(defaultConfig):
assert defaultConfig.reverse() == False
cfg = core.config.Config(["-r"])
assert cfg.reverse() == True
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_logfile(defaultConfig):
assert defaultConfig.logfile() is None
logfile = "some-random-logfile"
cfg = core.config.Config(["-f", logfile])
assert cfg.logfile() == logfile
def test_all_modules():
modules = core.config.all_modules()
assert len(modules) > 0
for module in modules:
pyname = "{}.py".format(module)
base = os.path.abspath(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"..",
"..",
"bumblebee_status",
"modules",
)
)
2020-06-20 15:11:53 +02:00
assert os.path.exists(os.path.join(base, "contrib", pyname)) or os.path.exists(
os.path.join(base, "core", pyname)
)
2020-06-20 14:53:44 +02:00
def test_list_output(mocker):
mocker.patch("core.config.sys")
cfg = core.config.Config(["-l", "themes"])
cfg = core.config.Config(["-l", "modules"])
cfg = core.config.Config(["-l", "modules-rst"])
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_missing_parameter():
cfg = core.config.Config(["-p", "test.key"])
assert cfg.get("test.key") == None
assert cfg.get("test.key", "no-value-set") == "no-value-set"
2020-06-20 15:11:53 +02:00
def test_file_case_sensitivity():
cfg = core.config.Config([])
cfg.load_config("", content="[module-parameters]\ntest.key = VaLuE\ntest.KeY2 = value")
assert cfg.get("test.key") == "VaLuE"
assert cfg.get("test.KeY2") == "value"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
#
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4