Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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')
Beispiel #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')
Beispiel #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)
Beispiel #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)
Beispiel #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))
Beispiel #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
Beispiel #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))
Beispiel #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
Beispiel #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']
Beispiel #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']
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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()
Beispiel #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()
Beispiel #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
Beispiel #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')
Beispiel #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')
Beispiel #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)
Beispiel #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)
Beispiel #25
0
 def test_sections(self):
     config = yact.from_file(self.sample_cfg)
     self.assertIsInstance(config.sections, list)
Beispiel #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)
Beispiel #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)
Beispiel #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']
Beispiel #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)
Beispiel #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')
Beispiel #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))
Beispiel #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))
Beispiel #33
0
 def test_unsafe_load(self):
     config = yact.from_file(self.SAMPLE_CFG, unsafe=True)
Beispiel #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')
Beispiel #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)
Beispiel #36
0
 def test_unsafe_load(self):
     config = yact.from_file(self.SAMPLE_CFG, unsafe=True)
Beispiel #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']
Beispiel #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)
Beispiel #39
0
 def test_unsafe_load(self):
     config = yact.from_file(self.sample_cfg, unsafe=True)
Beispiel #40
0
 def test_sections(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertIsInstance(config.sections, list)
Beispiel #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)
Beispiel #42
0
 def test_sections(self):
     config = yact.from_file(self.sample_cfg)
     self.assertIsInstance(config.sections, list)
Beispiel #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]
Beispiel #44
0
 def test_sections(self):
     config = yact.from_file(self.SAMPLE_CFG)
     self.assertIsInstance(config.sections, list)
Beispiel #45
0
 def test_unsafe_load(self):
     config = yact.from_file(self.sample_cfg, unsafe=True)
Beispiel #46
0
 def setup_config(self):
     filename = "coppermind.conf"
     config = yact.from_file(filename)