Exemplo n.º 1
0
    def test_not_exists_py(self, mock_isfile):
        c = config.Config()
        mock_isfile.return_value = False
        with self.assertRaises(ConfigError) as mock_exc:
            c.from_py_file(self.FILE_PY)

        self.assertEquals(mock_exc.exception.message,
                          'config file does not exist at path "{}"'.format(self.FILE_PY))
Exemplo n.º 2
0
    def test_exists_no_py(self, mock_isfile):
        c = config.Config()
        mock_isfile.return_value = True

        with self.assertRaises(ConfigError) as mock_exc:
            c.from_py_file(self.FILE_NO_PY)

        self.assertEquals(mock_exc.exception.message,
                          'config file is not python file')
Exemplo n.º 3
0
    def test_exists_py_fail(self, mock_isfile):
        c = config.Config()
        mock_isfile.return_value = True

        with self.assertRaises(IOError) as mock_exc:
            c.from_py_file(self.FILE_PY)

        expected_start = 'Unable to load file "'
        self.assertEquals(mock_exc.exception.strerror[:len(expected_start)],
                          expected_start)
Exemplo n.º 4
0
 def test_options(self):
     obj = _LoadObjectForTests()
     c = config.Config(options=obj)
     real_dict = dict(map(lambda k: (k, getattr(obj, k)), LOAD_OBJECT_NOT_CALLABLE_KEYS))
     self.assertDictEqual(dict(c), real_dict)
Exemplo n.º 5
0
 def test_no_options(self):
     c = config.Config(options=None)
     self.assertListEqual(dict(c).keys(), [])
Exemplo n.º 6
0
 def test_path_no(self, mock_from_py_file, mock_from_module):
     c = config.Config(path=self.PATH_NO)
     mock_from_module.assert_not_called()
     mock_from_py_file.assert_not_called()
Exemplo n.º 7
0
 def test_path_py(self, mock_from_py_file, mock_from_module):
     c = config.Config(path=self.PATH_PY)
     mock_from_module.assert_not_called()
     mock_from_py_file.assert_called_once_with(self.PATH_PY)
Exemplo n.º 8
0
 def test_exists_py(self):
     c = config.Config()
     c.from_py_file(self.FILE_PY_EXISTS)
     self.assertItemsEqual(dict(c).keys(), FIXTURE_TEST_KEYS)
Exemplo n.º 9
0
 def test_exists(self):
     c = config.Config()
     c.from_module(self.TEST_LIB)
     self.assertItemsEqual(dict(c).keys(), FIXTURE_TEST_KEYS)
Exemplo n.º 10
0
    def test_not_exists(self):
        c = config.Config()

        with self.assertRaises(ImportError):
            c.from_module(self.NON_EXIST)