-
-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change method of reporting target data #4593
Changes from 1 commit
ebd57f5
0bf7b14
e704bdf
d18a523
084422b
a05387b
437dc00
ec0e7aa
2d608e2
8ec2dfd
5566ad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,14 +429,16 @@ def _create_dict_with_nested_keys_and_val(cls, keys, value): | |
:param primitive value: The value of the information being stored. | ||
:return: dict of nested keys leading to the value. | ||
""" | ||
current_index = len(keys) - 1 | ||
|
||
if len(keys) > 1: | ||
new_val = {keys[current_index]: value} | ||
new_keys = keys[:current_index] | ||
new_keys = keys[:-1] | ||
new_val = {keys[-1]: value} | ||
return cls._create_dict_with_nested_keys_and_val(new_keys, new_val) | ||
elif len(keys) == 1: | ||
return {keys[current_index]: value} | ||
return {keys[0]: value} | ||
else: | ||
raise ValueError('Keys must contain at least one key.') | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit unorthodox to have a function (especially a recursive function) that returns a value but that doesn't handle every possible branch. In this case, |
||
@classmethod | ||
def _merge_list_of_keys_into_dict(cls, data, keys, value, index=0): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,10 +61,8 @@ def test_write_stats_to_json_file(self): | |
def test_create_dict_with_nested_keys_and_val(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comprehensive tests! |
||
keys = [] | ||
|
||
self.assertEquals( | ||
RunTracker._create_dict_with_nested_keys_and_val(keys, 'something'), | ||
None | ||
) | ||
with self.assertRaises(ValueError): | ||
RunTracker._create_dict_with_nested_keys_and_val(keys, 'something') | ||
|
||
keys += ['one'] | ||
self.assertEquals( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really succinct and neat now. Sometimes Python has its moments...