-
Notifications
You must be signed in to change notification settings - Fork 310
Add Fenced Docstring Testing #640
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
mattdangerw
merged 22 commits into
keras-team:master
from
abheesht17:fenced-docstring-testing
Jan 17, 2023
Merged
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bbec551
Add fenced docstring lib
abheesht17 cd1e0ce
Fixes
abheesht17 ce53cad
Use RegEx
abheesht17 1a42b22
Some UT fixes
abheesht17 80fdf17
More docstring fixes
abheesht17 eebed11
Fix find_files()
abheesht17 4c46ba5
Fix more docstrings
abheesht17 bd36af5
Fix classifier docstrings
abheesht17 12e1921
Fix mistake
abheesht17 ded4ff0
Module-level test collection
abheesht17 75a0eb9
Stop testing Backbone
abheesht17 38b6e42
Merge branch 'master' into fenced-docstring-testing
abheesht17 3698680
Fixes
abheesht17 50d91e0
Add source
abheesht17 21f08ec
Conditional import for astor
abheesht17 d4d9cf5
Small fixes
abheesht17 232f70f
Minor edit
abheesht17 59a6611
Fixes
abheesht17 5635776
Merge branch 'keras-team:master' into fenced-docstring-testing
abheesht17 616cdc0
Add FNet preprocessor to skipped fenced ds
abheesht17 b8a8cd0
Remove unused vars
abheesht17 2c8dd9f
copy edit
mattdangerw 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
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 |
|---|---|---|
|
|
@@ -77,7 +77,7 @@ class BertBackbone(Backbone): | |
| } | ||
|
|
||
| # Pretrained BERT encoder | ||
| model = keras_nlp.models.BertBackbone.from_preset("base_base_en_uncased") | ||
| model = keras_nlp.models.BertBackbone.from_preset("bert_base_en_uncased") | ||
|
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. lol, good we are running this :) |
||
| output = model(input_data) | ||
|
|
||
| # Randomly initialized BERT encoder with a custom config | ||
|
|
||
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
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 |
|---|---|---|
|
|
@@ -13,19 +13,23 @@ | |
| # limitations under the License. | ||
|
|
||
| import doctest | ||
| import io | ||
| import os | ||
| import sys | ||
| import unittest | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import sentencepiece | ||
| import tensorflow as tf | ||
| from tensorflow import keras | ||
|
|
||
| import keras_nlp | ||
| from keras_nlp.tests.doc_tests import docstring_lib | ||
| from keras_nlp.tests.doc_tests import fenced_docstring_lib | ||
|
|
||
| PACKAGE = "keras_nlp." | ||
| DIRECTORY = "keras_nlp" | ||
|
|
||
|
|
||
| def find_modules(): | ||
|
|
@@ -37,9 +41,6 @@ def find_modules(): | |
| return keras_nlp_modules | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| sys.platform == "win32", reason="Numpy prints differently on windows" | ||
| ) | ||
| def test_docstrings(): | ||
| keras_nlp_modules = find_modules() | ||
| # As of this writing, it doesn't seem like pytest support load_tests | ||
|
|
@@ -77,3 +78,67 @@ def test_docstrings(): | |
| if not result.wasSuccessful(): | ||
| print(result) | ||
| assert result.wasSuccessful() | ||
|
|
||
|
|
||
| @pytest.mark.extra_large | ||
| def test_fenced_docstrings(): | ||
|
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. we should probably mark this a large test, this will involve a lot of file downloads for the preset right? |
||
| """Tests fenced code blocks in docstrings. | ||
|
|
||
| This can only be run manually. Run with: | ||
| `pytest keras_nlp/tests/doc_tests/docstring_test.py --run_extra_large` | ||
| """ | ||
| keras_nlp_modules = find_modules() | ||
|
|
||
| runner = unittest.TextTestRunner() | ||
| suite = unittest.TestSuite() | ||
| for module in keras_nlp_modules: | ||
| # Temporarily stop testing gpt2 & deberta docstrings until we are | ||
| # exporting the symbols. | ||
| if "gpt2" in module.__name__ or "deberta_v3" in module.__name__: | ||
| continue | ||
| # Do not test certain modules. | ||
| if module.__name__ in [ | ||
| # Base classes. | ||
| "keras_nlp.models.backbone", | ||
| "keras_nlp.models.preprocessor", | ||
| # Preprocessors and tokenizers which use `model.spm`. | ||
| "keras_nlp.models.albert.albert_preprocessor", | ||
| "keras_nlp.models.albert.albert_tokenizer", | ||
| "keras_nlp.models.xlm_roberta.xlm_roberta_preprocessor", | ||
| ]: | ||
| continue | ||
|
|
||
| suite.addTest( | ||
| doctest.DocTestSuite( | ||
| module, | ||
| test_finder=doctest.DocTestFinder( | ||
| exclude_empty=False, | ||
| parser=fenced_docstring_lib.FencedCellParser( | ||
| fence_label="python" | ||
| ), | ||
| ), | ||
| globs={ | ||
| "_print_if_not_none": fenced_docstring_lib._print_if_not_none | ||
| }, | ||
| extraglobs={ | ||
| "tf": tf, | ||
| "np": np, | ||
| "os": os, | ||
| "keras": keras, | ||
| "keras_nlp": keras_nlp, | ||
| "io": io, | ||
| "sentencepiece": sentencepiece, | ||
| }, | ||
| checker=docstring_lib.DoctestOutputChecker(), | ||
| optionflags=( | ||
| doctest.ELLIPSIS | ||
| | doctest.NORMALIZE_WHITESPACE | ||
| | doctest.IGNORE_EXCEPTION_DETAIL | ||
| | doctest.DONT_ACCEPT_BLANKLINE | ||
| ), | ||
| ) | ||
| ) | ||
| result = runner.run(suite) | ||
| if not result.wasSuccessful(): | ||
| print(result) | ||
| assert result.wasSuccessful() | ||
Oops, something went wrong.
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.
Let's remember to remove this.