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))
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')
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)
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)
def test_no_options(self): c = config.Config(options=None) self.assertListEqual(dict(c).keys(), [])
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()
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)
def test_exists_py(self): c = config.Config() c.from_py_file(self.FILE_PY_EXISTS) self.assertItemsEqual(dict(c).keys(), FIXTURE_TEST_KEYS)
def test_exists(self): c = config.Config() c.from_module(self.TEST_LIB) self.assertItemsEqual(dict(c).keys(), FIXTURE_TEST_KEYS)
def test_not_exists(self): c = config.Config() with self.assertRaises(ImportError): c.from_module(self.NON_EXIST)