-
Notifications
You must be signed in to change notification settings - Fork 42
ENH: Support remote data in doctest #137
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 8 commits
7fb4c97
23c3af7
734eb2c
05315b0
026294c
e49bc1c
db9743a
1bfac47
2e4e174
12df23a
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 |
|---|---|---|
|
|
@@ -59,5 +59,8 @@ venv | |
| # PyCharm | ||
| .idea | ||
|
|
||
| # VS code | ||
| .vscode | ||
|
|
||
| pytest_doctestplus/version.py | ||
| pip-wheel-metadata/ | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -80,3 +80,77 @@ Code in doctest should run only if version condition is satisfied: | |||||
| .. doctest-requires:: pytest>=1.0 pytest>=2.0 | ||||||
|
|
||||||
| >>> import pytest | ||||||
|
|
||||||
|
|
||||||
| Remote data block code sandwiched in block codes | ||||||
| ================================================ | ||||||
|
|
||||||
| This code block should work just fine:: | ||||||
|
|
||||||
| >>> 1 + 1 | ||||||
| 2 | ||||||
|
|
||||||
| This should be skipped when remote data is not requested | ||||||
| otherwise the test should fail:: | ||||||
|
|
||||||
| .. doctest-remote-data:: | ||||||
|
|
||||||
| >>> 1 + 3 | ||||||
bsipocz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| 2 | ||||||
|
|
||||||
| This code block should work just fine:: | ||||||
|
|
||||||
| >>> 1 + 1 | ||||||
|
||||||
| 2 | ||||||
|
|
||||||
|
|
||||||
| Remote data followed by plain block code | ||||||
| ======================================== | ||||||
|
|
||||||
| This one should be skipped when remote data is not requested | ||||||
| otherwise the test should fail:: | ||||||
|
|
||||||
| .. doctest-remote-data:: | ||||||
|
|
||||||
| >>> 1 + 3 | ||||||
| 2 | ||||||
|
|
||||||
| This code block should work just fine:: | ||||||
|
|
||||||
| >>> 1 + 1 | ||||||
|
||||||
| 2 | ||||||
|
|
||||||
|
|
||||||
| Several blocks of Remote data | ||||||
| ============================= | ||||||
|
|
||||||
| The three block codes should be skipped when remote data | ||||||
| is not requested otherwise the tests should fail: | ||||||
|
|
||||||
| .. doctest-remote-data:: | ||||||
|
|
||||||
| >>> 1 + 3 | ||||||
| 2 | ||||||
|
|
||||||
| .. doctest-remote-data:: | ||||||
|
|
||||||
| >>> 1 + 4 | ||||||
| 2 | ||||||
|
|
||||||
| .. doctest-remote-data:: | ||||||
|
|
||||||
| >>> 1 + 5 | ||||||
| 2 | ||||||
|
|
||||||
| composite directive with remote data | ||||||
| ==================================== | ||||||
|
|
||||||
| This should be skipped otherwise the test should fail:: | ||||||
|
||||||
| This should be skipped otherwise the test should fail:: | |
| This should be skipped otherwise the test should fail: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,7 +433,7 @@ def test_ignore_warnings_rst(testdir): | |
| # First check that we get a warning if we don't add the IGNORE_WARNINGS | ||
| # directive | ||
| p = testdir.makefile(".rst", | ||
| """ | ||
| """ | ||
| :: | ||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) | ||
|
|
@@ -444,7 +444,7 @@ def test_ignore_warnings_rst(testdir): | |
|
|
||
| # Now try with the IGNORE_WARNINGS directive | ||
| p = testdir.makefile(".rst", | ||
| """ | ||
| """ | ||
| :: | ||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) # doctest: +IGNORE_WARNINGS | ||
|
|
@@ -486,7 +486,7 @@ def myfunc(): | |
| def test_show_warnings_rst(testdir): | ||
|
|
||
| p = testdir.makefile(".rst", | ||
| """ | ||
| """ | ||
| :: | ||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS | ||
|
|
@@ -498,7 +498,7 @@ def test_show_warnings_rst(testdir): | |
|
|
||
| # Make sure it fails if warning message is missing | ||
| p = testdir.makefile(".rst", | ||
| """ | ||
| """ | ||
| :: | ||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS | ||
|
|
@@ -509,7 +509,7 @@ def test_show_warnings_rst(testdir): | |
|
|
||
| # Make sure it fails if warning message is missing | ||
| p = testdir.makefile(".rst", | ||
| """ | ||
| """ | ||
| :: | ||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS | ||
|
|
@@ -775,3 +775,142 @@ def test_doctest_skip(testdir): | |
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
|
|
||
|
|
||
| # We repeat all testst including remote data with and without it opted in | ||
| def test_remote_data_url(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
| '.rst', | ||
| """ | ||
| # This test should be skipped when remote data is not requested. | ||
| .. doctest-remote-data:: | ||
|
|
||
| >>> from contextlib import closing | ||
| >>> from urllib.request import urlopen | ||
| >>> with closing(urlopen('https://www.astropy.org')) as remote: | ||
| ... remote.read() # doctest: +IGNORE_OUTPUT | ||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(passed=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
|
|
||
|
|
||
| def test_remote_data_float_cmp(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
| '.rst', | ||
| """ | ||
| #This test is skipped when remote data is not requested | ||
| .. doctest-remote-data:: | ||
|
|
||
| >>> x = 1/3. | ||
| >>> x # doctest: +FLOAT_CMP | ||
| 0.333333 | ||
saimn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(passed=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
|
|
||
|
|
||
| def test_remote_data_ignore_whitespace(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctest_optionflags = NORMALIZE_WHITESPACE | ||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
| '.rst', | ||
| """ | ||
| #This test should be skipped when remote data is not requested, and should | ||
| #pass when remote data is requested | ||
| .. doctest-remote-data:: | ||
|
|
||
| >>> a = "foo " | ||
| >>> print(a) | ||
| foo | ||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(passed=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
|
|
||
|
|
||
| def test_remote_data_ellipsis(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctest_optionflags = ELLIPSIS | ||
|
Contributor
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. What is the purpose of the extra
Contributor
Author
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 was trying to test if the ELLIPSIS option works well with the
Member
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. @pllim - we run into some cases where it seemed some of the default flags don't work nicely together, so as mentioned above the purpose was to test some of them. |
||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
tinuademargaret marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| '.rst', | ||
| """ | ||
| # This test should be skipped when remote data is not requested, and should | ||
| # pass when remote data is requested | ||
| .. doctest-remote-data:: | ||
|
|
||
| >>> a = "freedom at last" | ||
| >>> print(a) | ||
| freedom ... | ||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(passed=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
|
|
||
|
|
||
| def test_remote_data_requires(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
| '.rst', | ||
| """ | ||
| # This test should be skipped when remote data is not requested. | ||
| # It should also be skipped instead of failing when remote data is requested because | ||
| # the module required does not exist | ||
| .. doctest-remote-data:: | ||
| .. doctest-requires:: does-not-exist | ||
|
|
||
| >>> 1 + 1 | ||
| 3 | ||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(skipped=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
pllim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_remote_data_ignore_warnings(testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| doctestplus = enabled | ||
| """) | ||
|
|
||
| p = testdir.makefile( | ||
| '.rst', | ||
| """ | ||
| # This test should be skipped if remote data is not requested. | ||
| .. doctest-remote-data:: | ||
|
|
||
| >>> import warnings | ||
| >>> warnings.warn('A warning occurred', UserWarning) # doctest: +IGNORE_WARNINGS | ||
| """ | ||
| ) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst', '--remote-data').assertoutcome(passed=1) | ||
| testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1) | ||
Uh oh!
There was an error while loading. Please reload this page.