Unverified Commit b413e061 authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Remove `utils/documentation_tests.txt` (#25680)



* fix

* fix

* fix

* fix

* fix

* fix

* Apply suggestions from code review
Co-authored-by: default avatarArthur <48595927+ArthurZucker@users.noreply.github.com>

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
Co-authored-by: default avatarArthur <48595927+ArthurZucker@users.noreply.github.com>
parent 3d1edb6c
...@@ -43,9 +43,13 @@ jobs: ...@@ -43,9 +43,13 @@ jobs:
- name: Show installed libraries and their versions - name: Show installed libraries and their versions
run: pip freeze run: pip freeze
- name: Get doctest files
run: |
$(python3 -c 'from utils.tests_fetcher import get_all_doctest_files; to_test = get_all_doctest_files(); to_test = " ".join(to_test); fp = open("doc_tests.txt", "w"); fp.write(to_test); fp.close()')
- name: Run doctests - name: Run doctests
run: | run: |
python3 -m pytest -v --make-reports doc_tests_gpu --doctest-modules $(cat utils/documentation_tests.txt) -sv --doctest-continue-on-failure --doctest-glob="*.md" python3 -m pytest -v --make-reports doc_tests_gpu --doctest-modules $(cat doc_tests.txt) -sv --doctest-continue-on-failure --doctest-glob="*.md"
- name: Failure short reports - name: Failure short reports
if: ${{ failure() }} if: ${{ failure() }}
......
This diff is collapsed.
This diff is collapsed.
...@@ -367,6 +367,34 @@ def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: List[str]) -> ...@@ -367,6 +367,34 @@ def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: List[str]) ->
return code_diff return code_diff
def get_all_doctest_files() -> List[str]:
"""
Return the complete list of python and Markdown files on which we run doctest.
At this moment, we restrict this to only take files from `src/` or `docs/source/en/` that are not in `utils/not_doctested.txt`.
Returns:
`List[str]`: The complete list of Python and Markdown files on which we run doctest.
"""
py_files = [str(x.relative_to(PATH_TO_REPO)) for x in PATH_TO_REPO.glob("**/*.py")]
md_files = [str(x.relative_to(PATH_TO_REPO)) for x in PATH_TO_REPO.glob("**/*.md")]
test_files_to_run = py_files + md_files
# only include files in `src` or `docs/source/en/`
test_files_to_run = [x for x in test_files_to_run if x.startswith(("src/", "docs/source/en/"))]
# not include init files
test_files_to_run = [x for x in test_files_to_run if not x.endswith(("__init__.py",))]
# These are files not doctested yet.
with open("utils/not_doctested.txt") as fp:
not_doctested = set(fp.read().strip().split("\n"))
# So far we don't have 100% coverage for doctest. This line will be removed once we achieve 100%.
test_files_to_run = [x for x in test_files_to_run if x not in not_doctested]
return sorted(test_files_to_run)
def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]: def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]:
""" """
Return a list of python and Markdown files where doc example have been modified between: Return a list of python and Markdown files where doc example have been modified between:
...@@ -396,26 +424,19 @@ def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]: ...@@ -396,26 +424,19 @@ def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]:
print(f"Parent commit: {commit}") print(f"Parent commit: {commit}")
test_files_to_run = get_diff_for_doctesting(repo, repo.head.commit, parent_commits) test_files_to_run = get_diff_for_doctesting(repo, repo.head.commit, parent_commits)
# These are files not doctested yet. all_test_files_to_run = get_all_doctest_files()
with open("utils/not_doctested.txt") as fp:
not_doctested = set(fp.read().strip().split("\n")) # Do not run slow doctest tests on CircleCI
# Do not run slow doctest tests
with open("utils/slow_documentation_tests.txt") as fp: with open("utils/slow_documentation_tests.txt") as fp:
slow_documentation_tests = set(fp.read().strip().split("\n")) slow_documentation_tests = set(fp.read().strip().split("\n"))
test_files_to_run = [
# So far we don't have 100% coverage for doctest. This line will be removed once we achieve 100%. x for x in test_files_to_run if x in all_test_files_to_run and x not in slow_documentation_tests
test_files_to_run = [x for x in test_files_to_run if x not in not_doctested and x not in slow_documentation_tests] ]
# The file `utils/not_doctested.txt` doesn't contain all files that are not doc-tested, so we need more filters.
# 1. only include files in `src` or `docs/source/en/`
test_files_to_run = [x for x in test_files_to_run if x.startswith(("src/", "docs/source/en/"))]
# 2. not include init files
test_files_to_run = [x for x in test_files_to_run if not x.endswith(("__init__.py",))]
# Make sure we did not end up with a test file that was removed # Make sure we did not end up with a test file that was removed
test_files_to_run = [f for f in test_files_to_run if (PATH_TO_REPO / f).exists()] test_files_to_run = [f for f in test_files_to_run if (PATH_TO_REPO / f).exists()]
return test_files_to_run return sorted(test_files_to_run)
# (:?^|\n) -> Non-catching group for the beginning of the doc or a new line. # (:?^|\n) -> Non-catching group for the beginning of the doc or a new line.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment