From 0e278b604ba7a9981f9a11fcd02f9bbafca79fb5 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Tue, 2 Feb 2021 18:05:46 -0500 Subject: [PATCH] Add test coverage for .from_yaml() method --- .../providers/test_configuration_py2_py3.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/providers/test_configuration_py2_py3.py b/tests/unit/providers/test_configuration_py2_py3.py index 7397d60c..a0d267ae 100644 --- a/tests/unit/providers/test_configuration_py2_py3.py +++ b/tests/unit/providers/test_configuration_py2_py3.py @@ -647,6 +647,27 @@ class ConfigFromYamlTests(unittest.TestCase): '"pip install dependency-injector[yaml]"', ) + def test_option_no_yaml_installed(self): + @contextlib.contextmanager + def no_yaml_module(): + yaml = providers.yaml + providers.yaml = None + + yield + + providers.yaml = yaml + + with no_yaml_module(): + with self.assertRaises(errors.Error) as error: + self.config.option.from_yaml(self.config_file_1) + + self.assertEqual( + error.exception.args[0], + 'Unable to load yaml configuration - PyYAML is not installed. ' + 'Install PyYAML or install Dependency Injector with yaml extras: ' + '"pip install dependency-injector[yaml]"', + ) + class ConfigFromYamlWithEnvInterpolationTests(unittest.TestCase):