def test_command_line_override(self): cfg = yogi.Configuration(['test.py', make_config_path('a'), '--connection_target=my-host:1234', '--connection_timeout=0.555', '-i', 'Dude', '--location=/Home']) self.assertEqual(yogi.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)
def test_json_overrides(self): cfg = yogi.Configuration(['test.py', make_config_path('a'), '--json={"my-age": 42}', '-j', '{"my-id": 55}', '--json={"yogi": {"location": "/Somewhere"}}', '--location=/Home']) self.assertEqual(42, cfg.config['my-age']) self.assertEqual(55, cfg.config['my-id']) self.assertEqual(yogi.Path('/Home'), cfg.location)
def test_config_file_priority(self): cfg = yogi.Configuration(['test.py', make_config_path('a'), make_config_path('b')]) self.assertEqual(yogi.Path('/Pudding'), cfg.location) self.assertIsNone(cfg.connection_target)
def test_update(self): cfg = yogi.Configuration(['test.py', make_config_path('a')]) cfg.update('{"yogi": {"location": "/Home"}}') self.assertEqual(yogi.Path("/Home"), cfg.location) self.assertRaises(yogi.BadConfiguration, lambda: cfg.update('{'))
def test_config_file(self): cfg = yogi.Configuration(['test.py', make_config_path('a')]) self.assertEqual(yogi.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)
def test_is_root(self): self.assertTrue(yogi.Path('/').is_root) self.assertFalse(yogi.Path('/Test').is_root) self.assertFalse(yogi.Path('').is_root)
def test_empty_configuration(self): cfg = yogi.Configuration(argv=None) self.assertEqual(yogi.Path('/'), cfg.location) self.assertIsNone(cfg.connection_target) self.assertIsNone(cfg.connection_timeout) self.assertIsNone(cfg.connection_identification)
def test_clear(self): path = yogi.Path('/Test') path.clear() self.assertEqual(yogi.Path(), path)
def test_is_absolute(self): self.assertTrue(yogi.Path('/Test').is_absolute) self.assertFalse(yogi.Path('Test').is_absolute)
def test_truediv(self): self.assertEqual(yogi.Path('/Test/tmp'), yogi.Path('/Test') / yogi.Path('tmp')) self.assertEqual(yogi.Path('/Test/tmp'), yogi.Path('/Test') / 'tmp') self.assertRaises(yogi.BadPath, lambda: yogi.Path('/Test') / yogi.Path('/tmp'))
def test_eq(self): self.assertEqual(yogi.Path('/Test/tmp'), yogi.Path('/Test/tmp')) self.assertEqual(yogi.Path('/Test/tmp'), '/Test/tmp')
def test_len(self): self.assertEqual(5, len(yogi.Path('/Test')))
def test_str(self): self.assertEqual('/Test', str(yogi.Path('/Test')))
def test_bad_path(self): self.assertRaises(yogi.BadPath, lambda: yogi.Path('//')) self.assertRaises(yogi.BadPath, lambda: yogi.Path('/tmp//')) self.assertRaises(yogi.BadPath, lambda: yogi.Path('tmp//')) self.assertRaises(yogi.BadPath, lambda: yogi.Path('a//b'))