-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
test .py and .rst files with doctest #445
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
913b8a9
test all files with doctest
niccokunzmann 9c2d097
make sure .rst collection includes only icalendar files
niccokunzmann fb51485
convert usage.rst to valid doctest
niccokunzmann 7b2e905
document doctest
niccokunzmann dc2c280
Merge branch 'master' into doctest
niccokunzmann 8995669
update install.rst to latest version
niccokunzmann 4d899a2
Merge branch 'master' into doctest
niccokunzmann 0fbba53
update version in install documentation
niccokunzmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""This file tests the source code provided by the documentation. | ||
|
||
See | ||
- doctest documentation: https://docs.python.org/3/library/doctest.html | ||
- Issue 443: https://github.com/collective/icalendar/issues/443 | ||
|
||
This file should be tests, too: | ||
|
||
>>> print("Hello World!") | ||
Hello World! | ||
|
||
""" | ||
import doctest | ||
import os | ||
import pytest | ||
import importlib | ||
|
||
HERE = os.path.dirname(__file__) or "." | ||
ICALENDAR_PATH = os.path.dirname(HERE) | ||
|
||
PYTHON_FILES = [ | ||
os.path.join(dirpath, filename) | ||
for dirpath, dirnames, filenames in os.walk(ICALENDAR_PATH) | ||
for filename in filenames if filename.lower().endswith(".py") | ||
] | ||
|
||
MODULE_NAMES = [ | ||
"icalendar" + python_file[len(ICALENDAR_PATH):-3].replace("/", ".") | ||
for python_file in PYTHON_FILES | ||
] | ||
|
||
def test_this_module_is_among_them(): | ||
assert __name__ in MODULE_NAMES | ||
|
||
@pytest.mark.parametrize("module_name", MODULE_NAMES) | ||
def test_docstring_of_python_file(module_name): | ||
"""This test runs doctest on the Python module.""" | ||
module = importlib.import_module(module_name) | ||
test_result = doctest.testmod(module, name=module_name) | ||
assert test_result.failed == 0, f"{test_result.failed} errors in {module_name}" | ||
|
||
|
||
# This collection needs to exclude .tox and other subdirectories | ||
DOCUMENTATION_PATH = os.path.join(HERE, "../../../") | ||
|
||
DOCUMENT_PATHS = [ | ||
os.path.join(DOCUMENTATION_PATH, subdir, filename) | ||
for subdir in ["docs", "."] | ||
for filename in os.listdir(os.path.join(DOCUMENTATION_PATH, subdir)) | ||
if filename.lower().endswith(".rst") | ||
] | ||
|
||
@pytest.mark.parametrize("filename", [ | ||
"README.rst", | ||
"index.rst", | ||
]) | ||
def test_files_is_included(filename): | ||
assert any(path.endswith(filename) for path in DOCUMENT_PATHS) | ||
|
||
@pytest.mark.parametrize("document", DOCUMENT_PATHS) | ||
def test_documentation_file(document): | ||
"""This test runs doctest on a documentation file.""" | ||
test_result = doctest.testfile(document, module_relative=False) | ||
assert test_result.failed == 0, f"{test_result.failed} errors in {os.path.basename(document)}" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this one should do in the
tests_require
list that you can find in thesetup.py
file:icalendar/setup.py
Line 20 in 68dc8b1
Then the
requirements_docs.txt
file should install. [test]
(untested)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.
Thanks for your reply! Hm I do not know why hypothesis is even in there.
Here, it uses
use_debelop=True
and therewith does apip install .
.We do have different tests running that have different dependencies. Using use-develop is what we do here. I think, changing this would go into an other PR as it is independent of doctest. If you think, that change is worth experimenting with, you can create a PR or an issue, I would say. I do not really see a difference at the moment.
What do you think?