예제 #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)