示例#1
0
 def test_json_overrides(self):
     cfg = pychirp.Configuration([
         'test.py', 'config_a.json', '--json={"my-age": 42}', '-j',
         '{"my-id": 55}', '--json={"chirp": {"location": "/Somewhere"}}',
         '--location=/Home'
     ])
     self.assertEqual(42, cfg.config['my-age'])
     self.assertEqual(55, cfg.config['my-id'])
     self.assertEqual(pychirp.Path('/Home'), cfg.location)
示例#2
0
 def test_command_line_override(self):
     cfg = pychirp.Configuration([
         'test.py', 'config_a.json', '--connection_target=my-host:1234',
         '--connection_timeout=0.555', '-i', 'Dude', '--location=/Home'
     ])
     self.assertEqual(pychirp.Path('/Home'), cfg.location)
     self.assertEqual('my-host:1234', cfg.connection_target)
     self.assertAlmostEqual(0.555, cfg.connection_timeout)
     self.assertEqual('Dude', cfg.connection_identification)
示例#3
0
 def test_str(self):
     cfg = pychirp.Configuration(['test.py', 'config_a.json'])
     self.assertRegex(str(cfg), r'.*localhost:12345.*')
示例#4
0
 def test_bad_command_line(self):
     self.assertRaises(
         pychirp.BadCommandLine,
         lambda: pychirp.Configuration(['test.py', '--hey-dude']))
示例#5
0
 def test_bad_configuration_file(self):
     self.assertRaises(
         pychirp.BadConfiguration,
         lambda: pychirp.Configuration(['test.py', 'config_c.json']))
示例#6
0
 def test_empty_configuration(self):
     cfg = pychirp.Configuration(argv=None)
     self.assertEquals(pychirp.Path(), cfg.location)
     self.assertIsNone(cfg.connection_target)
     self.assertIsNone(cfg.connection_timeout)
     self.assertIsNone(cfg.connection_identification)
示例#7
0
 def test_config_file_priority(self):
     cfg = pychirp.Configuration(
         ['test.py', 'config_a.json', 'config_b.json'])
     self.assertEqual(pychirp.Path('/Pudding'), cfg.location)
     self.assertIsNone(cfg.connection_target)
示例#8
0
 def test_config_file(self):
     cfg = pychirp.Configuration(['test.py', 'config_a.json'])
     self.assertEqual(pychirp.Path('/Test'), cfg.location)
     self.assertEqual('localhost:12345', cfg.connection_target)
     self.assertAlmostEqual(1.234, cfg.connection_timeout)
     self.assertEqual('Hello World', cfg.connection_identification)
示例#9
0
 def test_update(self):
     cfg = pychirp.Configuration(['test.py', 'config_a.json'])
     cfg.update('{"chirp": {"location": "/Home"}}')
     self.assertEqual(pychirp.Path("/Home"), cfg.location)
     self.assertRaises(pychirp.BadConfiguration, lambda: cfg.update('{'))