Пример #1
0
    def test_save(self):
        config = yact.from_file(self.SAMPLE_CFG)

        new_filename = self.SAMPLE_CFG.replace('conf', 'yaml')
        config.filename = new_filename
        config.save()

        new_config = yact.from_file(new_filename)
        self.assertEqual(config._data, new_config._data)
Пример #2
0
    def test_save(self):
        config = yact.from_file(self.sample_cfg)

        new_filename = self.sample_cfg.replace('testing', 'yaml')
        config.filename = new_filename
        config.save()

        new_config = yact.from_file(new_filename)
        self.assertEqual(config._data, new_config._data)
Пример #3
0
    def test_save(self):
        config = yact.from_file(self.SAMPLE_CFG)

        new_filename = self.SAMPLE_CFG.replace('conf', 'yaml')
        config.filename = new_filename
        config.save()

        new_config = yact.from_file(new_filename)
        self.assertEqual(config._data, new_config._data)
Пример #4
0
    def test_save(self):
        config = yact.from_file(self.sample_cfg)

        new_filename = self.sample_cfg.replace('testing', 'yaml')
        config.filename = new_filename
        config.save()

        new_config = yact.from_file(new_filename)
        self.assertEqual(config._data, new_config._data)
Пример #5
0
 def test_from_file(self):
     """
     Check instantiation from path, filename
     """
     test_files = ['test.conf', os.path.join(os.path.curdir, 'test.conf')]
     for tf in test_files:
         config = yact.from_file(tf, 'tests')
         self.assertIsInstance(config, yact.Config)
     with self.assertRaises(yact.MissingConfig):
         config = yact.from_file('bogusfile')
Пример #6
0
 def test_from_file(self):
     """
     Check instantiation from path, filename
     """
     test_files = ['test.conf', os.path.join(os.path.curdir, 'test.conf')]
     for tf in test_files:
         config = yact.from_file(tf, 'tests')
         self.assertIsInstance(config, yact.Config)
     with self.assertRaises(yact.MissingConfig):
         config = yact.from_file('bogusfile')
Пример #7
0
 def test_autoreload(self):
     config = yact.from_file(self.sample_cfg, auto_reload=True)
     oldmd5 = config.md5sum
     with open(config.filename, 'a') as f:
         f.write('modified: True')
     sleep(6)
     # By now yact should have refreshed, let's verify
     self.assertNotEqual(oldmd5, config.md5sum)
Пример #8
0
 def test_autoreload(self):
     config = yact.from_file(self.sample_cfg, auto_reload=True)
     oldmd5 = config.md5sum
     with open(config.filename, 'a') as f:
         f.write('modified: True')
     sleep(6)
     # By now yact should have refreshed, let's verify
     self.assertNotEqual(oldmd5, config.md5sum)
Пример #9
0
 def test_repr(self):
     """
     Does repr do what I expect?
     """
     config = yact.from_file(self.sample_cfg)
     self.assertEqual(
         str(config), '{}({})'.format(config.__class__.__name__,
                                      self.sample_cfg))
Пример #10
0
 def test_remove(self):
     config = yact.from_file(self.SAMPLE_CFG)
     config.set('temporary', True)
     self.assertEqual(config['temporary'], True)
     config.remove('temporary')
     with self.assertRaises(KeyError):
         config['temporary']
     config.remove('temporary')  # Shouldn't error out
Пример #11
0
 def test_repr(self):
     """
     Does repr do what I expect?
     """
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(
         str(config), '{0}({1})'.format(config.__class__.__name__,
                                        self.SAMPLE_CFG))
Пример #12
0
 def test_remove(self):
     config = yact.from_file(self.SAMPLE_CFG)
     config.set('temporary', True)
     self.assertEqual(config['temporary'], True)
     config.remove('temporary')
     with self.assertRaises(KeyError):
         config['temporary']
     config.remove('temporary') # Shouldn't error out
Пример #13
0
 def test_getitem(self):
     config = yact.from_file(self.sample_cfg)  # Known entries
     self.assertEqual(config['environment'], 'development')
     self.assertEqual(config['db.host'], 'localhost')
     self.assertEqual(config['db']['host'], 'localhost')
     with self.assertRaises(KeyError):
         config['db.missingentry']
     with self.assertRaises(KeyError):
         config['missingentry']
Пример #14
0
 def test_getitem(self):
     config = yact.from_file(self.sample_cfg) # Known entries
     self.assertEqual(config['environment'], 'development')
     self.assertEqual(config['db.host'], 'localhost')
     self.assertEqual(config['db']['host'], 'localhost')
     with self.assertRaises(KeyError):
         config['db.missingentry']
     with self.assertRaises(KeyError):
         config['missingentry']
