From 4b3557384852c48548945689239a7c24d10528c5 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Sat, 9 Feb 2019 19:59:55 -0500 Subject: [PATCH 1/7] Fix minor error in dynamic load function --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index bce33f7e78daa..20f32124a2532 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -267,7 +267,7 @@ def _load_obj(name): else: continue - if 'module' not in locals(): + if 'obj' not in locals(): raise ImportError('No module can be imported ' 'from "{}"'.format(name)) From 34152efcb59872327d1d1503b4ccbb1338720718 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Thu, 21 Feb 2019 07:44:55 -0500 Subject: [PATCH 2/7] Add basic tests of validate_docstrings.Docstring --- scripts/tests/test_validate_docstrings.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index bb58449843096..448d5b5d5d061 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -4,6 +4,8 @@ import textwrap import pytest import numpy as np +import pandas + import validate_docstrings validate_one = validate_docstrings.validate_one @@ -1004,6 +1006,30 @@ def test_item_subsection(self, idx, subsection): assert result[idx][3] == subsection +class TestDocstringClass(object): + @pytest.mark.parametrize('name_and_expected_obj', + [('pandas.isnull', pandas.isnull), + ('pandas.DataFrame', pandas.DataFrame), + ('pandas.Series.sum', pandas.Series.sum)]) + def test_resolves_class_name(self, name_and_expected_obj): + name, expected_obj = name_and_expected_obj + d = validate_docstrings.Docstring(name) + assert d.obj is expected_obj + + @pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame']) + def test_raises_for_invalid_module_name(self, invalid_name): + # Note that the module names in this test are misspelled. + with pytest.raises(ImportError): + validate_docstrings.Docstring(invalid_name) + + @pytest.mark.parametrize('invalid_name', + ['pandas.BadClassName', + 'pandas.Series.bad_method_name']) + def test_raises_for_invalid_attribute_name(self, invalid_name): + with pytest.raises(AttributeError): + validate_docstrings.Docstring(invalid_name) + + class TestMainFunction(object): def test_exit_status_for_validate_one(self, monkeypatch): monkeypatch.setattr( From 480a3de5c83f04d2df41b60860b8a1bb51465060 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Fri, 22 Feb 2019 07:46:28 -0500 Subject: [PATCH 3/7] Match message in validate_docstrings test --- scripts/tests/test_validate_docstrings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 448d5b5d5d061..f08a1d82d53fb 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1018,8 +1018,10 @@ def test_resolves_class_name(self, name_and_expected_obj): @pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame']) def test_raises_for_invalid_module_name(self, invalid_name): - # Note that the module names in this test are misspelled. - with pytest.raises(ImportError): + # When an invalid module name is supplied, an ImportError should be + # raised, and the message should contain the user-supplied name. + msg = 'No module can be imported.*{}'.format(invalid_name) + with pytest.raises(ImportError, match=msg): validate_docstrings.Docstring(invalid_name) @pytest.mark.parametrize('invalid_name', From 64ec859e95cd838f5be1ec3cb005b4d50808b685 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Wed, 27 Feb 2019 21:35:17 -0500 Subject: [PATCH 4/7] Use idiomatic pytest parameter unpacking --- scripts/tests/test_validate_docstrings.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index f08a1d82d53fb..eda3038a49845 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1007,12 +1007,11 @@ def test_item_subsection(self, idx, subsection): class TestDocstringClass(object): - @pytest.mark.parametrize('name_and_expected_obj', + @pytest.mark.parametrize('name, expected_obj', [('pandas.isnull', pandas.isnull), ('pandas.DataFrame', pandas.DataFrame), ('pandas.Series.sum', pandas.Series.sum)]) - def test_resolves_class_name(self, name_and_expected_obj): - name, expected_obj = name_and_expected_obj + def test_resolves_class_name(self, name, expected_obj): d = validate_docstrings.Docstring(name) assert d.obj is expected_obj From 7f7d577fe84bfe030867a20949000c5c667928d4 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Wed, 27 Feb 2019 21:36:21 -0500 Subject: [PATCH 5/7] Use standard pandas import in test_validate_docstrings --- scripts/tests/test_validate_docstrings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index eda3038a49845..041d2e8f3bfac 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -4,7 +4,7 @@ import textwrap import pytest import numpy as np -import pandas +import pandas as pd import validate_docstrings validate_one = validate_docstrings.validate_one @@ -1008,9 +1008,9 @@ def test_item_subsection(self, idx, subsection): class TestDocstringClass(object): @pytest.mark.parametrize('name, expected_obj', - [('pandas.isnull', pandas.isnull), - ('pandas.DataFrame', pandas.DataFrame), - ('pandas.Series.sum', pandas.Series.sum)]) + [('pandas.isnull', pd.isnull), + ('pandas.DataFrame', pd.DataFrame), + ('pandas.Series.sum', pd.Series.sum)]) def test_resolves_class_name(self, name, expected_obj): d = validate_docstrings.Docstring(name) assert d.obj is expected_obj From f4704ea3f74b366d5d1e8b48c2d7e80d2edbfa54 Mon Sep 17 00:00:00 2001 From: Nicholas Musolino Date: Wed, 27 Feb 2019 22:06:15 -0500 Subject: [PATCH 6/7] Match AttributeError raised by getattr per review --- scripts/tests/test_validate_docstrings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 041d2e8f3bfac..f8ea891d43020 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1027,7 +1027,10 @@ def test_raises_for_invalid_module_name(self, invalid_name): ['pandas.BadClassName', 'pandas.Series.bad_method_name']) def test_raises_for_invalid_attribute_name(self, invalid_name): - with pytest.raises(AttributeError): + name_components = invalid_name.split('.') + obj_name, invalid_attr_name = name_components[-2], name_components[-1] + msg = "'{}' has no attribute '{}'".format(obj_name, invalid_attr_name) + with pytest.raises(AttributeError, match=msg): validate_docstrings.Docstring(invalid_name) From 1b1ee481e4bf0db4d462bac14413160f0c70aac7 Mon Sep 17 00:00:00 2001 From: William Ayd Date: Wed, 27 Feb 2019 19:10:37 -0800 Subject: [PATCH 7/7] Update test_validate_docstrings.py Minor tweaks --- scripts/tests/test_validate_docstrings.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index f8ea891d43020..09fb5a30cbc3b 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1017,9 +1017,7 @@ def test_resolves_class_name(self, name, expected_obj): @pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame']) def test_raises_for_invalid_module_name(self, invalid_name): - # When an invalid module name is supplied, an ImportError should be - # raised, and the message should contain the user-supplied name. - msg = 'No module can be imported.*{}'.format(invalid_name) + msg = 'No module can be imported from "{}"'.format(invalid_name) with pytest.raises(ImportError, match=msg): validate_docstrings.Docstring(invalid_name)