test for config contents

This commit is contained in:
sezanzeb 2020-10-31 15:29:25 +01:00 committed by sezanzeb
parent a3f814f063
commit ee28c59bed
3 changed files with 13 additions and 9 deletions

View File

@ -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:

View File

@ -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

View File

@ -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()