Пример #1
0
 def test_options_dict_like_object(self):
     """Pass a dict-like object and make sure we get valid options back"""
     mock_dict = MockDict() 
     opt = DictMatch(config=mock_dict, mapped_defaults=self.mapped_defaults)
     actual = opt.options()
     expected = self.mapped_defaults
     self.assertEqual(actual, expected) 
Пример #2
0
 def test_options_from_file_empty_defaults(self):
     """Just one default should not overwrite other config values"""
     opt = DictMatch('/tmp/guachi/conf_eight.ini', self.mapped_options, {})
     actual = opt.options()
     expected = {
         'db_host': 'example.com',
         'db_port': '',
         'web_host': '',
         'web_port': '',
         }
     self.assertEqual(actual, expected) 
Пример #3
0
    def test_options_key_error_passes(self):
        """When options are missing options() passes on the KeyError"""
        opt = DictMatch('/tmp/guachi/conf_seven.ini', self.mapped_options, self.mapped_defaults)
        actual = opt.options()
        expected = {
            'db_host': 'remote.example.com',
            'db_port': '0',
            'web_host': 'localhost',
            'web_port': '8080',
            }

        self.assertEqual(actual, expected) 
Пример #4
0
    def test_options_from_file_one_option(self):
        """A conf file with one value should get values filled in"""
        opt = DictMatch('/tmp/guachi/conf_eight.ini', self.mapped_options, self.mapped_defaults)
        actual = opt.options()
        expected = {
            'db_host': 'example.com',
            'db_port': 27017,
            'web_host': 'localhost',
            'web_port': '8080',
            }

        self.assertEqual(actual, expected) 
Пример #5
0
    def set_config(self, configuration=None):
        """Accepts a dictionary or a file to set persistent configurations"""
        mapped_ini = self.get_ini_options()
        mapped_defaults = self.get_default_options()

        # First make sure that whatever we get, gets translated
        # into a dictionary 
        dict_match = DictMatch(configuration, mapped_ini, mapped_defaults)
        dict_config = dict_match.options()
        if len(dict_config.items()) > 0:
            db = dbdict(self.path)
            for key, value in dict_config.items():
                db[key] = value 
Пример #6
0
 def test_options_from_file_empty_options(self):
     """A conf file with empty values should get values filled in"""
     opt = DictMatch('/tmp/guachi/conf_nine.ini', self.mapped_options, self.mapped_defaults)
     actual = opt.options()
     expected = self.mapped_defaults
     self.assertEqual(actual, expected) 
Пример #7
0
 def test_options_from_dict(self):
     """Pass a dict with no values and get defaults back"""
     opt = DictMatch(config={}, mapped_defaults=self.mapped_defaults)
     actual = opt.options()
     expected = self.mapped_defaults
     self.assertEqual(actual, expected) 
Пример #8
0
 def test_options_config_dict_empty_defaults(self):
     """A dict config and no defaults should return an empty dict"""
     opts = DictMatch(config={})  
     actual = opts.options()
     expected = {}
     self.assertEqual(actual, expected)
Пример #9
0
 def test_options_config_invalid_empty_defaults(self):
     """Invalid config file and no defaults should return an empty dict"""
     opts = DictMatch(config='/path/to/invalid/file')
     actual = opts.options()
     expected = {}
     self.assertEqual(actual, expected)