Skip to content

Commit

Permalink
Merge pull request #22 from garymacindoe/master
Browse files Browse the repository at this point in the history
Add ability to parse dicts of dicts in JSON to pass kwargs.
  • Loading branch information
txels committed Sep 23, 2015
2 parents 7ca1ad2 + 9e088fc commit 7ed3a52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ddt.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ def _raise_ve(*args): # pylint: disable-msg=W0613
elif isinstance(data, list):
value = elem
test_name = mk_test_name(name, value, i)
add_test(cls, test_name, func, value)
if isinstance(value, dict):
add_test(cls, test_name, func, **value)
else:
add_test(cls, test_name, func, value)


def ddt(cls):
Expand Down
22 changes: 22 additions & 0 deletions test/test_data_dict_dict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"positive_integer_range": {
"start": 0,
"end": 2,
"value": 1
},
"negative_integer_range": {
"start": -2,
"end": 0,
"value": -1
},
"positive_real_range": {
"start": 0.0,
"end": 1.0,
"value": 0.5
},
"negative_real_range": {
"start": -1.0,
"end": 0.0,
"value": -0.5
}
}
6 changes: 6 additions & 0 deletions test/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def test_greater(self, value):
a, b = value
self.assertGreater(a, b)

@file_data("test_data_dict_dict.json")
def test_file_data_dict_dict(self, start, end, value):
self.assertLess(start, end)
self.assertLess(value, end)
self.assertGreater(value, start)

@file_data('test_data_dict.json')
def test_file_data_dict(self, value):
self.assertTrue(has_three_elements(value))
Expand Down

0 comments on commit 7ed3a52

Please sign in to comment.