def _saveOptsFile(self): opts = {} if self.growsize is not None: opts['growsize'] = self.growsize if self.maxsize is not None: opts['maxsize'] = self.maxsize s_common.yamlmod(opts, self.optspath)
def test_common_yaml(self): obj = [{'key': 1, 'key2': [1, 2, 3], 'key3': True, 'key4': 'some str', 'key5': { 'oh': 'my', 'we all': 'float down here' }, }, 'duck', False, 'zero', 0.1, ] with self.getTestDir() as dirn: s_common.yamlsave(obj, dirn, 'test.yaml') robj = s_common.yamlload(dirn, 'test.yaml') self.eq(obj, robj) obj = {'foo': 'bar', 'zap': [3, 4, 'f']} s_common.yamlsave(obj, dirn, 'test.yaml') s_common.yamlmod({'bar': 42}, dirn, 'test.yaml') robj = s_common.yamlload(dirn, 'test.yaml') obj['bar'] = 42 self.eq(obj, robj) # Test yaml helper safety s = '!!python/object/apply:os.system ["pwd"]' with s_common.genfile(dirn, 'explode.yaml') as fd: fd.write(s.encode()) self.raises(yaml.YAMLError, s_common.yamlload, dirn, 'explode.yaml')
def test_common_yaml(self): obj = [ { 'key': 1, 'key2': [1, 2, 3], 'key3': True, 'key4': 'some str', 'key5': { 'oh': 'my', 'we all': 'float down here' }, }, 'duck', False, 'zero', 0.1, ] with self.getTestDir() as dirn: s_common.yamlsave(obj, dirn, 'test.yaml') robj = s_common.yamlload(dirn, 'test.yaml') self.eq(obj, robj) obj = {'foo': 'bar', 'zap': [3, 4, 'f']} s_common.yamlsave(obj, dirn, 'test.yaml') s_common.yamlmod({'bar': 42}, dirn, 'test.yaml') robj = s_common.yamlload(dirn, 'test.yaml') obj['bar'] = 42 self.eq(obj, robj) # Test yaml helper safety s = '!!python/object/apply:os.system ["pwd"]' with s_common.genfile(dirn, 'explode.yaml') as fd: fd.write(s.encode()) self.raises(yaml.YAMLError, s_common.yamlload, dirn, 'explode.yaml')