Ejemplo n.º 1
0
def backup_dictionary_stack(dictionaries, path):
    if dictionaries:
        with open(path, 'w') as f:
            json.dump([DictionaryConfig.to_dict(d) for d in dictionaries], f)
    else:
        try:
            os.remove(path)
        except OSError:
            pass  #Good, we didn't want it anyway!
Ejemplo n.º 2
0
 def test_dictionary_config(self):
     short_path = os.path.normcase(os.path.normpath('~/foo/bar'))
     full_path = os.path.normcase(os.path.expanduser(os.path.normpath('~/foo/bar')))
     dc = DictionaryConfig(short_path)
     # Path should be expanded.
     self.assertEqual(dc.path, full_path)
     # Shortened path is available through short_path.
     self.assertEqual(dc.short_path, short_path)
     # Enabled default to True.
     self.assertEqual(dc.enabled, True)
     # Check conversion to dict: short path should be used.
     self.assertEqual(dc.to_dict(), {'path': short_path, 'enabled': True})
     # Test replace method.
     dc = dc.replace(enabled=False)
     self.assertEqual(dc.path, full_path)
     self.assertEqual(dc.enabled, False)
     # Test creation from dict.
     self.assertEqual(DictionaryConfig.from_dict({'path': short_path, 'enabled': False}), dc)