Skip to content
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

CI: make docstring checks "instantaneous" #57878

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
439395a
support running multiple docstring checks in one call
dontgoto Mar 12, 2024
6afa708
add test
dontgoto Mar 12, 2024
03fe545
group docstring calls in code_checks
dontgoto Mar 12, 2024
c01a78e
fix after merge, add cache size limit
dontgoto Mar 12, 2024
0cdb574
merge
dontgoto Mar 13, 2024
841793f
merge
dontgoto Mar 13, 2024
0ed525a
prepare PR
dontgoto Mar 13, 2024
22c8dce
revert CLI formatting
dontgoto Mar 13, 2024
8194d25
Merge branch 'main' into improve_docstring_check_performance
dontgoto Mar 13, 2024
5d3bd40
Merge remote-tracking branch 'upstream/main' into improve_docstring_c…
dontgoto Mar 13, 2024
1e27de8
Merge remote-tracking branch 'origin/improve_docstring_check_performa…
dontgoto Mar 13, 2024
99f0cee
introduce new shell parameter
dontgoto Mar 14, 2024
06cebc7
fix merge errors
dontgoto Mar 14, 2024
bf5da55
Merge branch 'main' into improve_docstring_check_performance
dontgoto Mar 14, 2024
69545dc
use for_error_ignore_functions everywhere
dontgoto Mar 16, 2024
e9a3a8c
Merge remote-tracking branch 'origin/improve_docstring_check_performa…
dontgoto Mar 16, 2024
12aac1b
Merge remote-tracking branch 'upstream/main' into improve_docstring_c…
dontgoto Mar 16, 2024
96f269b
cleanup
dontgoto Mar 16, 2024
6140bb5
remove whitespace changes
dontgoto Mar 16, 2024
37cc33d
make pandas_validate accept and return list
dontgoto Mar 16, 2024
41ae9ba
make pandas_validate accept and return list
dontgoto Mar 16, 2024
48d66a0
add pep8 bulk validator
dontgoto Mar 16, 2024
1038b45
Merge branch 'main' into improve_docstring_check_performance
dontgoto Mar 16, 2024
013514c
integrate review comments
dontgoto Mar 16, 2024
5bf704d
Merge remote-tracking branch 'origin/improve_docstring_check_performa…
dontgoto Mar 16, 2024
a172c67
remove cmd formatting code
dontgoto Mar 16, 2024
471f18d
Merge branch 'improve_docstring_check_performance' into docstring_che…
dontgoto Mar 16, 2024
a3c2a76
fix validate pep8
dontgoto Mar 17, 2024
3e315c7
add comment
dontgoto Mar 17, 2024
337db47
merge main and fix conflicts in code_checks.sh
dontgoto Mar 17, 2024
98f5ced
Merge branch 'improve_docstring_check_performance' into docstring_che…
dontgoto Mar 17, 2024
e116dc4
remove old validate_pep8
dontgoto Mar 17, 2024
a958037
fix line cont char
dontgoto Mar 17, 2024
23f7cbc
Merge branch 'improve_docstring_check_performance' into docstring_che…
dontgoto Mar 17, 2024
a4a3dae
Merge remote-tracking branch 'upstream/main' into docstring_check_red…
dontgoto Mar 17, 2024
4c5c859
remove examples_errs; clean up code
dontgoto Mar 17, 2024
14e3915
fix prefix bug, add test, refactor tests
dontgoto Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 100 additions & 85 deletions scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,69 @@ def leftover_files(self) -> None:
"""


def _print_validate_all_base(monkeypatch,
prefix=None,
ignore_deprecated=False,
ignore_errors=None,
overwrite_api_items=True
) -> tuple[int, int]:
dummy_docinfo = {
"docstring": "docstring1",
"errors": [
("ER01", "err desc"),
("ER02", "err desc"),
("ER03", "err desc")
],
"warnings": [],
"deprecated": True,
"file": "file1",
"file_line": "file_line1"
}
monkeypatch.setattr(
validate_docstrings,
"pandas_validate",
lambda func_names: {
func_name: dummy_docinfo
for func_name in func_names},
)
if overwrite_api_items:
monkeypatch.setattr(
validate_docstrings,
"get_all_api_items",
lambda: [
(
"pandas.DataFrame.align",
"func",
"current_section",
"current_subsection",
),
(
"pandas.Index.all",
"func",
"current_section",
"current_subsection",
),
],
)

exit_status = validate_docstrings.print_validate_all_results(
output_format="default",
prefix=prefix,
errors=["ER01", "ER02"],
ignore_deprecated=ignore_deprecated,
ignore_errors=ignore_errors
)
exit_status_reference = validate_docstrings.print_validate_all_results(
output_format="default",
prefix=None,
errors=["ER01", "ER02"],
ignore_deprecated=False,
ignore_errors=None
)

return exit_status_reference, exit_status


class TestValidator:
def _import_path(self, klass=None, func=None):
"""
Expand Down Expand Up @@ -118,11 +181,14 @@ def _import_path(self, klass=None, func=None):
return base_path