Пример #15
0
 def test_set(self):
     config = yact.from_file(self.SAMPLE_CFG)
     config.set('set', 'go')
     self.assertEqual(config['set'], 'go')
     config.set('this.must.nest', True)
     config.set('this.must.be.nested', True)
     self.assertEqual(config['this']['must']['nest'], True)
     self.assertEqual(config['this']['must']['be']['nested'], True)
     config.set('this.is.a.list', [1, 2, 3])
     with self.assertRaises(yact.ConfigEditFailed):
         config.set('this.is.a.list.not', False)  # Raise expection
Пример #16
0
 def test_set(self):
     config = yact.from_file(self.sample_cfg)
     config.set('ham', 'spam')
     self.assertEqual(config['ham'], 'spam')
     config.set('spam.spam.spam', True)
     config.set('spam.with.ham.and.eggs', True)
     self.assertEqual(config['spam']['spam']['spam'], True)
     self.assertEqual(config['spam']['with']['ham']['and']['eggs'], True)
     config.set('menu', ['spam', 'spam', 'spam', 'spam'])
     with self.assertRaises(yact.ConfigEditFailed):
         config.set('menu.breakfast', False)  # Raise expection
Пример #17
0
 def test_set(self):
     config = yact.from_file(self.sample_cfg)
     config.set('ham', 'spam')
     self.assertEqual(config['ham'], 'spam')
     config.set('spam.spam.spam', True)
     config.set('spam.with.ham.and.eggs', True)
     self.assertEqual(config['spam']['spam']['spam'], True)
     self.assertEqual(config['spam']['with']['ham']['and']['eggs'], True)
     config.set('menu', ['spam', 'spam', 'spam', 'spam'])
     with self.assertRaises(yact.ConfigEditFailed):
         config.set('menu.breakfast', False)  # Raise expection
Пример #18
0
    def test_refresh(self):
        config = yact.from_file(self.sample_cfg)
        loaded = config.ts_refreshed_utc
        sleep(2)
        config.refresh()
        refreshed = config.ts_refreshed_utc
        self.assertGreaterEqual((refreshed - loaded).total_seconds(), 2)

        config.filename = 'nonexistent'
        with self.assertRaises(yact.InvalidConfigFile):
            config.refresh()
Пример #19
0
    def test_refresh(self):
        config = yact.from_file(self.sample_cfg)
        loaded = config.ts_refreshed_utc
        sleep(2)
        config.refresh()
        refreshed = config.ts_refreshed_utc
        self.assertGreaterEqual((refreshed - loaded).total_seconds(), 2)

        config.filename = 'nonexistent'
        with self.assertRaises(yact.InvalidConfigFile):
            config.refresh()
Пример #20
0
 def test_set(self):
     config = yact.from_file(self.SAMPLE_CFG)
     config.set('set', 'go')
     self.assertEqual(config['set'], 'go')
     config.set('this.must.nest', True)
     config.set('this.must.be.nested', True)
     self.assertEqual(config['this']['must']['nest'], True)
     self.assertEqual(config['this']['must']['be']['nested'], True)
     config.set('this.is.a.list', [1,2,3])
     with self.assertRaises(yact.ConfigEditFailed):
         config.set('this.is.a.list.not', False)  # Raise expection
Пример #21
0
 def test_remove(self):
     config = yact.from_file(self.sample_cfg)
     config.set('temporary', True)
     self.assertEqual(config['temporary'], True)
     config.remove('temporary')
     with self.assertRaises(KeyError):
         config['temporary']
     config.remove('temporary') # Shouldn't error out
     config.set('foo.bar.baz', True)
     config.set('foo.bar.bat', True)
     config.remove('foo.bar')
     config.remove('foo.bar.baz')
     config['foo']
     config.remove('foo')
Пример #22
0
 def test_remove(self):
     config = yact.from_file(self.sample_cfg)
     config.set('temporary', True)
     self.assertEqual(config['temporary'], True)
     config.remove('temporary')
     with self.assertRaises(KeyError):
         config['temporary']
     config.remove('temporary')  # Shouldn't error out
     config.set('foo.bar.baz', True)
     config.set('foo.bar.bat', True)
     config.remove('foo.bar')
     config.remove('foo.bar.baz')
     config['foo']
     config.remove('foo')
Пример #23
0
    def test_md5sum(self):
        # First, let's test the fresh config file
        with open(self.sample_cfg, 'r') as f:
            md5 = hashlib.md5(f.read().encode('utf-8')).hexdigest()
        config = yact.from_file(self.sample_cfg)
        # If all is good, the raw md5sum and the one provided by yact will match
        self.assertEqual(config.md5sum, md5)

        # This is a bit tricky, we copy a file every time self.sample_cfg
        # is accessed so we need to know the current filename config uses
        config.set('thischanged', True)
        with open(config.filename, 'r') as f:
            newmd5 = hashlib.md5(f.read().encode('utf-8')).hexdigest()
        self.assertEqual(newmd5, config.md5sum)
        self.assertNotEqual(newmd5, md5)
