Skip to content

Commit

Permalink
Merge pull request #236 from masayukig/use-yaml-safe-load
Browse files Browse the repository at this point in the history
Use yaml.safe_load instead of yaml.load
  • Loading branch information
mtreinish committed Mar 16, 2019
2 parents 6ddb750 + f0c8c11 commit c65692c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion stestr/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate_worker_partitions(ids, worker_path, repository=None,
:returns: A list where each element is a distinct subset of test_ids.
"""
with open(worker_path, 'r') as worker_file:
workers_desc = yaml.load(worker_file.read())
workers_desc = yaml.safe_load(worker_file.read())
worker_groups = []
for worker in workers_desc:
if isinstance(worker, dict) and 'worker' in worker.keys():
Expand Down
12 changes: 6 additions & 6 deletions stestr/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_generate_worker_partitions(self):
{'worker': ['test_']},
{'worker': ['test']},
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
groups = scheduler.generate_worker_partitions(test_ids, 'fakepath')
expected_grouping = [
['test_a', 'test_b'],
Expand All @@ -139,7 +139,7 @@ def test_generate_worker_partitions_group_without_list(self):
{'worker': ['test_']},
{'worker': 'test'},
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
self.assertRaises(TypeError, scheduler.generate_worker_partitions,
test_ids, 'fakepath')

Expand All @@ -150,7 +150,7 @@ def test_generate_worker_partitions_no_worker_tag(self):
{'worker-foo': ['test_']},
{'worker': ['test']},
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
self.assertRaises(TypeError, scheduler.generate_worker_partitions,
test_ids, 'fakepath')

Expand All @@ -162,7 +162,7 @@ def test_generate_worker_partitions_group_without_match(self):
{'worker': ['test']},
{'worker': ['foo']}
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
groups = scheduler.generate_worker_partitions(test_ids, 'fakepath')
expected_grouping = [
['test_a', 'test_b'],
Expand All @@ -178,7 +178,7 @@ def test_generate_worker_partitions_with_count(self):
{'worker': ['test']},
{'worker': ['a_thing'], 'concurrency': 2},
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
groups = scheduler.generate_worker_partitions(test_ids, 'fakepath')
expected_grouping = [
['test_a', 'test_b'],
Expand All @@ -196,7 +196,7 @@ def test_generate_worker_partitions_with_count_1(self):
{'worker': ['test_']},
{'worker': ['test'], 'count': 1},
]
with mock.patch('yaml.load', return_value=fake_worker_yaml):
with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):
groups = scheduler.generate_worker_partitions(test_ids, 'fakepath')
expected_grouping = [
['test_a', 'test_b'],
Expand Down
8 changes: 5 additions & 3 deletions stestr/tests/test_user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ def fake_isfile(path):
user_config.get_user_config()
user_mock.assert_called_once_with(self.home_path)

@mock.patch('yaml.load', return_value={})
@mock.patch('yaml.safe_load', return_value={})
@mock.patch('six.moves.builtins.open', mock.mock_open())
def test_user_config_empty_schema(self, yaml_mock):
user_conf = user_config.UserConfig('/path')
self.assertEqual({}, user_conf.config)

@mock.patch('yaml.load', return_value={'init': {'subunit-trace': True}})
@mock.patch('yaml.safe_load',
return_value={'init': {'subunit-trace': True}})
@mock.patch('sys.exit')
@mock.patch('six.moves.builtins.open', mock.mock_open())
def test_user_config_invalid_command(self, exit_mock, yaml_mock):
Expand All @@ -111,7 +112,8 @@ def test_user_config_invalid_command(self, exit_mock, yaml_mock):
"extra keys not allowed @ data['init']")
exit_mock.assert_called_once_with(error_string)

@mock.patch('yaml.load', return_value={'run': {'subunit-trace': True}})
@mock.patch('yaml.safe_load',
return_value={'run': {'subunit-trace': True}})
@mock.patch('sys.exit')
@mock.patch('six.moves.builtins.open', mock.mock_open())
def test_user_config_invalid_option(self, exit_mock, yaml_mock):
Expand Down
2 changes: 1 addition & 1 deletion stestr/user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, path):
}
})
with open(path, 'r') as fd:
self.config = yaml.load(fd.read())
self.config = yaml.safe_load(fd.read())
if self.config is None:
self.config = {}
try:
Expand Down

0 comments on commit c65692c

Please sign in to comment.