def test_bad_class(self, capsys) -> None:
errors = validate_docstrings.pandas_validate(
results = validate_docstrings.pandas_validate(
self._import_path(klass="BadDocstrings")
)["errors"]
assert isinstance(errors, list)
assert errors
)
assert len(results.keys()) == 1
for docinfo in results.values():
errors = docinfo["errors"]
assert errors
assert isinstance(errors, list)

@pytest.mark.parametrize(
"klass,func,msgs",
Expand Down Expand Up @@ -193,92 +259,41 @@ def test_bad_class(self, capsys) -> None:
],
)
def test_bad_docstrings(self, capsys, klass, func, msgs) -> None:
result = validate_docstrings.pandas_validate(
results = validate_docstrings.pandas_validate(
self._import_path(klass=klass, func=func)
)
for msg in msgs:
assert msg in " ".join([err[1] for err in result["errors"]])

def test_validate_all_ignore_deprecated(self, monkeypatch) -> None:
monkeypatch.setattr(
validate_docstrings,
"pandas_validate",
lambda func_name: {
"docstring": "docstring1",
"errors": [
("ER01", "err desc"),
("ER02", "err desc"),
("ER03", "err desc"),
],
"warnings": [],
"examples_errors": "",
"deprecated": True,
},
)
result = validate_docstrings.validate_all(prefix=None, ignore_deprecated=True)
assert len(result) == 0
assert len(results.keys()) == 1
for result in results.values():
for msg in msgs:
assert msg in " ".join([err[1] for err in result["errors"]])

def test_print_validate_all_ignore_deprecated(self, monkeypatch) -> None:
status, status_ignore_depr = _print_validate_all_base(monkeypatch,
ignore_deprecated=True,
overwrite_api_items=False)
assert status_ignore_depr == 0
assert status > 100
assert status % 2 == 0

def test_validate_all_prefix(self, monkeypatch):
status, status_prefix = _print_validate_all_base(monkeypatch,
prefix="pandas.DataFrame")
# the two errors of pandas.Index shall not be counted
assert status_prefix == status - 2

def test_validate_all_ignore_errors(self, monkeypatch):
monkeypatch.setattr(
validate_docstrings,
"pandas_validate",
lambda func_name: {
"docstring": "docstring1",
"errors": [
("ER01", "err desc"),
("ER02", "err desc"),
("ER03", "err desc")
],
"warnings": [],
"examples_errors": "",
"deprecated": True,
"file": "file1",
"file_line": "file_line1"
},
)
monkeypatch.setattr(
validate_docstrings,
"get_all_api_items",
lambda: [
(
"pandas.DataFrame.align",
"func",
"current_section",
"current_subsection",
),
(
"pandas.Index.all",
"func",
"current_section",
"current_subsection",
),
],
)

exit_status_ignore_func = validate_docstrings.print_validate_all_results(
output_format="default",
prefix=None,
errors=["ER01", "ER02"],
ignore_deprecated=False,
ignore_errors={
"pandas.DataFrame.align": ["ER01"],
# ignoring an error that is not requested should be of no effect
"pandas.Index.all": ["ER03"]
}
)
exit_status = validate_docstrings.print_validate_all_results(
output_format="default",
prefix=None,
errors=["ER01", "ER02"],
ignore_deprecated=False,
ignore_errors=None
)
ignore_errs = {
"pandas.DataFrame.align": ["ER01"],
# ignoring an error that is not requested should be of no effect
"pandas.Index.all": ["ER03"]
}
status, status_ignore_func = _print_validate_all_base(monkeypatch,
ignore_errors=ignore_errs)

# we have 2 error codes activated out of the 3 available in the validate results
# one run has a function to ignore, the other does not
assert exit_status == 2*2
assert exit_status_ignore_func == exit_status - 1

assert status == 2*2
assert status_ignore_func == status - 1


class TestApiItems:
Expand Down Expand Up @@ -375,7 +390,8 @@ class TestPandasDocstringClass:
)
def test_encode_content_write_to_file(self, name) -> None:
# GH25466
docstr = validate_docstrings.PandasDocstring(name).validate_pep8()
docstr = validate_docstrings.PandasDocstring(name)
docstr = validate_docstrings.validate_pep8_for_examples(docstr)[docstr]
# the list of pep8 errors should be empty
assert not list(docstr)

Expand All @@ -392,7 +408,6 @@ def test_exit_status_for_main(self, monkeypatch) -> None:
("ER02", "err desc"),
("ER03", "err desc"),
],
"examples_errs": "",
},
)
exit_status = validate_docstrings.main(
Expand Down
Loading
Loading