Пример #24
0
    def test_md5sum(self):
        # First, let's test the fresh config file
        with open(self.sample_cfg, 'r') as f:
            md5 = hashlib.md5(f.read().encode('utf-8')).hexdigest()
        config = yact.from_file(self.sample_cfg)
        # If all is good, the raw md5sum and the one provided by yact will match
        self.assertEqual(config.md5sum, md5)

        # This is a bit tricky, we copy a file every time self.sample_cfg
        # is accessed so we need to know the current filename config uses
        config.set('thischanged', True)
        with open(config.filename, 'r') as f:
            newmd5 = hashlib.md5(f.read().encode('utf-8')).hexdigest()
        self.assertEqual(newmd5, config.md5sum)
        self.assertNotEqual(newmd5, md5)
Пример #25
0
 def test_sections(self):
     config = yact.from_file(self.sample_cfg)
     self.assertIsInstance(config.sections, list)
Пример #26
0
 def test_config_file_changed(self):
     config = yact.from_file(self.sample_cfg)
     with open(config.filename, 'a') as f:
         f.write('modified: True')
     self.assertTrue(config.config_file_changed)
Пример #27
0
 def test_get(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(config.get('ham.eggs.bar'), 1)
     self.assertEqual(config.get('haml.eggs.spam'), None)
Пример #28
0
 def test_getitem(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(config['ham']['eggs']['bar'], 1)
     self.assertEqual(config['ham.eggs.bar'], 1)
     with self.assertRaises(KeyError):
         config['nonexistent']
Пример #29
0
 def test_get(self):
     config = yact.from_file(self.sample_cfg)  # Known entries
     self.assertEqual(config.get('environment'), 'development')
     self.assertEqual(config.get('db.missingentry'), None)
Пример #30
0
 def test_setitem(self):
     config = yact.from_file(self.sample_cfg)
     config['ham'] = 'spam'
     self.assertEqual(config['ham'], 'spam')
     config['spam.ham'] = 'spam'
     self.assertEqual(config['spam']['ham'], 'spam')
Пример #31
0
 def test_repr(self):
     """
     Does repr do what I expect?
     """
     config = yact.from_file(self.sample_cfg)
     self.assertEqual(str(config), '{}({})'.format(config.__class__.__name__, self.sample_cfg))
Пример #32
0
 def test_repr(self):
     """
     Does repr do what I expect?
     """
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(str(config), '{0}({1})'.format(config.__class__.__name__, self.SAMPLE_CFG))
Пример #33
0
 def test_unsafe_load(self):
     config = yact.from_file(self.SAMPLE_CFG, unsafe=True)
Пример #34
0
 def test_setitem(self):
     config = yact.from_file(self.sample_cfg)
     config['ham'] = 'spam'
     self.assertEqual(config['ham'], 'spam')
     config['spam.ham'] = 'spam'
     self.assertEqual(config['spam']['ham'], 'spam')
Пример #35
0
 def test_get(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(config.get('ham.eggs.bar'), 1)
     self.assertEqual(config.get('haml.eggs.spam'), None)
Пример #36
0
 def test_unsafe_load(self):
     config = yact.from_file(self.SAMPLE_CFG, unsafe=True)
Пример #37
0
 def test_getitem(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertEqual(config['ham']['eggs']['bar'], 1)
     self.assertEqual(config['ham.eggs.bar'], 1)
     with self.assertRaises(KeyError):
         config['nonexistent']
Пример #38
0
 def test_config_file_changed(self):
     config = yact.from_file(self.sample_cfg)
     with open(config.filename, 'a') as f:
         f.write('modified: True')
     self.assertTrue(config.config_file_changed)
Пример #39
0
 def test_unsafe_load(self):
     config = yact.from_file(self.sample_cfg, unsafe=True)
Пример #40
0
 def test_sections(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertIsInstance(config.sections, list)
Пример #41
0
 def test_get(self):
     config = yact.from_file(self.sample_cfg)  # Known entries
     self.assertEqual(config.get('environment'), 'development')
     self.assertEqual(config.get('db.missingentry'), None)
Пример #42
0
 def test_sections(self):
     config = yact.from_file(self.sample_cfg)
     self.assertIsInstance(config.sections, list)
Пример #43
0
 def from_yaml(self, config_file, directory=None):
     config = yact.from_file(config_file, directory=directory)
     for section in config.sections:
         self[section.upper()] = config[section]
Пример #44
0
 def test_sections(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertIsInstance(config.sections, list)
Пример #45
0
 def test_unsafe_load(self):
     config = yact.from_file(self.sample_cfg, unsafe=True)
Пример #46
0
 def setup_config(self):
     filename = "coppermind.conf"
     config = yact.from_file(filename)