-
Notifications
You must be signed in to change notification settings - Fork 309
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
Changes from all commits
bbec551
cd1e0ce
ce53cad
1a42b22
80fdf17
eebed11
4c46ba5
bd36af5
12e1921
ded4ff0
75a0eb9
38b6e42
3698680
50d91e0
21f08ec
d4d9cf5
232f70f
59a6611
5635776
616cdc0
b8a8cd0
2c8dd9f
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 |
|---|---|---|
|
|
@@ -13,17 +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 | ||
| from keras_nlp.tests.doc_tests.fenced_docstring_lib import ( | ||
| astor, # For checking conditional import. | ||
| ) | ||
|
|
||
| PACKAGE = "keras_nlp." | ||
|
|
||
|
|
@@ -37,9 +43,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 +80,73 @@ def test_docstrings(): | |
| if not result.wasSuccessful(): | ||
| print(result) | ||
| assert result.wasSuccessful() | ||
|
|
||
|
|
||
| @pytest.mark.extra_large | ||
| @pytest.mark.skipif( | ||
|
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 can probably remove this case everywhere, we aren't supporting win32 natively anymore (only through WSL). |
||
| astor is None, | ||
| reason="This test requires `astor`. Please `pip install astor` to run.", | ||
| ) | ||
| 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", | ||
| "keras_nlp.models.f_net.f_net_preprocessor", | ||
| "keras_nlp.models.f_net.f_net_tokenizer", | ||
| ]: | ||
| 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() | ||
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.
lol, good we are running this :)