Skip to content
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

Add basic support for YAML data files #42

Merged
merged 16 commits into from May 30, 2016
Merged

Conversation

pradyunsg
Copy link
Contributor

Add support for YAML files, when PyYAML is installed. If PyYAML is not
installed, any YAML file_data functions error out.

Only files ending with .yml or .yaml are considered to be YAML files.
All other files are loaded as JSON files.

Add support for YAML files, when PyYAML is installed. If PyYAML is not
installed, any YAML file_data functions error out.

Only files ending with .yml or .yaml are considered to be YAML files.
All other files are loaded as JSON files.
return

# Load the data as YAML or JSON
if data_file_path.endswith((".yml", ".yaml")):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other extensions you wish to support?

@pradyunsg
Copy link
Contributor Author

Off-topic: Shouldn't flake8 be run, on a separate worker instead of for all Python versions?

@codecov-io
Copy link

codecov-io commented May 27, 2016

Current coverage is 100%

Merging #42 into master will not change coverage

@@           master   #42   diff @@
===================================
  Files           1     1          
  Lines          88   104    +16   
  Methods         0     0          
  Messages        0     0          
  Branches        0     0          
===================================
+ Hits           88   104    +16   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last updated by 72fbfed...53f5528

@pradyunsg
Copy link
Contributor Author

I'm not sure how to add coverage for the no-YAML installed branches, unless a change is made to the API which I don't want to do since the current API is sufficient.

  • adding a flag variable? Not nice.

@pradyunsg
Copy link
Contributor Author

Oh, I forgot to mention, Fixes #30.

@pradyunsg pradyunsg closed this May 27, 2016
@pradyunsg pradyunsg reopened this May 27, 2016
@pradyunsg
Copy link
Contributor Author

pradyunsg commented May 27, 2016

whoops! I will now wait for someone else to say something.

@txels
Copy link
Collaborator

txels commented May 29, 2016

Looks good, and thanks for spotting the open file issue.

I realise that code coverage has now decreased, because there isn't any test for the case where the user doesn't have yaml support installed. Do you think you could add one?

except Exception:
do_not_have_yaml_support = True
else:
do_not_have_yaml_support = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a matter of preference, I'd prefer to word things positively and avoid double negative statements like this one.
has_yaml_support makes things more readable. Below you can use not has_yaml_support for skipping the unit test...

@txels
Copy link
Collaborator

txels commented May 29, 2016

The documentation should also be updated (even if just mentioning in https://github.com/txels/ddt/blob/master/docs/example.rst that file can be JSON or YAML).

Change behaviour to close the data file once work is done.

Also, pass the data file object is directly to the loaders, instead of
reading and buffering the entire file and passing the buffer.
It would disallow for arbitary objects from being created and makes the
file-loading safe.
@pradyunsg
Copy link
Contributor Author

pradyunsg commented May 29, 2016

I realise that code coverage has now decreased, because there isn't any test for the case where the user doesn't have yaml support installed. Do you think you could add one?

It's not trivial. The thing is running that test would require the lack of PyYAML. That would increase the size of the build-matrix, and still, the reported coverage won't increase (unless codecov allows for some sort of these-are-related-builds flags). I could have a test-run without PyYAML but I'm not sure how that is to be done within the current method of dependency installation.

I think I'm going to make another PR re-factoring the tests to be more comprehensive and easier to manage, after this PR...

@txels
Copy link
Collaborator

txels commented May 29, 2016

In honesty you could test the pyyaml absence by just patching _have_yaml to be False in ddt.py in the specific test cases, using the mock library. That would be my approach. I don't think it's worth the effort to go for something more complicated than that, for the marginal value of the tests.

@pradyunsg
Copy link
Contributor Author

But you'll still be missing the except clause around the import of yaml.

On Sun, May 29, 2016, 8:22 PM Carles Barrobés notifications@github.com
wrote:

In honesty you could test the pyyaml absence by just patching _have_yaml
to be False in ddt in the specific test cases, using the mock library.
That would be my approach. I don't think it's worth the effort to go for
something more complicated than that, for the marginal value of the tests.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#42 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ADH7SbN-oWzwUdcyKquLpqubO7YZgizCks5qGagmgaJpZM4IoNh0
.

@txels
Copy link
Collaborator

txels commented May 29, 2016

True, but I can live with that.

@pradyunsg
Copy link
Contributor Author

Okay. That's all the tests done and all the CI/Code-Quality checks satisfied.

Are there any other outstanding issues?

@@ -270,3 +299,24 @@ def test_feed_data_with_invalid_identifier():
'test_data_with_invalid_identifier_1_32v2_g__Gmw845h_W_b53wi_'
)
assert_equal(method(), '32v2 g #Gmw845h$W b53wi.')


@mock.patch('ddt._have_yaml', False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Documentation only change, skip ci
@txels
Copy link
Collaborator

txels commented May 30, 2016

Merge on green.
I will release this afternoon at latest.

@txels txels merged commit 115a805 into datadriventests:master May 30, 2016
@pradyunsg
Copy link
Contributor Author

pradyunsg commented May 30, 2016

I thought I had skipped the CI build. Then I realized, I missed the square brackets... 😅

Would the release be a minor or major version bump? I would like major. But it's upto you.

@pradyunsg
Copy link
Contributor Author

Bump. A gentle reminder close #30 and release this version.

@txels
Copy link
Collaborator

txels commented May 31, 2016

:) thanks for the reminder.

Done, pushed and closed. Unfortunately pypi is having a fit at the moment (generating 503 errors) so it will take a bit longer for me to release the new version.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants