test for config contents

first
sezanzeb 4 years ago
parent 1780fbee96
commit cb6adb0a5c

@ -145,17 +145,10 @@ class Config:
def get(self, key):
"""Read a value from the configuration or get the default."""
self.check_mtime()
if key not in _defaults:
logger.error('Unknown setting %s', key)
return None
return self._config.get(key, _defaults[key])
def set(self, key, value):
"""Write a setting into memory and ~/.config/key-mapper/config."""
if key not in _defaults:
logger.error('Unknown setting %s', key)
return None
"""Write a setting into memory and ~/.config/key-mapper/."""
self.check_mtime()
if key in self._config and self._config[key] == value:

@ -32,5 +32,10 @@ def find_devices():
def get_presets(device):
"""Get all configured presets for the device"""
"""Get all configured presets for the device."""
pass
def get_mappings(device, preset):
"""Get all configured buttons of the preset."""
pass

@ -56,6 +56,12 @@ class ConfigTest(unittest.TestCase):
get_config('device2', 'preset3', '/tmp/key-mapper')
self.assertTrue(os.path.isfile('/tmp/key-mapper/device2/preset3'))
config.set('key1', 'value')
config.set('key2', 123)
with open('/tmp/key-mapper/device1/preset1', 'r') as f:
contents = f.read()
self.assertEqual(contents, 'key1=value\nkey2=123\n')
if __name__ == "__main__":
unittest.main()

Loading…
Cancel
Save