From 0b4ed38ca6c50f61636fd98bedf759f2198ac5e4 Mon Sep 17 00:00:00 2001 From: Daniel Bengtsson Date: Tue, 10 Dec 2019 09:52:22 +0100 Subject: Fix the yaml load warning. In the new version of PyYAML the API changed to be more explicit. Now the default value for the Loader is None, see: https://github.com/yaml/pyyaml/blob/5.1/lib3/yaml/__init__.py#L103 The load is unsafe. It's better to use safe_load function. Change-Id: Ia1cd16f2ff970ca220a266c99b6554dd4254ebd9 --- jenkins_jobs/cache.py | 2 +- jenkins_jobs/cli/entry.py | 2 +- tests/cachestorage/test_cachestorage.py | 2 +- tests/cmd/subcommands/test_test.py | 2 +- tests/modules/test_helpers.py | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/jenkins_jobs/cache.py b/jenkins_jobs/cache.py index 01769295..62621b56 100644 --- a/jenkins_jobs/cache.py +++ b/jenkins_jobs/cache.py @@ -59,7 +59,7 @@ class JobCache(object): self.data = {} else: with io.open(self.cachefilename, "r", encoding="utf-8") as yfile: - self.data = yaml.load(yfile) + self.data = yaml.safe_load(yfile) logger.debug("Using cache: '{0}'".format(self.cachefilename)) def _lock(self): diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py index e67ecb24..3aa24fe1 100644 --- a/jenkins_jobs/cli/entry.py +++ b/jenkins_jobs/cli/entry.py @@ -101,7 +101,7 @@ class JenkinsJobs(object): with io.open( self.options.plugins_info_path, "r", encoding="utf-8" ) as yaml_file: - plugins_info = yaml.load(yaml_file) + plugins_info = yaml.safe_load(yaml_file) if not isinstance(plugins_info, list): self.parser.error( "{0} must contain a Yaml list!".format( diff --git a/tests/cachestorage/test_cachestorage.py b/tests/cachestorage/test_cachestorage.py index 34803895..13c7b87a 100644 --- a/tests/cachestorage/test_cachestorage.py +++ b/tests/cachestorage/test_cachestorage.py @@ -40,6 +40,6 @@ class TestCaseJobCache(base.BaseTestCase): """ test_file = os.path.abspath(__file__) with mock.patch("os.path.join", return_value=test_file): - with mock.patch("yaml.load"): + with mock.patch("yaml.safe_load"): with mock.patch("jenkins_jobs.builder.JobCache._lock"): jenkins_jobs.builder.JobCache("dummy").data = None diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index 1e0234a9..ee7d93a7 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -213,7 +213,7 @@ class TestTests(CmdTestsBase): self.execute_jenkins_jobs_with_args(args) with io.open(plugins_info_stub_yaml_file, "r", encoding="utf-8") as yaml_file: - plugins_info_list = yaml.load(yaml_file) + plugins_info_list = yaml.safe_load(yaml_file) registry_mock.assert_called_with(mock.ANY, plugins_info_list) diff --git a/tests/modules/test_helpers.py b/tests/modules/test_helpers.py index f0cebb41..6fc50496 100644 --- a/tests/modules/test_helpers.py +++ b/tests/modules/test_helpers.py @@ -31,7 +31,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test default values default_root = XML.Element("testdefault") - default_data = yaml.load("string: hello") + default_data = yaml.safe_load("string: hello") default_mappings = [("default-string", "defaultString", "default")] convert_mapping_to_xml( @@ -42,7 +42,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test user input user_input_root = XML.Element("testUserInput") - user_input_data = yaml.load("user-input-string: hello") + user_input_data = yaml.safe_load("user-input-string: hello") user_input_mappings = [("user-input-string", "userInputString", "user-input")] convert_mapping_to_xml( @@ -53,7 +53,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test missing required input required_root = XML.Element("testrequired") - required_data = yaml.load("string: hello") + required_data = yaml.safe_load("string: hello") required_mappings = [("required-string", "requiredString", None)] self.assertRaises( @@ -67,7 +67,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test invalid user input for list user_input_root = XML.Element("testUserInput") - user_input_data = yaml.load("user-input-string: bye") + user_input_data = yaml.safe_load("user-input-string: bye") valid_inputs = ["hello"] user_input_mappings = [ ("user-input-string", "userInputString", "user-input", valid_inputs) @@ -83,7 +83,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test invalid user input for dict user_input_root = XML.Element("testUserInput") - user_input_data = yaml.load("user-input-string: later") + user_input_data = yaml.safe_load("user-input-string: later") valid_inputs = {"hello": "world"} user_input_mappings = [ ("user-input-string", "userInputString", "user-input", valid_inputs) @@ -99,7 +99,7 @@ class TestCaseTestHelpers(base.BaseTestCase): # Test invalid key for dict user_input_root = XML.Element("testUserInput") - user_input_data = yaml.load("user-input-string: world") + user_input_data = yaml.safe_load("user-input-string: world") valid_inputs = {"hello": "world"} user_input_mappings = [ ("user-input-string", "userInputString", "user-input", valid_inputs) -- cgit