示例#1
0
 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'))
示例#2
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)
示例#3
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)
示例#4
0
 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'))
示例#5
0
 def test_is_root(self):
     self.assertTrue(pychirp.Path('/').is_root)
     self.assertFalse(pychirp.Path('/Test').is_root)
     self.assertFalse(pychirp.Path('').is_root)
示例#6
0
 def test_is_absolute(self):
     self.assertTrue(pychirp.Path('/Test').is_absolute)
     self.assertFalse(pychirp.Path('Test').is_absolute)
示例#7
0
 def test_clear(self):
     path = pychirp.Path('/Test')
     path.clear()
     self.assertEqual(pychirp.Path(), path)
示例#8
0
 def test_eq(self):
     self.assertEqual(pychirp.Path('/Test/tmp'), pychirp.Path('/Test/tmp'))
     self.assertEqual(pychirp.Path('/Test/tmp'), '/Test/tmp')
示例#9
0
 def test_len(self):
     self.assertEqual(5, len(pychirp.Path('/Test')))
示例#10
0
 def test_str(self):
     self.assertEqual('/Test', str(pychirp.Path('/Test')))
示例#11
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)
示例#12
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)
示例#13
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)
示例#14
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('{'))