def test_valid(self): content = ('# Configuration file example\n' 'key-1 = value-1\n' 'key-2=value-2\n' 'key-3 = value=3') exp = {'key-1': 'value-1', 'key-2': 'value-2', 'key-3': 'value=3'} self.assertEqual(exp, parse_config(content))
def test_invalid(self): content = ('# First line\n' 'invalid-line\n' 'another-invalid-line\n') with self.assertRaises(ValueError) as e: parse_config(content) self.assertEqual('invalid syntax at line 2', str(e.exception))
def test_empty(self): self.assertEqual({}, parse_config(''))
def test_comments(self): content = ('# A comment.\n' '\n' '# Another comment line.\n') self.assertEqual({}, parse_config(''))
'--version', action='store_true', help='output version information and exit') args = ap.parse_args() if args.version: print_version() sys.exit(0) try: content = '' with open(args.config, 'r') as f: content = f.read() cfg = carbonpool.parse_config(content) except OSError as e: fatal('failed to read configuration file: {}'.format(e)) except ValueError as e: fatal('failed to parse configuration file: {}'.format(e)) data_dir = cfg.get('data-dir', '/var/lib/carbon-pool') seg_size = size_to_bytes(cfg.get('segment-size', '16M')) max_segs = int(cfg.get('max-segments', '10')) metrics_addr = (cfg.get('metrics-addr', '127.0.0.1'), int(cfg.get('metrics-port', '2003'))) api_addr = (cfg.get('api-addr', '127.0.0.1'), int(cfg.get('api-port', '2002'))) app = carbonpool.App(data_dir, seg_size, max_segs, metrics_addr, api_addr) app.serve_forever()