def test_truediv(self): self.assertEqual(pychirp.Path('/Test/tmp'), pychirp.Path('/Test') / pychirp.Path('tmp')) self.assertEqual(pychirp.Path('/Test/tmp'), pychirp.Path('/Test') / 'tmp') self.assertRaises(pychirp.BadPath, lambda: pychirp.Path('/Test') / pychirp.Path('/tmp'))
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)
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)
def test_bad_path(self): self.assertRaises(pychirp.BadPath, lambda: pychirp.Path('//')) self.assertRaises(pychirp.BadPath, lambda: pychirp.Path('/tmp//')) self.assertRaises(pychirp.BadPath, lambda: pychirp.Path('tmp//')) self.assertRaises(pychirp.BadPath, lambda: pychirp.Path('a//b'))
def test_is_root(self): self.assertTrue(pychirp.Path('/').is_root) self.assertFalse(pychirp.Path('/Test').is_root) self.assertFalse(pychirp.Path('').is_root)
def test_is_absolute(self): self.assertTrue(pychirp.Path('/Test').is_absolute) self.assertFalse(pychirp.Path('Test').is_absolute)
def test_clear(self): path = pychirp.Path('/Test') path.clear() self.assertEqual(pychirp.Path(), path)
def test_eq(self): self.assertEqual(pychirp.Path('/Test/tmp'), pychirp.Path('/Test/tmp')) self.assertEqual(pychirp.Path('/Test/tmp'), '/Test/tmp')
def test_len(self): self.assertEqual(5, len(pychirp.Path('/Test')))
def test_str(self): self.assertEqual('/Test', str(pychirp.Path('/Test')))
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)
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)
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)
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('{'))