2020-05-02 14:09:30 +02:00
|
|
|
import os
|
2020-01-19 15:36:52 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import core.config
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
class config(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.someModules = ["b", "x", "a"]
|
|
|
|
self.moreModules = ["this", "module", "here"]
|
|
|
|
self.someTheme = "some-theme"
|
|
|
|
self.someIconset = "some-iconset"
|
2020-05-02 14:09:30 +02:00
|
|
|
self.defaultConfig = core.config.Config([])
|
2020-01-19 15:36:52 +01:00
|
|
|
|
2020-01-25 14:24:21 +01:00
|
|
|
def test_module(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-m"] + self.someModules)
|
2020-02-09 13:46:56 +01:00
|
|
|
self.assertEqual(self.someModules, cfg.modules())
|
2020-01-19 15:36:52 +01:00
|
|
|
|
2020-01-25 14:24:21 +01:00
|
|
|
def test_module_ordering_maintained(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-m"] + self.someModules + ["-m"] + self.moreModules)
|
2020-02-09 13:46:56 +01:00
|
|
|
self.assertEqual(self.someModules + self.moreModules, cfg.modules())
|
2020-01-19 15:36:52 +01:00
|
|
|
|
2020-01-25 14:24:21 +01:00
|
|
|
def test_default_interval(self):
|
2020-05-02 14:09:30 +02:00
|
|
|
self.assertEqual(1, self.defaultConfig.interval())
|
2020-01-25 14:24:21 +01:00
|
|
|
|
|
|
|
def test_interval(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-p", "interval=4"])
|
2020-01-25 14:24:21 +01:00
|
|
|
self.assertEqual(4, cfg.interval())
|
|
|
|
|
|
|
|
def test_float_interval(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-p", "interval=0.5"])
|
2020-01-25 14:24:21 +01:00
|
|
|
self.assertEqual(0.5, cfg.interval())
|
|
|
|
|
2020-02-09 13:46:56 +01:00
|
|
|
def test_default_theme(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual("default", self.defaultConfig.theme())
|
2020-02-09 13:46:56 +01:00
|
|
|
|
|
|
|
def test_theme(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-t", self.someTheme])
|
2020-02-09 13:46:56 +01:00
|
|
|
self.assertEqual(self.someTheme, cfg.theme())
|
|
|
|
|
|
|
|
def test_default_iconset(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual("auto", self.defaultConfig.iconset())
|
2020-02-09 13:46:56 +01:00
|
|
|
|
|
|
|
def test_iconset(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-i", self.someIconset])
|
2020-02-09 13:46:56 +01:00
|
|
|
self.assertEqual(self.someIconset, cfg.iconset())
|
|
|
|
|
2020-05-02 14:09:30 +02:00
|
|
|
def test_right_to_left(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-r"])
|
2020-05-02 14:09:30 +02:00
|
|
|
self.assertTrue(cfg.reverse())
|
|
|
|
self.assertFalse(self.defaultConfig.reverse())
|
|
|
|
|
|
|
|
def test_logfile(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-f", "my-custom-logfile"])
|
2020-05-02 14:09:30 +02:00
|
|
|
self.assertEquals(None, self.defaultConfig.logfile())
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEquals("my-custom-logfile", cfg.logfile())
|
2020-05-02 14:09:30 +02:00
|
|
|
|
|
|
|
def test_all_modules(self):
|
|
|
|
modules = core.config.all_modules()
|
|
|
|
self.assertGreater(len(modules), 0)
|
|
|
|
for module in modules:
|
2020-05-03 11:15:52 +02:00
|
|
|
pyname = "{}.py".format(module)
|
|
|
|
base = os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)), "..", "..", "modules"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.exists(os.path.join(base, "contrib", pyname))
|
|
|
|
or os.path.exists(os.path.join(base, "core", pyname))
|
|
|
|
)
|
2020-05-02 14:09:30 +02:00
|
|
|
|
|
|
|
def test_list_output(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
with unittest.mock.patch("core.config.sys") as sys:
|
|
|
|
cfg = core.config.Config(["-l", "themes"])
|
|
|
|
cfg = core.config.Config(["-l", "modules"])
|
|
|
|
cfg = core.config.Config(["-l", "modules-markdown"])
|
2020-05-02 14:09:30 +02:00
|
|
|
# TODO: think of some plausibility testing here
|
|
|
|
|
|
|
|
def test_missing_parameter(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
cfg = core.config.Config(["-p", "test.key"])
|
|
|
|
self.assertEqual("no-value-set", cfg.get("test.key", "no-value-set"))
|
|
|
|
|
2020-05-02 14:09:30 +02:00
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|