From dfa07c7c1fca8799d81b7ae165afc1f0699bb1f6 Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 15 Oct 2018 10:01:24 -0400 Subject: [PATCH 1/3] TST: add a check for common parameters type error in doctests --- scripts/tests/test_validate_docstrings.py | 41 ++++++++++++++++++++++- scripts/validate_docstrings.py | 11 +++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 27c63e3ba3a79..dbbece7b1af6c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -208,7 +208,7 @@ def mode(self, axis, numeric_only): .. versionchanged:: 0.1.2 - numeric_only : boolean + numeric_only : bool Sentence ending in period, followed by multiple directives. .. versionadded:: 0.1.2 @@ -455,6 +455,39 @@ def blank_lines(self, kind): """ pass + def integer_parameter(self, kind): + """ + Uses integer instead of int. + + Parameters + ---------- + kind : integer + Foo bar baz. + """ + pass + + def string_parameter(self, kind): + """ + Uses string instead of str. + + Parameters + ---------- + kind : string + Foo bar baz. + """ + pass + + def boolean_parameter(self, kind): + """ + Uses boolean instead of bool. + + Parameters + ---------- + kind : boolean + Foo bar baz. + """ + pass + class BadReturns(object): @@ -590,6 +623,12 @@ def test_bad_generic_functions(self, func): ('Parameter "kind" description should finish with "."',)), ('BadParameters', 'parameter_capitalization', ('Parameter "kind" description should start with a capital letter',)), + ('BadParameters', 'integer_parameter', + ('Parameter "kind" type should be "int" instead of "integer"',)), + ('BadParameters', 'string_parameter', + ('Parameter "kind" type should be "str" instead of "string"',)), + ('BadParameters', 'boolean_parameter', + ('Parameter "kind" type should be "bool" instead of "boolean"',)), pytest.param('BadParameters', 'blank_lines', ('No error yet?',), marks=pytest.mark.xfail), # Returns tests diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 6588522331433..db7e891172921 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -464,7 +464,16 @@ def validate_one(func_name): if doc.parameter_type(param)[-1] == '.': param_errs.append('Parameter "{}" type should ' 'not finish with "."'.format(param)) - + common_type_errors = [('integer', 'int'), + ('boolean', 'bool'), + ('string', 'str')] + for incorrect_type, correct_type in common_type_errors: + if incorrect_type in doc.parameter_type(param): + param_errs.append('Parameter "{}" type should be ' + '"{}" instead of "{}"' + .format(param, + correct_type, + incorrect_type)) if not doc.parameter_desc(param): param_errs.append('Parameter "{}" ' 'has no description'.format(param)) From 87638fe46df61756f50530b95c0cbac49618568a Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 15 Oct 2018 10:38:35 -0400 Subject: [PATCH 2/3] Fix pep8 issue --- scripts/validate_docstrings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index db7e891172921..cf6dfa9b30b6f 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -465,8 +465,8 @@ def validate_one(func_name): param_errs.append('Parameter "{}" type should ' 'not finish with "."'.format(param)) common_type_errors = [('integer', 'int'), - ('boolean', 'bool'), - ('string', 'str')] + ('boolean', 'bool'), + ('string', 'str')] for incorrect_type, correct_type in common_type_errors: if incorrect_type in doc.parameter_type(param): param_errs.append('Parameter "{}" type should be ' From 26bf7bee449e6e320f706a8566d30ad725dddbfd Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Tue, 16 Oct 2018 15:01:51 -0400 Subject: [PATCH 3/3] Add a test for list of . --- scripts/tests/test_validate_docstrings.py | 23 ++++++++++++++++++++--- scripts/validate_docstrings.py | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index dbbece7b1af6c..fcae4051dc471 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -488,6 +488,17 @@ def boolean_parameter(self, kind): """ pass + def list_incorrect_parameter_type(self, kind): + """ + Uses list of boolean instead of list of bool. + + Parameters + ---------- + kind : list of boolean, integer, float or string + Foo bar baz. + """ + pass + class BadReturns(object): @@ -624,11 +635,17 @@ def test_bad_generic_functions(self, func): ('BadParameters', 'parameter_capitalization', ('Parameter "kind" description should start with a capital letter',)), ('BadParameters', 'integer_parameter', - ('Parameter "kind" type should be "int" instead of "integer"',)), + ('Parameter "kind" type should use "int" instead of "integer"',)), ('BadParameters', 'string_parameter', - ('Parameter "kind" type should be "str" instead of "string"',)), + ('Parameter "kind" type should use "str" instead of "string"',)), ('BadParameters', 'boolean_parameter', - ('Parameter "kind" type should be "bool" instead of "boolean"',)), + ('Parameter "kind" type should use "bool" instead of "boolean"',)), + ('BadParameters', 'list_incorrect_parameter_type', + ('Parameter "kind" type should use "bool" instead of "boolean"',)), + ('BadParameters', 'list_incorrect_parameter_type', + ('Parameter "kind" type should use "int" instead of "integer"',)), + ('BadParameters', 'list_incorrect_parameter_type', + ('Parameter "kind" type should use "str" instead of "string"',)), pytest.param('BadParameters', 'blank_lines', ('No error yet?',), marks=pytest.mark.xfail), # Returns tests diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index cf6dfa9b30b6f..c571827db70f8 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -469,7 +469,7 @@ def validate_one(func_name): ('string', 'str')] for incorrect_type, correct_type in common_type_errors: if incorrect_type in doc.parameter_type(param): - param_errs.append('Parameter "{}" type should be ' + param_errs.append('Parameter "{}" type should use ' '"{}" instead of "{}"' .format(param, correct_type,