-
Notifications
You must be signed in to change notification settings - Fork 112
Cartesian products #25
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
Changes from all commits
f174fc0
eecee22
a6e0fc2
a66d954
7b09306
b4001ff
9e75754
9b44abb
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 |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
|
|
||
| import six | ||
|
|
||
| from ddt import ddt, data, file_data, is_hash_randomized | ||
| from ddt import ( | ||
| ddt, data, file_data, is_hash_randomized, DataValues, FileValues | ||
| ) | ||
| from nose.tools import assert_equal, assert_is_not_none, assert_raises | ||
|
|
||
|
|
||
|
|
@@ -71,7 +73,31 @@ def hello(): | |
| extra_attrs = dh_keys - keys | ||
| assert_equal(len(extra_attrs), 1) | ||
| extra_attr = extra_attrs.pop() | ||
| assert_equal(getattr(data_hello, extra_attr), (1, 2)) | ||
| assert_equal(getattr(data_hello, extra_attr), [DataValues((1, 2))]) | ||
|
|
||
|
|
||
| def test_multiple_data_decorators(): | ||
| """ | ||
| Test the ``data`` method decorator with multiple applications | ||
| """ | ||
|
|
||
| def hello(): | ||
| pass | ||
|
|
||
| pre_size = len(hello.__dict__) | ||
| keys = set(hello.__dict__.keys()) | ||
| data_hello = data(1, 2)(data(3)(hello)) | ||
|
Collaborator
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. I'd prefer adding a new test case for the new feature, rather than overloading an existing test case. The main reason being, any new feature should strive to be backwards compatible... meaning all existing tests should pass unmodified. It is harder for me to figure out whether your contribution is backwards-compatible or not, if you modify existing tests. |
||
| dh_keys = set(data_hello.__dict__.keys()) | ||
| post_size = len(data_hello.__dict__) | ||
|
|
||
| assert_equal(post_size, pre_size + 1) | ||
| extra_attrs = dh_keys - keys | ||
| assert_equal(len(extra_attrs), 1) | ||
| extra_attr = extra_attrs.pop() | ||
| assert_equal( | ||
| getattr(data_hello, extra_attr), | ||
| [DataValues((1, 2)), DataValues((3,))] | ||
| ) | ||
|
|
||
|
|
||
| def test_file_data_decorator_with_dict(): | ||
|
|
@@ -84,7 +110,7 @@ def hello(): | |
|
|
||
| pre_size = len(hello.__dict__) | ||
| keys = set(hello.__dict__.keys()) | ||
| data_hello = data("test_data_dict.json")(hello) | ||
| data_hello = file_data("test_data_dict.json")(hello) | ||
|
|
||
| dh_keys = set(data_hello.__dict__.keys()) | ||
| post_size = len(data_hello.__dict__) | ||
|
|
@@ -93,7 +119,39 @@ def hello(): | |
| extra_attrs = dh_keys - keys | ||
| assert_equal(len(extra_attrs), 1) | ||
| extra_attr = extra_attrs.pop() | ||
| assert_equal(getattr(data_hello, extra_attr), ("test_data_dict.json",)) | ||
| assert_equal( | ||
| getattr(data_hello, extra_attr), | ||
| [FileValues("test_data_dict.json")] | ||
| ) | ||
|
|
||
|
|
||
| def test_multiple_file_data_decorators_with_dict(): | ||
| """ | ||
| Test the ``file_data`` method decorator with multiple applications | ||
| """ | ||
|
|
||
| def hello(): | ||
| pass | ||
|
|
||
| pre_size = len(hello.__dict__) | ||
| keys = set(hello.__dict__.keys()) | ||
| data_hello = file_data("test_other_data.json")(hello) | ||
| data_hello = file_data("test_data_dict.json")(data_hello) | ||
|
|
||
| dh_keys = set(data_hello.__dict__.keys()) | ||
| post_size = len(data_hello.__dict__) | ||
|
|
||
| assert_equal(post_size, pre_size + 1) | ||
| extra_attrs = dh_keys - keys | ||
| assert_equal(len(extra_attrs), 1) | ||
| extra_attr = extra_attrs.pop() | ||
| assert_equal( | ||
| getattr(data_hello, extra_attr), | ||
| [ | ||
| FileValues("test_data_dict.json"), | ||
| FileValues("test_other_data.json"), | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| is_test = lambda x: x.startswith('test_') | ||
|
|
||
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.
All your examples include 2 sets of
@data. I haven't debugged your implementation to see if this is a limitation there, but it doesn't feel like it should. In that case, it would be nice to include some example case with more than 2@dataentries to make that explicit.