-
-
Notifications
You must be signed in to change notification settings - Fork 142
Test Notebooks #298
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
Merged
Merged
Test Notebooks #298
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
04b9f89
added test to execute all notebooks in examples
edwardelson 355513d
added jupyter to pipfile
edwardelson 94c5f2f
Merge branch 'dev' of https://github.com/OpenMined/PyDP into dev
edwardelson fb14c53
moved dependencies to dev and fixed dir in dp proof notebook
edwardelson 3ef626b
moved jupyter to packages
edwardelson 42fca5e
updated print format, moved subprocess execution
edwardelson 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,3 +15,5 @@ gcovr = "*" | |
| coverage = "*" | ||
|
|
||
| [packages] | ||
| jupyter = "*" | ||
| pandas = "*" | ||
This file contains hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| import glob | ||
|
|
||
| # execute notebook in given path | ||
| def _execute_notebook(notebook_path: str) -> bool: | ||
| # convert notebook-under-test in path to a temp notebook and execute it | ||
| with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout: | ||
| args = [ | ||
| "jupyter", | ||
| "nbconvert", | ||
| "--to", | ||
| "notebook", | ||
| "--execute", | ||
| "--output", | ||
| fout.name, | ||
| notebook_path, | ||
| ] | ||
| subprocess.check_call(args) | ||
|
|
||
| # return true if execution is successful | ||
| return True | ||
|
|
||
|
|
||
| # return all .ipynb notebooks in a given folder | ||
| def _get_all_notebooks(path: str) -> list: | ||
| # recursively find all .ipynb files in a given path's subdirectories | ||
| notebook_paths = glob.glob(os.path.join(path, "./**/*.ipynb"), recursive=True) | ||
|
|
||
| return notebook_paths | ||
|
|
||
|
|
||
| # test all notebooks in a given path | ||
| def test_all_notebooks(path="examples/"): | ||
| # get all notebooks under path | ||
| notebook_paths = _get_all_notebooks(path) | ||
|
|
||
| # execute each notebook | ||
| for notebook_path in notebook_paths: | ||
| # make sure notebook is successfully executed | ||
| assert _execute_notebook(notebook_path) |
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.
Rather, can we include this as part of
pytest?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 guess we could. I'm just not sure what was the original intention of putting this script in the contributing.md file? Was it perhaps to let newcomers try and run the code by themselves to get a better feel for the repo? In that case, maybe we should still put this command as part of contributing.md?
Uh oh!
There was an error while loading. Please reload this page.
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.
The idea is new-comers could try the python notebook to run our code. the python files are for how to include them as part of the codebase.
I just realized this comment was supposed to be for the file in
testsfolder.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.
@chinmayshah99 I moved jupyter & pandas to devDependencies but the CI seemed to dislike this (?) I encountered jupyter can't be found error (https://github.com/OpenMined/PyDP/runs/1132943621?check_suite_focus=true)