more config tests

This commit is contained in:
sezanzeb 2020-11-27 00:11:23 +01:00
parent 924e2490da
commit 166e5b49bb
4 changed files with 20 additions and 7 deletions

View File

@ -52,7 +52,6 @@ class _Config:
if load: if load:
self._config['autoload'][device] = preset self._config['autoload'][device] = preset
elif self._config['autoload'].get(device) is not None: elif self._config['autoload'].get(device) is not None:
# TODO test
del self._config['autoload'][device] del self._config['autoload'][device]
def iterate_autoload_presets(self): def iterate_autoload_presets(self):
@ -61,7 +60,6 @@ class _Config:
def is_autoloaded(self, device, preset): def is_autoloaded(self, device, preset):
"""Should this preset be loaded automatically?""" """Should this preset be loaded automatically?"""
# TODO test
autoload_map = self._config.get('autoload') autoload_map = self._config.get('autoload')
if autoload_map is None: if autoload_map is None:
return False return False
@ -70,7 +68,7 @@ class _Config:
if autoload_preset is None: if autoload_preset is None:
return False return False
return True return autoload_preset == preset
def load_config(self): def load_config(self):
"""Load the config from the file system.""" """Load the config from the file system."""

View File

@ -80,7 +80,6 @@ class Daemon(service.Object):
""" """
def __init__(self, *args, autoload=True, **kwargs): def __init__(self, *args, autoload=True, **kwargs):
"""Constructs the daemon. You still need to run the GLib mainloop.""" """Constructs the daemon. You still need to run the GLib mainloop."""
print(autoload)
self.injectors = {} self.injectors = {}
if autoload: if autoload:
for device, preset in config.iterate_autoload_presets(): for device, preset in config.iterate_autoload_presets():

View File

@ -293,7 +293,6 @@ class Window:
device = self.selected_device device = self.selected_device
preset = self.selected_preset preset = self.selected_preset
# TODO test call this and then check config # TODO test call this and then check config
# TODO new screenshot
config.set_autoload_preset(device, preset, active) config.set_autoload_preset(device, preset, active)
config.save_config() config.save_config()

View File

@ -33,21 +33,38 @@ class TestConfig(unittest.TestCase):
def test_autoload(self): def test_autoload(self):
del config._config['autoload'] del config._config['autoload']
self.assertEqual(len(config.iterate_autoload_presets()), 0) self.assertEqual(len(config.iterate_autoload_presets()), 0)
self.assertFalse(config.is_autoloaded('d1', 'a'))
self.assertFalse(config.is_autoloaded('d2', 'b'))
config.set_autoload_preset('d1', 'a') config.set_autoload_preset('d1', 'a')
self.assertEqual(len(config.iterate_autoload_presets()), 1) self.assertEqual(len(config.iterate_autoload_presets()), 1)
self.assertTrue(config.is_autoloaded('d1', 'a'))
self.assertFalse(config.is_autoloaded('d2', 'b'))
config.set_autoload_preset('d2', 'b') config.set_autoload_preset('d2', 'b', True)
self.assertEqual(len(config.iterate_autoload_presets()), 2) self.assertEqual(len(config.iterate_autoload_presets()), 2)
self.assertTrue(config.is_autoloaded('d1', 'a'))
self.assertTrue(config.is_autoloaded('d2', 'b'))
config.set_autoload_preset('d2', 'c') config.set_autoload_preset('d2', 'c')
self.assertEqual(len(config.iterate_autoload_presets()), 2) self.assertEqual(len(config.iterate_autoload_presets()), 2)
self.assertTrue(config.is_autoloaded('d1', 'a'))
self.assertFalse(config.is_autoloaded('d2', 'b'))
self.assertTrue(config.is_autoloaded('d2', 'c'))
self.assertListEqual( self.assertListEqual(
list(config.iterate_autoload_presets()), list(config.iterate_autoload_presets()),
[('d1', 'a'), ('d2', 'c')] [('d1', 'a'), ('d2', 'c')]
) )
config.set_autoload_preset('d2', 'foo', False)
self.assertTrue(config.is_autoloaded('d1', 'a'))
self.assertFalse(config.is_autoloaded('d2', 'b'))
self.assertFalse(config.is_autoloaded('d2', 'c'))
self.assertListEqual(
list(config.iterate_autoload_presets()),
[('d1', 'a')]
)
def test_save_load(self): def test_save_load(self):
self.assertEqual(len(config.iterate_autoload_presets()), 0) self.assertEqual(len(config.iterate_autoload_presets()), 0)