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

Run doctests with tox #49

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

AndreMiras
Copy link
Contributor

What was wrong?

Currently the CI doesn't run doctests.
However keep in mind that now we have 5 tests failing.
If you're interested with the approach, I can also fix them in this PR or in another one.

Issue #9

How was it fixed?

Enabling doctests via tox.ini and pytest.ini

Cute Animal Picture

image

@pipermerriam
Copy link
Member

Yes please, enabling doctest is something we've been adding to all of our repos and it should be in place here as well.

@carver
Copy link
Contributor

carver commented Nov 14, 2018

Yup, this is great, thanks!

If you're interested with the approach, I can also fix them in this PR or in another one.

Please fix in this PR. As a rule we never merge a failing CI run.

FWIW, it's important that the readability of the docs not suffer in order to get the tests passing.

@AndreMiras
Copy link
Contributor Author

Great, then I may pick this up over the weekend if I get a chance.
Yes I agree the documentation should still be as readable 👍

@fubuloubu
Copy link
Contributor

Seems like this can be closed?

@carver
Copy link
Contributor

carver commented May 31, 2019

Seems like this can be closed?

I don't think this change was done yet. We are already test appropriately-marked snippets in the docs/ folder. But this one would test the docstring'd method definitions, which is also reasonable to do.

Fixes some syntax errors in previous doctests.
Some tests are disabled with `doctest: +SKIP` as they couldn't be ran or
fixed as it is for now. Note that this `doctest: +SKIP` comment won't
appear in the generated documentation.
@AndreMiras
Copy link
Contributor Author

Hi guys, I will eventually resume my contributions starting from this one as I have more time 🎉
So I've rebased this PR, fixed the tests I could and skipped some others. Currently 9 are skipped, but I think it's a good start for now and we may reduce this number in the future.
I can't wait to contribute more in the future 😄

... 'salt': '45cf943b4de2c05c2c440ef96af914a2'},
... 'mac': 'f5e1af09df5ded25c96fcf075ada313fb6f79735a914adc8cb02e8ddee7813c3'},
... 'id': 'b812f3f9-78cc-462a-9e89-74418aa27cb0',
... 'version': 3}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enabling doctests helped in detecting this "syntax error"


>>> import getpass
>>> Account.decrypt(encrypted, getpass.getpass())
>>> Account.decrypt(encrypted, getpass.getpass()) # doctest: +SKIP
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to disable because obviously getpass() would ask for terminal input.
We could also give an example with an hardcoded value for the password that always produces an expected output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, maybe worth doing both: demonstrating good practices but skipping the test (as you already did), and adding a version that can be doctest-ed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that could be it. Actually I initially wanted to find the password used to generate this output, but haven't found it so far.
I've created a task for adding a doctest that works #81

@carver
Copy link
Contributor

carver commented Jan 6, 2020

Currently 9 are skipped

Maybe add an issue for fixing & re-enabling these tests?

Copy link
Contributor

@carver carver left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

I'll wait a bit for you to add that non-getpass() version. If you want to skip that for now, just let me know, and I'll merge it in.

@@ -187,13 +187,13 @@ def encode_defunct(
SignableMessage(version=b'E', header=b'thereum Signed Message:\n6', body=b'I\xe2\x99\xa5SF')

# these four also produce the same hash:
>>> encode_defunct(w3.toBytes(text=message_text))
>>> encode_defunct(w3.toBytes(text=message_text)) # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious what the failure was here (I'm fine to push it to another issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NameError: name 'w3' is not defined

Copy link
Contributor

Choose a reason for hiding this comment

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

Hah, ok. Well that's not an instance method so it should be straightforward to switch w3 to Web3 and just add a from web3 import Web3 up top. Just a note for when you/someone does the follow-up work.

@AndreMiras
Copy link
Contributor Author

Thanks for the review and approval @carver

I'll wait a bit for you to add that non-getpass() version. If you want to skip that for now, just let me know, and I'll merge it in.

I'm on holiday without much access to dev laptop, so I'd prefer we merge it. However I've created a followup task that I'll be happy to pick up later.

@carver carver merged commit 692cf9d into ethereum:master Jan 9, 2020
@AndreMiras AndreMiras deleted the feature/ticket9_run_doctests branch January 10, 2020 09:22
AndreMiras added a commit to AndreMiras/eth-account that referenced this pull request Jan 18, 2020
AndreMiras added a commit to AndreMiras/eth-account that referenced this pull request Jan 18, 2020
carver added a commit to carver/eth-account that referenced this pull request Jul 21, 2021
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.

4 participants