diff options
| author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2023-01-09 12:59:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-09 11:59:42 +0000 |
| commit | e259af237ed140e7c15ad61483e92302b3e8ce14 (patch) | |
| tree | 43ebfe4f2602192b5c414d51c2a343edb43e2b47 | |
| parent | b717e99964bf9e601b0acb939865990e64da19ee (diff) | |
| download | astroid-git-e259af237ed140e7c15ad61483e92302b3e8ce14.tar.gz | |
Initial pass with ``pydocstringformatter`` over tests (#1949)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
29 files changed, 197 insertions, 252 deletions
diff --git a/tests/test_brain_regex.py b/tests/test_brain_regex.py index 55cc64c4..1fbd59b9 100644 --- a/tests/test_brain_regex.py +++ b/tests/test_brain_regex.py @@ -26,7 +26,7 @@ class TestRegexBrain: @test_utils.require_version(minver="3.9") def test_regex_pattern_and_match_subscriptable(self): - """Test regex.Pattern and regex.Match are subscriptable in PY39+""" + """Test regex.Pattern and regex.Match are subscriptable in PY39+.""" node1 = builder.extract_node( """ import regex diff --git a/tests/unittest_brain_ctypes.py b/tests/unittest_brain_ctypes.py index dbcf54d9..fe8b2541 100644 --- a/tests/unittest_brain_ctypes.py +++ b/tests/unittest_brain_ctypes.py @@ -57,8 +57,8 @@ pytestmark = pytest.mark.skipif( ], ) def test_ctypes_redefined_types_members(c_type, builtin_type, type_code): - """ - Test that the "value" and "_type_" member of each redefined types are correct + """Test that the "value" and "_type_" member of each redefined types are + correct. """ src = f""" import ctypes @@ -102,7 +102,8 @@ def test_cdata_member_access() -> None: def test_other_ctypes_member_untouched() -> None: """ - Test that other ctypes members, which are not touched by the brain, are correctly inferred + Test that other ctypes members, which are not touched by the brain, are correctly + inferred. """ src = """ import ctypes diff --git a/tests/unittest_brain_dataclasses.py b/tests/unittest_brain_dataclasses.py index b487d7d1..6de25b06 100644 --- a/tests/unittest_brain_dataclasses.py +++ b/tests/unittest_brain_dataclasses.py @@ -74,7 +74,8 @@ def test_inference_non_field_default(module: str): @parametrize_module def test_inference_field_default(module: str): """Test inference of dataclass attribute with a field call default - (default keyword argument given).""" + (default keyword argument given). + """ klass, instance = astroid.extract_node( f""" from {module} import dataclass @@ -105,7 +106,8 @@ def test_inference_field_default(module: str): @parametrize_module def test_inference_field_default_factory(module: str): """Test inference of dataclass attribute with a field call default - (default_factory keyword argument given).""" + (default_factory keyword argument given). + """ klass, instance = astroid.extract_node( f""" from {module} import dataclass @@ -406,7 +408,7 @@ def test_pydantic_field() -> None: @parametrize_module def test_init_empty(module: str): - """Test init for a dataclass with no attributes""" + """Test init for a dataclass with no attributes.""" node = astroid.extract_node( f""" from {module} import dataclass @@ -424,7 +426,7 @@ def test_init_empty(module: str): @parametrize_module def test_init_no_defaults(module: str): - """Test init for a dataclass with attributes and no defaults""" + """Test init for a dataclass with attributes and no defaults.""" node = astroid.extract_node( f""" from {module} import dataclass @@ -451,7 +453,7 @@ def test_init_no_defaults(module: str): @parametrize_module def test_init_defaults(module: str): - """Test init for a dataclass with attributes and some defaults""" + """Test init for a dataclass with attributes and some defaults.""" node = astroid.extract_node( f""" from {module} import dataclass @@ -486,7 +488,7 @@ def test_init_defaults(module: str): @parametrize_module def test_init_initvar(module: str): - """Test init for a dataclass with attributes and an InitVar""" + """Test init for a dataclass with attributes and an InitVar.""" node = astroid.extract_node( f""" from {module} import dataclass @@ -602,7 +604,8 @@ def test_init_override(module: str): @parametrize_module def test_init_attributes_from_superclasses(module: str): - """Test init for a dataclass that inherits and overrides attributes from superclasses. + """Test init for a dataclass that inherits and overrides attributes from + superclasses. Based on https://github.com/PyCQA/pylint/issues/3201 """ @@ -636,7 +639,9 @@ def test_init_attributes_from_superclasses(module: str): @parametrize_module def test_invalid_init(module: str): - """Test that astroid doesn't generate an initializer when attribute order is invalid.""" + """Test that astroid doesn't generate an initializer when attribute order is + invalid. + """ node = astroid.extract_node( f""" from {module} import dataclass @@ -655,7 +660,9 @@ def test_invalid_init(module: str): @parametrize_module def test_annotated_enclosed_field_call(module: str): - """Test inference of dataclass attribute with a field call in another function call""" + """Test inference of dataclass attribute with a field call in another function + call. + """ node = astroid.extract_node( f""" from {module} import dataclass, field diff --git a/tests/unittest_brain_numpy_core_einsumfunc.py b/tests/unittest_brain_numpy_core_einsumfunc.py index 7f91e3e1..593eeec2 100644 --- a/tests/unittest_brain_numpy_core_einsumfunc.py +++ b/tests/unittest_brain_numpy_core_einsumfunc.py @@ -29,9 +29,7 @@ def _inferred_numpy_func_call(func_name: str, *func_args: str) -> nodes.Function @pytest.mark.skipif(not HAS_NUMPY, reason="This test requires the numpy library.") def test_numpy_function_calls_inferred_as_ndarray() -> None: - """ - Test that calls to numpy functions are inferred as numpy.ndarray - """ + """Test that calls to numpy functions are inferred as numpy.ndarray.""" method = "einsum" inferred_values = list( _inferred_numpy_func_call(method, "ii, np.arange(25).reshape(5, 5)") diff --git a/tests/unittest_brain_numpy_core_fromnumeric.py b/tests/unittest_brain_numpy_core_fromnumeric.py index bbb6ba92..09589f58 100644 --- a/tests/unittest_brain_numpy_core_fromnumeric.py +++ b/tests/unittest_brain_numpy_core_fromnumeric.py @@ -16,9 +16,7 @@ from astroid import builder @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class BrainNumpyCoreFromNumericTest(unittest.TestCase): - """ - Test the numpy core fromnumeric brain module - """ + """Test the numpy core fromnumeric brain module.""" numpy_functions = (("sum", "[1, 2]"),) @@ -33,9 +31,7 @@ class BrainNumpyCoreFromNumericTest(unittest.TestCase): return node.infer() def test_numpy_function_calls_inferred_as_ndarray(self): - """ - Test that calls to numpy functions are inferred as numpy.ndarray - """ + """Test that calls to numpy functions are inferred as numpy.ndarray.""" licit_array_types = (".ndarray",) for func_ in self.numpy_functions: with self.subTest(typ=func_): diff --git a/tests/unittest_brain_numpy_core_function_base.py b/tests/unittest_brain_numpy_core_function_base.py index f0d561d6..f66fc940 100644 --- a/tests/unittest_brain_numpy_core_function_base.py +++ b/tests/unittest_brain_numpy_core_function_base.py @@ -16,9 +16,7 @@ from astroid import builder @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class BrainNumpyCoreFunctionBaseTest(unittest.TestCase): - """ - Test the numpy core numeric brain module - """ + """Test the numpy core numeric brain module.""" numpy_functions = ( ("linspace", "1, 100"), @@ -37,9 +35,7 @@ class BrainNumpyCoreFunctionBaseTest(unittest.TestCase): return node.infer() def test_numpy_function_calls_inferred_as_ndarray(self): - """ - Test that calls to numpy functions are inferred as numpy.ndarray - """ + """Test that calls to numpy functions are inferred as numpy.ndarray.""" licit_array_types = (".ndarray",) for func_ in self.numpy_functions: with self.subTest(typ=func_): diff --git a/tests/unittest_brain_numpy_core_multiarray.py b/tests/unittest_brain_numpy_core_multiarray.py index bbf24973..c4818a47 100644 --- a/tests/unittest_brain_numpy_core_multiarray.py +++ b/tests/unittest_brain_numpy_core_multiarray.py @@ -16,9 +16,7 @@ from astroid import builder @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class BrainNumpyCoreMultiarrayTest(unittest.TestCase): - """ - Test the numpy core multiarray brain module - """ + """Test the numpy core multiarray brain module.""" numpy_functions_returning_array = ( ("array", "[1, 2]"), @@ -82,9 +80,7 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase): return node.infer() def test_numpy_function_calls_inferred_as_ndarray(self): - """ - Test that calls to numpy functions are inferred as numpy.ndarray - """ + """Test that calls to numpy functions are inferred as numpy.ndarray.""" for infer_wrapper in ( self._inferred_numpy_func_call, self._inferred_numpy_no_alias_func_call, @@ -106,9 +102,7 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase): ) def test_numpy_function_calls_inferred_as_bool(self): - """ - Test that calls to numpy functions are inferred as bool - """ + """Test that calls to numpy functions are inferred as bool.""" for infer_wrapper in ( self._inferred_numpy_func_call, self._inferred_numpy_no_alias_func_call, @@ -130,9 +124,7 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase): ) def test_numpy_function_calls_inferred_as_dtype(self): - """ - Test that calls to numpy functions are inferred as numpy.dtype - """ + """Test that calls to numpy functions are inferred as numpy.dtype.""" for infer_wrapper in ( self._inferred_numpy_func_call, self._inferred_numpy_no_alias_func_call, @@ -154,9 +146,7 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase): ) def test_numpy_function_calls_inferred_as_none(self): - """ - Test that calls to numpy functions are inferred as None - """ + """Test that calls to numpy functions are inferred as None.""" for infer_wrapper in ( self._inferred_numpy_func_call, self._inferred_numpy_no_alias_func_call, @@ -178,9 +168,7 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase): ) def test_numpy_function_calls_inferred_as_tuple(self): - """ - Test that calls to numpy functions are inferred as tuple - """ + """Test that calls to numpy functions are inferred as tuple.""" for infer_wrapper in ( self._inferred_numpy_func_call, self._inferred_numpy_no_alias_func_call, diff --git a/tests/unittest_brain_numpy_core_numeric.py b/tests/unittest_brain_numpy_core_numeric.py index bc2b4902..e2b51fef 100644 --- a/tests/unittest_brain_numpy_core_numeric.py +++ b/tests/unittest_brain_numpy_core_numeric.py @@ -20,9 +20,7 @@ from astroid import builder @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class BrainNumpyCoreNumericTest(unittest.TestCase): - """ - Test the numpy core numeric brain module - """ + """Test the numpy core numeric brain module.""" numpy_functions = ( ("zeros_like", "[1, 2]"), @@ -42,9 +40,7 @@ class BrainNumpyCoreNumericTest(unittest.TestCase): return node.infer() def test_numpy_function_calls_inferred_as_ndarray(self): - """ - Test that calls to numpy functions are inferred as numpy.ndarray - """ + """Test that calls to numpy functions are inferred as numpy.ndarray.""" licit_array_types = (".ndarray",) for func_ in self.numpy_functions: with self.subTest(typ=func_): diff --git a/tests/unittest_brain_numpy_core_numerictypes.py b/tests/unittest_brain_numpy_core_numerictypes.py index 2ed91c1c..40679fc6 100644 --- a/tests/unittest_brain_numpy_core_numerictypes.py +++ b/tests/unittest_brain_numpy_core_numerictypes.py @@ -21,9 +21,7 @@ from astroid.brain.brain_numpy_utils import ( @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class NumpyBrainCoreNumericTypesTest(unittest.TestCase): - """ - Test of all the missing types defined in numerictypes module. - """ + """Test of all the missing types defined in numerictypes module.""" all_types = [ "uint16", @@ -87,18 +85,14 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): return next(node.value.infer()) def test_numpy_core_types(self): - """ - Test that all defined types have ClassDef type. - """ + """Test that all defined types have ClassDef type.""" for typ in self.all_types: with self.subTest(typ=typ): inferred = self._inferred_numpy_attribute(typ) self.assertIsInstance(inferred, nodes.ClassDef) def test_generic_types_have_methods(self): - """ - Test that all generic derived types have specified methods - """ + """Test that all generic derived types have specified methods.""" generic_methods = [ "all", "any", @@ -210,9 +204,7 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): self.assertTrue(meth in {m.name for m in inferred.methods()}) def test_generic_types_have_attributes(self): - """ - Test that all generic derived types have specified attributes - """ + """Test that all generic derived types have specified attributes.""" generic_attr = [ "base", "data", @@ -270,9 +262,7 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): self.assertNotEqual(len(inferred.getattr(attr)), 0) def test_number_types_have_unary_operators(self): - """ - Test that number types have unary operators - """ + """Test that number types have unary operators.""" unary_ops = ("__neg__",) for type_ in ( @@ -301,9 +291,7 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): self.assertNotEqual(len(inferred.getattr(attr)), 0) def test_array_types_have_unary_operators(self): - """ - Test that array types have unary operators - """ + """Test that array types have unary operators.""" unary_ops = ("__neg__", "__invert__") for type_ in ("ndarray",): @@ -346,9 +334,7 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): f"This test requires the numpy library with a version above {NUMPY_VERSION_TYPE_HINTS_SUPPORT}", ) def test_generic_types_are_subscriptables(self): - """ - Test that all types deriving from generic are subscriptables - """ + """Test that all types deriving from generic are subscriptables.""" for type_ in ( "bool_", "bytes_", @@ -401,19 +387,20 @@ class NumpyBrainCoreNumericTypesTest(unittest.TestCase): class NumpyBrainUtilsTest(unittest.TestCase): """ This class is dedicated to test that astroid does not crash - if numpy module is not available + if numpy module is not available. """ def test_get_numpy_version_do_not_crash(self): """ - Test that the function _get_numpy_version doesn't crash even if numpy is not installed + Test that the function _get_numpy_version doesn't crash even if numpy is not + installed. """ self.assertEqual(_get_numpy_version(), ("0", "0", "0")) def test_numpy_object_uninferable(self): """ Test that in case numpy is not available, then a numpy object is uninferable - but the inference doesn't lead to a crash + but the inference doesn't lead to a crash. """ src = """ import numpy as np diff --git a/tests/unittest_brain_numpy_core_umath.py b/tests/unittest_brain_numpy_core_umath.py index 27d79a92..9a03119d 100644 --- a/tests/unittest_brain_numpy_core_umath.py +++ b/tests/unittest_brain_numpy_core_umath.py @@ -16,9 +16,7 @@ from astroid import bases, builder, nodes @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class NumpyBrainCoreUmathTest(unittest.TestCase): - """ - Test of all members of numpy.core.umath module - """ + """Test of all members of numpy.core.umath module.""" one_arg_ufunc = ( "arccos", @@ -112,18 +110,14 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): return next(node.infer()) def test_numpy_core_umath_constants(self): - """ - Test that constants have Const type. - """ + """Test that constants have Const type.""" for const in self.constants: with self.subTest(const=const): inferred = self._inferred_numpy_attribute(const) self.assertIsInstance(inferred, nodes.Const) def test_numpy_core_umath_constants_values(self): - """ - Test the values of the constants. - """ + """Test the values of the constants.""" exact_values = {"e": 2.718281828459045, "euler_gamma": 0.5772156649015329} for const in self.constants: with self.subTest(const=const): @@ -131,18 +125,14 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): self.assertEqual(inferred.value, exact_values[const]) def test_numpy_core_umath_functions(self): - """ - Test that functions have FunctionDef type. - """ + """Test that functions have FunctionDef type.""" for func in self.all_ufunc: with self.subTest(func=func): inferred = self._inferred_numpy_attribute(func) self.assertIsInstance(inferred, bases.Instance) def test_numpy_core_umath_functions_one_arg(self): - """ - Test the arguments names of functions. - """ + """Test the arguments names of functions.""" exact_arg_names = [ "self", "x", @@ -161,9 +151,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): ) def test_numpy_core_umath_functions_two_args(self): - """ - Test the arguments names of functions. - """ + """Test the arguments names of functions.""" exact_arg_names = [ "self", "x1", @@ -183,9 +171,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): ) def test_numpy_core_umath_functions_kwargs_default_values(self): - """ - Test the default values for keyword arguments. - """ + """Test the default values for keyword arguments.""" exact_kwargs_default_values = [None, True, "same_kind", "K", None, True] for func in self.one_arg_ufunc + self.two_args_ufunc: with self.subTest(func=func): @@ -207,9 +193,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): return node.infer() def test_numpy_core_umath_functions_return_type(self): - """ - Test that functions which should return a ndarray do return it - """ + """Test that functions which should return a ndarray do return it.""" ndarray_returning_func = [ f for f in self.all_ufunc if f not in ("frexp", "modf") ] @@ -228,9 +212,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): ) def test_numpy_core_umath_functions_return_type_tuple(self): - """ - Test that functions which should return a pair of ndarray do return it - """ + """Test that functions which should return a pair of ndarray do return it.""" ndarray_returning_func = ("frexp", "modf") for func_ in ndarray_returning_func: diff --git a/tests/unittest_brain_numpy_ma.py b/tests/unittest_brain_numpy_ma.py index 7f7b36cb..1b6bbaea 100644 --- a/tests/unittest_brain_numpy_ma.py +++ b/tests/unittest_brain_numpy_ma.py @@ -16,9 +16,7 @@ from astroid import builder @pytest.mark.skipif(HAS_NUMPY is False, reason="This test requires the numpy library.") class TestBrainNumpyMa: - """ - Test the numpy ma brain module - """ + """Test the numpy ma brain module.""" def _assert_maskedarray(self, code): node = builder.extract_node(code) diff --git a/tests/unittest_brain_numpy_ndarray.py b/tests/unittest_brain_numpy_ndarray.py index fb216de4..1f778b0d 100644 --- a/tests/unittest_brain_numpy_ndarray.py +++ b/tests/unittest_brain_numpy_ndarray.py @@ -20,9 +20,7 @@ from astroid.brain.brain_numpy_utils import ( @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class NumpyBrainNdarrayTest(unittest.TestCase): - """ - Test that calls to numpy functions returning arrays are correctly inferred - """ + """Test that calls to numpy functions returning arrays are correctly inferred.""" ndarray_returning_ndarray_methods = ( "__abs__", @@ -127,9 +125,7 @@ class NumpyBrainNdarrayTest(unittest.TestCase): return node.infer() def test_numpy_function_calls_inferred_as_ndarray(self): - """ - Test that some calls to numpy functions are inferred as numpy.ndarray - """ + """Test that some calls to numpy functions are inferred as numpy.ndarray.""" licit_array_types = ".ndarray" for func_ in self.ndarray_returning_ndarray_methods: with self.subTest(typ=func_): @@ -144,9 +140,7 @@ class NumpyBrainNdarrayTest(unittest.TestCase): ) def test_numpy_ndarray_attribute_inferred_as_ndarray(self): - """ - Test that some numpy ndarray attributes are inferred as numpy.ndarray - """ + """Test that some numpy ndarray attributes are inferred as numpy.ndarray.""" licit_array_types = ".ndarray" for attr_ in ("real", "imag", "shape", "T"): with self.subTest(typ=attr_): @@ -165,9 +159,7 @@ class NumpyBrainNdarrayTest(unittest.TestCase): f"This test requires the numpy library with a version above {NUMPY_VERSION_TYPE_HINTS_SUPPORT}", ) def test_numpy_ndarray_class_support_type_indexing(self): - """ - Test that numpy ndarray class can be subscripted (type hints) - """ + """Test that numpy ndarray class can be subscripted (type hints).""" src = """ import numpy as np np.ndarray[int] diff --git a/tests/unittest_brain_numpy_random_mtrand.py b/tests/unittest_brain_numpy_random_mtrand.py index beb8fb6e..665d1de4 100644 --- a/tests/unittest_brain_numpy_random_mtrand.py +++ b/tests/unittest_brain_numpy_random_mtrand.py @@ -16,9 +16,7 @@ from astroid import builder, nodes @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") class NumpyBrainRandomMtrandTest(unittest.TestCase): - """ - Test of all the functions of numpy.random.mtrand module. - """ + """Test of all the functions of numpy.random.mtrand module.""" # Map between functions names and arguments names and default values all_mtrand = { @@ -82,18 +80,14 @@ class NumpyBrainRandomMtrandTest(unittest.TestCase): return next(node.infer()) def test_numpy_random_mtrand_functions(self): - """ - Test that all functions have FunctionDef type. - """ + """Test that all functions have FunctionDef type.""" for func in self.all_mtrand: with self.subTest(func=func): inferred = self._inferred_numpy_attribute(func) self.assertIsInstance(inferred, nodes.FunctionDef) def test_numpy_random_mtrand_functions_signature(self): - """ - Test the arguments names and default values. - """ + """Test the arguments names and default values.""" for ( func, (exact_arg_names, exact_kwargs_default_values), diff --git a/tests/unittest_brain_qt.py b/tests/unittest_brain_qt.py index 7e10db70..2d029e02 100644 --- a/tests/unittest_brain_qt.py +++ b/tests/unittest_brain_qt.py @@ -20,7 +20,7 @@ class TestBrainQt: @staticmethod def test_value_of_lambda_instance_attrs_is_list(): - """Regression test for https://github.com/PyCQA/pylint/issues/6221 + """Regression test for https://github.com/PyCQA/pylint/issues/6221. A crash occurred in pylint when a nodes.FunctionDef was iterated directly, giving items like "self" instead of iterating a one-element list containing @@ -40,7 +40,7 @@ class TestBrainQt: @staticmethod def test_implicit_parameters() -> None: - """Regression test for https://github.com/PyCQA/pylint/issues/6464""" + """Regression test for https://github.com/PyCQA/pylint/issues/6464.""" src = """ from PyQt6.QtCore import QTimer timer = QTimer() diff --git a/tests/unittest_brain_unittest.py b/tests/unittest_brain_unittest.py index d8d638a3..111d9856 100644 --- a/tests/unittest_brain_unittest.py +++ b/tests/unittest_brain_unittest.py @@ -9,9 +9,7 @@ from astroid.test_utils import require_version class UnittestTest(unittest.TestCase): - """ - A class that tests the brain_unittest module - """ + """A class that tests the brain_unittest module.""" @require_version(minver="3.8.0") def test_isolatedasynciotestcase(self): diff --git a/tests/unittest_builder.py b/tests/unittest_builder.py index 63b06a6c..cd165966 100644 --- a/tests/unittest_builder.py +++ b/tests/unittest_builder.py @@ -2,7 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""tests for the astroid builder and rebuilder module""" +"""Tests for the astroid builder and rebuilder module.""" import collections import importlib @@ -428,7 +428,7 @@ class BuilderTest(unittest.TestCase): self.builder.string_build('"\\x1"') def test_missing_newline(self) -> None: - """check that a file with no trailing new line is parseable""" + """Check that a file with no trailing new line is parseable.""" resources.build_file("data/noendingnewline.py") def test_missing_file(self) -> None: @@ -436,7 +436,7 @@ class BuilderTest(unittest.TestCase): resources.build_file("data/inexistent.py") def test_inspect_build0(self) -> None: - """test astroid tree build from a living object""" + """Test astroid tree build from a living object.""" builtin_ast = self.manager.ast_from_module_name("builtins") # just check type and object are there builtin_ast.getattr("type") @@ -495,7 +495,7 @@ class BuilderTest(unittest.TestCase): self.manager.unregister_transform(nodes.Module, transform_time) def test_package_name(self) -> None: - """test base properties and method of an astroid module""" + """Test base properties and method of an astroid module.""" datap = resources.build_file("data/__init__.py", "data") self.assertEqual(datap.name, "data") self.assertEqual(datap.package, 1) @@ -507,7 +507,7 @@ class BuilderTest(unittest.TestCase): self.assertEqual(datap.package, 0) def test_yield_parent(self) -> None: - """check if we added discard nodes as yield parent (w/ compiler)""" + """Check if we added discard nodes as yield parent (w/ compiler).""" code = """ def yiell(): #@ yield 0 @@ -720,7 +720,7 @@ class BuilderTest(unittest.TestCase): self.assertIn("body", astroid["visit_if"].locals) def test_build_constants(self) -> None: - """test expected values of constants after rebuilding""" + """Test expected values of constants after rebuilding.""" code = """ def func(): return None @@ -759,7 +759,7 @@ class FileBuildTest(unittest.TestCase): self.module = resources.build_file("data/module.py", "data.module") def test_module_base_props(self) -> None: - """test base properties and method of an astroid module""" + """Test base properties and method of an astroid module.""" module = self.module self.assertEqual(module.name, "data.module") with pytest.warns(DeprecationWarning) as records: @@ -783,7 +783,7 @@ class FileBuildTest(unittest.TestCase): module.statement(future=True) def test_module_locals(self) -> None: - """test the 'locals' dictionary of an astroid module""" + """Test the 'locals' dictionary of an astroid module.""" module = self.module _locals = module.locals self.assertIs(_locals, module.globals) @@ -804,7 +804,7 @@ class FileBuildTest(unittest.TestCase): self.assertEqual(keys, sorted(should)) def test_function_base_props(self) -> None: - """test base properties and method of an astroid function""" + """Test base properties and method of an astroid function.""" module = self.module function = module["global_access"] self.assertEqual(function.name, "global_access") @@ -824,14 +824,14 @@ class FileBuildTest(unittest.TestCase): self.assertEqual(function.type, "function") def test_function_locals(self) -> None: - """test the 'locals' dictionary of an astroid function""" + """Test the 'locals' dictionary of an astroid function.""" _locals = self.module["global_access"].locals self.assertEqual(len(_locals), 4) keys = sorted(_locals.keys()) self.assertEqual(keys, ["i", "key", "local", "val"]) def test_class_base_props(self) -> None: - """test base properties and method of an astroid class""" + """Test base properties and method of an astroid class.""" module = self.module klass = module["YO"] self.assertEqual(klass.name, "YO") @@ -851,7 +851,7 @@ class FileBuildTest(unittest.TestCase): self.assertTrue(klass.newstyle) def test_class_locals(self) -> None: - """test the 'locals' dictionary of an astroid class""" + """Test the 'locals' dictionary of an astroid class.""" module = self.module klass1 = module["YO"] locals1 = klass1.locals @@ -887,7 +887,7 @@ class FileBuildTest(unittest.TestCase): self.assertEqual(klass2.basenames, ["YO"]) def test_method_base_props(self) -> None: - """test base properties and method of an astroid method""" + """Test base properties and method of an astroid method.""" klass2 = self.module["YOUPI"] # "normal" method method = klass2["method"] @@ -910,7 +910,7 @@ class FileBuildTest(unittest.TestCase): self.assertEqual(method.type, "staticmethod") def test_method_locals(self) -> None: - """test the 'locals' dictionary of an astroid method""" + """Test the 'locals' dictionary of an astroid method.""" method = self.module["YOUPI"]["method"] _locals = method.locals keys = sorted(_locals) @@ -924,7 +924,9 @@ class FileBuildTest(unittest.TestCase): def test_module_build_dunder_file() -> None: - """Test that module_build() can work with modules that have the *__file__* attribute""" + """Test that module_build() can work with modules that have the *__file__* + attribute. + """ module = builder.AstroidBuilder().module_build(collections) assert module.path[0] == collections.__file__ @@ -969,7 +971,7 @@ def test_arguments_of_signature() -> None: class HermeticInterpreterTest(unittest.TestCase): - """Modeled on https://github.com/PyCQA/astroid/pull/1207#issuecomment-951455588""" + """Modeled on https://github.com/PyCQA/astroid/pull/1207#issuecomment-951455588.""" @classmethod def setUpClass(cls): @@ -1004,6 +1006,7 @@ class HermeticInterpreterTest(unittest.TestCase): def test_build_from_live_module_without_source_file(self) -> None: """Assert that inspect_build() is not called. + See comment in module_build() before the call to inspect_build(): "get a partial representation by introspection" diff --git a/tests/unittest_constraint.py b/tests/unittest_constraint.py index cba506fd..ab2b4ad1 100644 --- a/tests/unittest_constraint.py +++ b/tests/unittest_constraint.py @@ -2,7 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""Tests for inference involving constraints""" +"""Tests for inference involving constraints.""" from __future__ import annotations import pytest @@ -58,7 +58,9 @@ def test_if_single_statement( def test_if_multiple_statements( condition: str, satisfy_val: int | None, fail_val: int | None ) -> None: - """Test constraint for a variable that is used in an if body with multiple statements.""" + """Test constraint for a variable that is used in an if body with multiple + statements. + """ node1, node2 = builder.extract_node( f""" def f1(x = {fail_val}): @@ -185,7 +187,9 @@ def test_nested_if( def test_if_uninferable() -> None: - """Test that when no inferred values satisfy all constraints, Uninferable is inferred.""" + """Test that when no inferred values satisfy all constraints, Uninferable is + inferred. + """ node1, node2 = builder.extract_node( """ def f1(): @@ -505,7 +509,9 @@ def test_if_instance_attr_varname_collision1( def test_if_instance_attr_varname_collision2( condition: str, satisfy_val: int | None, fail_val: int | None ) -> None: - """Test that constraint in an if condition doesn't apply to a variable with the same name.""" + """Test that constraint in an if condition doesn't apply to a variable with the same + name. + """ node1, node2 = builder.extract_node( f""" class A1: diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index fc799ee9..13514570 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -2,7 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""Tests for the astroid inference capabilities""" +"""Tests for the astroid inference capabilities.""" from __future__ import annotations @@ -1133,7 +1133,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertIsInstance(inferred[0].elts[1], nodes.List) def test_binary_op_list_mul_none(self) -> None: - "test correct handling on list multiplied by None" + """Test correct handling on list multiplied by None.""" ast = builder.string_build('a = [1] * None\nb = [1] * "r"') inferred = ast["a"].inferred() self.assertEqual(len(inferred), 1) @@ -1143,7 +1143,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(inferred[0], util.Uninferable) def test_binary_op_list_mul_int(self) -> None: - "test correct handling on list multiplied by int when there are more than one" + """Test correct handling on list multiplied by int when there are more than one.""" code = """ from ctypes import c_int seq = [c_int()] * 4 @@ -1156,7 +1156,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(len(listval.itered()), 4) def test_binary_op_on_self(self) -> None: - "test correct handling of applying binary operator to self" + """Test correct handling of applying binary operator to self.""" code = """ import sys sys.path = ['foo'] + sys.path @@ -1232,7 +1232,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(inferred[0], util.Uninferable) def test_nonregr_instance_attrs(self) -> None: - """non regression for instance_attrs infinite loop : pylint / #4""" + """Non regression for instance_attrs infinite loop : pylint / #4.""" code = """ class Foo(object): @@ -1275,7 +1275,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): def test_nonregr_layed_dictunpack(self) -> None: """Regression test for https://github.com/PyCQA/astroid/issues/483 - Make sure multiple dictunpack references are inferable + Make sure multiple dictunpack references are inferable. """ code = """ base = {'data': 0} @@ -1287,7 +1287,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertIsInstance(ass.inferred()[0], nodes.Dict) def test_nonregr_inference_modifying_col_offset(self) -> None: - """Make sure inference doesn't improperly modify col_offset + """Make sure inference doesn't improperly modify col_offset. Regression test for https://github.com/PyCQA/pylint/issues/1839 """ @@ -1305,7 +1305,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(cdef.col_offset, orig_offset) def test_no_runtime_error_in_repeat_inference(self) -> None: - """Stop repeat inference attempt causing a RuntimeError in Python3.7 + """Stop repeat inference attempt causing a RuntimeError in Python3.7. See https://github.com/PyCQA/pylint/issues/2317 """ @@ -1469,7 +1469,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.fail(f"expected to find an instance of Application in {inferred}") def test_list_inference(self) -> None: - """#20464""" code = """ from unknown import Unknown A = [] @@ -2071,7 +2070,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertInferDict(node, expected_value) def test_dict_inference_unpack_repeated_key(self) -> None: - """Make sure astroid does not infer repeated keys in a dictionary + """Make sure astroid does not infer repeated keys in a dictionary. Regression test for https://github.com/PyCQA/pylint/issues/1843 """ @@ -2397,7 +2396,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertRaises(InferenceError, next, module["no_yield"].infer()) def test_nested_contextmanager(self) -> None: - """Make sure contextmanager works with nested functions + """Make sure contextmanager works with nested functions. Previously contextmanager would retrieve the first yield instead of the yield in the @@ -4066,7 +4065,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): def test_metaclass_custom_dunder_call(self) -> None: """The Metaclass __call__ should take precedence - over the default metaclass type call (initialization) + over the default metaclass type call (initialization). See https://github.com/PyCQA/pylint/issues/2159 """ @@ -4089,7 +4088,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): assert val == 1 def test_metaclass_custom_dunder_call_boundnode(self) -> None: - """The boundnode should be the calling class""" + """The boundnode should be the calling class.""" cls = extract_node( """ class _Meta(type): @@ -5199,11 +5198,10 @@ class ObjectDunderNewTest(unittest.TestCase): def test_augassign_recursion() -> None: - """Make sure inference doesn't throw a RecursionError + """Make sure inference doesn't throw a RecursionError. Regression test for augmented assign dropping context.path causing recursion errors - """ # infinitely recurses in python code = """ @@ -5361,7 +5359,7 @@ def test_unpacking_starred_empty_list_in_assignment() -> None: def test_regression_infinite_loop_decorator() -> None: """Make sure decorators with the same names - as a decorated method do not cause an infinite loop + as a decorated method do not cause an infinite loop. See https://github.com/PyCQA/astroid/issues/375 """ @@ -5400,7 +5398,7 @@ def test_stop_iteration_in_int() -> None: def test_call_on_instance_with_inherited_dunder_call_method() -> None: - """Stop inherited __call__ method from incorrectly returning wrong class + """Stop inherited __call__ method from incorrectly returning wrong class. See https://github.com/PyCQA/pylint/issues/2199 """ @@ -5425,7 +5423,8 @@ def test_call_on_instance_with_inherited_dunder_call_method() -> None: class TestInferencePropagation: """Make sure function argument values are properly - propagated to sub functions""" + propagated to sub functions. + """ @pytest.mark.xfail(reason="Relying on path copy") def test_call_context_propagation(self): @@ -5723,7 +5722,7 @@ def test_compare_unknown() -> None: def test_limit_inference_result_amount() -> None: - """Test setting limit inference result amount""" + """Test setting limit inference result amount.""" code = """ args = [] @@ -5752,7 +5751,7 @@ def test_limit_inference_result_amount() -> None: def test_attribute_inference_should_not_access_base_classes() -> None: - """attributes of classes should mask ancestor attributes""" + """Attributes of classes should mask ancestor attributes.""" code = """ type.__new__ #@ """ @@ -5762,9 +5761,7 @@ def test_attribute_inference_should_not_access_base_classes() -> None: def test_attribute_mro_object_inference() -> None: - """ - Inference should only infer results from the first available method - """ + """Inference should only infer results from the first available method.""" inferred = extract_node( """ class A: @@ -6703,7 +6700,7 @@ def test_issue926_binop_referencing_same_name_is_not_uninferable() -> None: def test_pylint_issue_4692_attribute_inference_error_in_infer_import_from() -> None: - """https://github.com/PyCQA/pylint/issues/4692""" + """Https://github.com/PyCQA/pylint/issues/4692.""" code = """ import click @@ -6738,19 +6735,21 @@ b def test_namespace_package() -> None: - """check that a file using namespace packages and relative imports is parseable""" + """Check that a file using namespace packages and relative imports is parseable.""" resources.build_file("data/beyond_top_level/import_package.py") def test_namespace_package_same_name() -> None: - """check that a file using namespace packages and relative imports - with similar names is parseable""" + """Check that a file using namespace packages and relative imports + with similar names is parseable. + """ resources.build_file("data/beyond_top_level_two/a.py") def test_relative_imports_init_package() -> None: - """check that relative imports within a package that uses __init__.py - still works""" + """Check that relative imports within a package that uses __init__.py + still works. + """ resources.build_file( "data/beyond_top_level_three/module/sub_module/sub_sub_module/main.py" ) @@ -6766,7 +6765,8 @@ def test_inference_of_items_on_module_dict() -> None: def test_imported_module_var_inferable() -> None: """ - Module variables can be imported and inferred successfully as part of binary operators. + Module variables can be imported and inferred successfully as part of binary + operators. """ mod1 = parse( textwrap.dedent( diff --git a/tests/unittest_inference_calls.py b/tests/unittest_inference_calls.py index 61f57eb0..72afb989 100644 --- a/tests/unittest_inference_calls.py +++ b/tests/unittest_inference_calls.py @@ -2,14 +2,14 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""Tests for function call inference""" +"""Tests for function call inference.""" from astroid import bases, builder, nodes from astroid.util import Uninferable def test_no_return() -> None: - """Test function with no return statements""" + """Test function with no return statements.""" node = builder.extract_node( """ def f(): @@ -25,7 +25,7 @@ def test_no_return() -> None: def test_one_return() -> None: - """Test function with a single return that always executes""" + """Test function with a single return that always executes.""" node = builder.extract_node( """ def f(): @@ -42,7 +42,7 @@ def test_one_return() -> None: def test_one_return_possible() -> None: - """Test function with a single return that only sometimes executes + """Test function with a single return that only sometimes executes. Note: currently, inference doesn't handle this type of control flow """ @@ -63,7 +63,7 @@ def test_one_return_possible() -> None: def test_multiple_returns() -> None: - """Test function with multiple returns""" + """Test function with multiple returns.""" node = builder.extract_node( """ def f(x): @@ -85,7 +85,7 @@ def test_multiple_returns() -> None: def test_argument() -> None: - """Test function whose return value uses its arguments""" + """Test function whose return value uses its arguments.""" node = builder.extract_node( """ def f(x, y): @@ -102,7 +102,7 @@ def test_argument() -> None: def test_inner_call() -> None: - """Test function where return value is the result of a separate function call""" + """Test function where return value is the result of a separate function call.""" node = builder.extract_node( """ def f(): diff --git a/tests/unittest_lookup.py b/tests/unittest_lookup.py index b0646a76..835b315e 100644 --- a/tests/unittest_lookup.py +++ b/tests/unittest_lookup.py @@ -2,8 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""tests for the astroid variable lookup capabilities -""" +"""Tests for the astroid variable lookup capabilities.""" import functools import unittest @@ -155,7 +154,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(xnames[2].lookup("i")[1][0].lineno, 4) def test_list_comp_target(self) -> None: - """test the list comprehension target""" + """Test the list comprehension target.""" astroid = builder.parse( """ ten = [ var for var in range(10) ] @@ -466,7 +465,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase): class LookupControlFlowTest(unittest.TestCase): - """Tests for lookup capabilities and control flow""" + """Tests for lookup capabilities and control flow.""" def test_consecutive_assign(self) -> None: """When multiple assignment statements are in the same block, only the last one @@ -495,7 +494,7 @@ class LookupControlFlowTest(unittest.TestCase): self.assertEqual(len(stmts), 0) def test_del_removes_prior(self) -> None: - """Delete statement removes any prior assignments""" + """Delete statement removes any prior assignments.""" code = """ x = 10 del x @@ -507,7 +506,7 @@ class LookupControlFlowTest(unittest.TestCase): self.assertEqual(len(stmts), 0) def test_del_no_effect_after(self) -> None: - """Delete statement doesn't remove future assignments""" + """Delete statement doesn't remove future assignments.""" code = """ x = 10 del x @@ -626,7 +625,9 @@ class LookupControlFlowTest(unittest.TestCase): def test_if_else(self) -> None: """When an assignment statement appears in both an if and else branch, both - are added. This does NOT replace an assignment statement appearing before the + are added. + + This does NOT replace an assignment statement appearing before the if statement. (See issue #213) """ code = """ diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py index dc59a4d8..f35b94ec 100644 --- a/tests/unittest_manager.py +++ b/tests/unittest_manager.py @@ -154,7 +154,7 @@ class AstroidManagerTest( side_effect=AttributeError, ) def test_module_unexpectedly_missing_path(self, mocked) -> None: - """https://github.com/PyCQA/pylint/issues/7592""" + """Https://github.com/PyCQA/pylint/issues/7592.""" self.assertFalse(util.is_namespace("astroid")) def test_module_unexpectedly_spec_is_none(self) -> None: @@ -278,25 +278,25 @@ class AstroidManagerTest( os.remove(linked_file_name) def test_zip_import_data(self) -> None: - """check if zip_import_data works""" + """Check if zip_import_data works.""" with self._restore_package_cache(): filepath = resources.find("data/MyPyPa-0.1.0-py2.5.zip/mypypa") ast = self.manager.zip_import_data(filepath) self.assertEqual(ast.name, "mypypa") def test_zip_import_data_without_zipimport(self) -> None: - """check if zip_import_data return None without zipimport""" + """Check if zip_import_data return None without zipimport.""" self.assertEqual(self.manager.zip_import_data("path"), None) def test_file_from_module(self) -> None: - """check if the unittest filepath is equals to the result of the method""" + """Check if the unittest filepath is equals to the result of the method.""" self.assertEqual( _get_file_from_object(unittest), self.manager.file_from_module_name("unittest", None).location, ) def test_file_from_module_name_astro_building_exception(self) -> None: - """check if the method raises an exception with a wrong module name""" + """Check if the method raises an exception with a wrong module name.""" self.assertRaises( AstroidBuildingError, self.manager.file_from_module_name, @@ -311,7 +311,7 @@ class AstroidManagerTest( self.assertEqual(ast.pure_python, False) def test_ast_from_module_cache(self) -> None: - """check if the module is in the cache manager""" + """Check if the module is in the cache manager.""" ast = self.manager.ast_from_module(unittest) self.assertEqual(ast.name, "unittest") self.assertIn("unittest", self.manager.astroid_cache) @@ -329,7 +329,7 @@ class AstroidManagerTest( self.assertIn("__setattr__", ast) def test_ast_from_class_with_module(self) -> None: - """check if the method works with the module name""" + """Check if the method works with the module name.""" ast = self.manager.ast_from_class(int, int.__module__) self.assertEqual(ast.name, "int") self.assertEqual(ast.parent.frame().name, "builtins") @@ -342,7 +342,7 @@ class AstroidManagerTest( self.assertIn("__setattr__", ast) def test_ast_from_class_attr_error(self) -> None: - """give a wrong class at the ast_from_class method""" + """Give a wrong class at the ast_from_class method.""" self.assertRaises(AstroidBuildingError, self.manager.ast_from_class, None) def test_failed_import_hooks(self) -> None: @@ -385,8 +385,9 @@ class AstroidManagerTest( class BorgAstroidManagerTC(unittest.TestCase): def test_borg(self) -> None: - """test that the AstroidManager is really a borg, i.e. that two different - instances has same cache""" + """Test that the AstroidManager is really a borg, i.e. that two different + instances has same cache. + """ first_manager = manager.AstroidManager() built = first_manager.ast_from_module_name("builtins") diff --git a/tests/unittest_modutils.py b/tests/unittest_modutils.py index 6f8d8033..ab1acaac 100644 --- a/tests/unittest_modutils.py +++ b/tests/unittest_modutils.py @@ -2,9 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -""" -unit tests for module modutils (module manipulation utilities) -""" +"""Unit tests for module modutils (module manipulation utilities).""" import email import logging import os @@ -68,7 +66,7 @@ class ModuleFileTest(unittest.TestCase): class LoadModuleFromNameTest(unittest.TestCase): - """load a python module from its name""" + """Load a python module from its name.""" def test_known_values_load_module_from_name_1(self) -> None: self.assertEqual(modutils.load_module_from_name("sys"), sys) @@ -115,7 +113,7 @@ def test_import_dotted_library( class GetModulePartTest(unittest.TestCase): - """given a dotted name return the module part of the name""" + """Given a dotted name return the module part of the name.""" def test_known_values_get_module_part_1(self) -> None: self.assertEqual( @@ -129,7 +127,7 @@ class GetModulePartTest(unittest.TestCase): ) def test_known_values_get_module_part_3(self) -> None: - """relative import from given file""" + """Relative import from given file.""" self.assertEqual( modutils.get_module_part("nodes.node_classes.AssName", modutils.__file__), "nodes.node_classes", @@ -150,7 +148,7 @@ class GetModulePartTest(unittest.TestCase): class ModPathFromFileTest(unittest.TestCase): - """given an absolute file path return the python module's path as a list""" + """Given an absolute file path return the python module's path as a list.""" def test_known_values_modpath_from_file_1(self) -> None: self.assertEqual( @@ -291,8 +289,8 @@ class GetSourceFileTest(unittest.TestCase): class StandardLibModuleTest(resources.SysPathSetup, unittest.TestCase): """ - return true if the module may be considered as a module from the standard - library + Return true if the module may be considered as a module from the standard + library. """ def test_datetime(self) -> None: @@ -395,7 +393,7 @@ class GetModuleFilesTest(unittest.TestCase): self.assertEqual(modules, {os.path.join(package, x) for x in expected}) def test_get_all_files(self) -> None: - """test that list_all returns all Python files from given location""" + """Test that list_all returns all Python files from given location.""" non_package = resources.find("data/notamodule") modules = modutils.get_module_files(non_package, [], list_all=True) self.assertEqual(modules, [os.path.join(non_package, "file.py")]) diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py index 5cb3310b..e0ef9167 100644 --- a/tests/unittest_nodes.py +++ b/tests/unittest_nodes.py @@ -2,8 +2,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""tests for specific behaviour of astroid nodes -""" +"""Tests for specific behaviour of astroid nodes.""" from __future__ import annotations @@ -115,19 +114,19 @@ class AsStringTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(ast.as_string(), "raise_string(*args, **kwargs)") def test_module_as_string(self) -> None: - """check as_string on a whole module prepared to be returned identically""" + """Check as_string on a whole module prepared to be returned identically.""" module = resources.build_file("data/module.py", "data.module") with open(resources.find("data/module.py"), encoding="utf-8") as fobj: self.assertMultiLineEqual(module.as_string(), fobj.read()) def test_module2_as_string(self) -> None: - """check as_string on a whole module prepared to be returned identically""" + """Check as_string on a whole module prepared to be returned identically.""" module2 = resources.build_file("data/module2.py", "data.module2") with open(resources.find("data/module2.py"), encoding="utf-8") as fobj: self.assertMultiLineEqual(module2.as_string(), fobj.read()) def test_as_string(self) -> None: - """check as_string for python syntax >= 2.7""" + """Check as_string for python syntax >= 2.7.""" code = """one_two = {1, 2} b = {v: k for (k, v) in enumerate('string')} cdd = {k for k in b}\n\n""" @@ -135,7 +134,7 @@ cdd = {k for k in b}\n\n""" self.assertMultiLineEqual(ast.as_string(), code) def test_3k_as_string(self) -> None: - """check as_string for python 3k syntax""" + """Check as_string for python 3k syntax.""" code = """print() def function(var): @@ -223,7 +222,7 @@ y = (3).imag def check_as_string_ast_equality(code: str) -> None: """ Check that as_string produces source code with exactly the same - semantics as the source it was originally parsed from + semantics as the source it was originally parsed from. """ pre = builder.parse(code) post = builder.parse(pre.as_string()) @@ -286,7 +285,7 @@ everything = f""" " \' \r \t \\ {{ }} {'x' + x!r:a} {["'"]!s:{a}}""" class _NodeTest(unittest.TestCase): - """test transformation of If Node""" + """Test transformation of If Node.""" CODE = "" @@ -301,7 +300,7 @@ class _NodeTest(unittest.TestCase): class IfNodeTest(_NodeTest): - """test transformation of If Node""" + """Test transformation of If Node.""" CODE = """ if 0: @@ -328,7 +327,7 @@ class IfNodeTest(_NodeTest): """ def test_if_elif_else_node(self) -> None: - """test transformation for If node""" + """Test transformation for If node.""" self.assertEqual(len(self.astroid.body), 4) for stmt in self.astroid.body: self.assertIsInstance(stmt, nodes.If) @@ -656,16 +655,14 @@ class ConstNodeTest(unittest.TestCase): assert node.value.kind, "u" def test_copy(self) -> None: - """ - Make sure copying a Const object doesn't result in infinite recursion - """ + """Make sure copying a Const object doesn't result in infinite recursion.""" const = copy.copy(nodes.Const(1)) assert const.value == 1 class NameNodeTest(unittest.TestCase): def test_assign_to_true(self) -> None: - """Test that True and False assignments don't crash""" + """Test that True and False assignments don't crash.""" code = """ True = False def hello(False): @@ -678,7 +675,7 @@ class NameNodeTest(unittest.TestCase): @pytest.mark.skipif(not PY38_PLUS, reason="needs assignment expressions") class TestNamedExprNode: - """Tests for the NamedExpr node""" + """Tests for the NamedExpr node.""" @staticmethod def test_frame() -> None: @@ -1214,7 +1211,7 @@ class ContextTest(unittest.TestCase): def test_unknown() -> None: - """Test Unknown node""" + """Test Unknown node.""" assert isinstance(next(nodes.Unknown().infer()), type(util.Uninferable)) assert isinstance(nodes.Unknown().name, str) assert isinstance(nodes.Unknown().qname(), str) @@ -1481,7 +1478,7 @@ class AsyncGeneratorTest: def test_f_string_correct_line_numbering() -> None: - """Test that we generate correct line numbers for f-strings""" + """Test that we generate correct line numbers for f-strings.""" node = astroid.extract_node( """ def func_foo(arg_bar, arg_foo): diff --git a/tests/unittest_nodes_lineno.py b/tests/unittest_nodes_lineno.py index 2cc8094d..9e6a4908 100644 --- a/tests/unittest_nodes_lineno.py +++ b/tests/unittest_nodes_lineno.py @@ -16,7 +16,9 @@ from astroid.const import IS_PYPY, PY38, PY38_PLUS, PY39_PLUS, PY310_PLUS reason="end_lineno and end_col_offset were added in PY38", ) class TestEndLinenoNotSet: - """Test 'end_lineno' and 'end_col_offset' are initialized as 'None' for Python < 3.8.""" + """Test 'end_lineno' and 'end_col_offset' are initialized as 'None' for Python < + 3.8. + """ @staticmethod def test_end_lineno_not_set() -> None: @@ -45,7 +47,9 @@ class TestEndLinenoNotSet: reason="end_lineno and end_col_offset were added in PY38", ) class TestLinenoColOffset: - """Test 'lineno', 'col_offset', 'end_lineno', and 'end_col_offset' for all nodes.""" + """Test 'lineno', 'col_offset', 'end_lineno', and 'end_col_offset' for all + nodes. + """ @staticmethod def test_end_lineno_container() -> None: @@ -1232,7 +1236,7 @@ class TestLinenoColOffset: @staticmethod def test_end_lineno_module() -> None: - """Tests for Module""" + """Tests for Module.""" code = """print()""" module = astroid.parse(code) assert isinstance(module, nodes.Module) diff --git a/tests/unittest_object_model.py b/tests/unittest_object_model.py index 9d412b78..732593d9 100644 --- a/tests/unittest_object_model.py +++ b/tests/unittest_object_model.py @@ -394,8 +394,7 @@ class FunctionModelTest(unittest.TestCase): next(node.infer()) def test_descriptor_error_regression(self) -> None: - """Make sure the following code does - node cause an exception""" + """Make sure the following code does node cause an exception.""" node = builder.extract_node( """ class MyClass: diff --git a/tests/unittest_objects.py b/tests/unittest_objects.py index ef553727..6e62d7df 100644 --- a/tests/unittest_objects.py +++ b/tests/unittest_objects.py @@ -541,7 +541,7 @@ class SuperTests(unittest.TestCase): def test_super_qname(self) -> None: """Make sure a Super object generates a qname - equivalent to super.__qname__ + equivalent to super.__qname__. """ # See issue 533 code = """ diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py index 63765a5e..cde7465a 100644 --- a/tests/unittest_protocols.py +++ b/tests/unittest_protocols.py @@ -171,7 +171,7 @@ class ProtocolTests(unittest.TestCase): ) def test_assigned_stmts_starred_inside_call(self) -> None: - """Regression test for https://github.com/PyCQA/pylint/issues/6372""" + """Regression test for https://github.com/PyCQA/pylint/issues/6372.""" code = "string_twos = ''.join(str(*y) for _, *y in [[1, 2], [1, 2]]) #@" stmt = extract_node(code) starred = next(stmt.nodes_of_class(nodes.Starred)) diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py index 806e6fe0..587255f8 100644 --- a/tests/unittest_regrtest.py +++ b/tests/unittest_regrtest.py @@ -68,7 +68,7 @@ class NonRegressionTests(resources.AstroidCacheSetupMixin, unittest.TestCase): @unittest.skipIf(not HAS_NUMPY, "Needs numpy") def test_numpy_crash(self): - """test don't crash on numpy""" + """Test don't crash on numpy.""" # a crash occurred somewhere in the past, and an # InferenceError instead of a crash was better, but now we even infer! builder = AstroidBuilder() @@ -374,7 +374,9 @@ def test_crash_in_dunder_inference_prevented() -> None: def test_regression_crash_classmethod() -> None: - """Regression test for a crash reported in https://github.com/PyCQA/pylint/issues/4982""" + """Regression test for a crash reported in + https://github.com/PyCQA/pylint/issues/4982. + """ code = """ class Base: @classmethod @@ -394,7 +396,8 @@ def test_regression_crash_classmethod() -> None: def test_max_inferred_for_complicated_class_hierarchy() -> None: - """Regression test for a crash reported in https://github.com/PyCQA/pylint/issues/5679. + """Regression test for a crash reported in + https://github.com/PyCQA/pylint/issues/5679. The class hierarchy of 'sqlalchemy' is so intricate that it becomes uninferable with the standard max_inferred of 100. We used to crash when this happened. diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py index 2a37a8ad..39d21369 100644 --- a/tests/unittest_scoped_nodes.py +++ b/tests/unittest_scoped_nodes.py @@ -2,8 +2,8 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt -"""tests for specific behaviour of astroid scoped nodes (i.e. module, class and -function) +"""Tests for specific behaviour of astroid scoped nodes (i.e. module, class and +function). """ from __future__ import annotations @@ -539,7 +539,7 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): ) def test_return_nothing(self) -> None: - """test inferred value on a function with empty return""" + """Test inferred value on a function with empty return.""" data = """ def func(): return @@ -604,7 +604,7 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): assert inferred.value == value def test_func_instance_attr(self) -> None: - """test instance attributes for functions""" + """Test instance attributes for functions.""" data = """ def test(): print(test.bar) @@ -1991,7 +1991,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): self.assertRaises(AttributeInferenceError, instance.getattr, "mro") def test_metaclass_lookup_using_same_class(self) -> None: - """Check that we don't have recursive attribute access for metaclass""" + """Check that we don't have recursive attribute access for metaclass.""" cls = builder.extract_node( """ class A(object): pass @@ -2143,7 +2143,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): def test_instance_bound_method_lambdas_2(self) -> None: """ Test the fact that a method which is a lambda built from - a factory is well inferred as a bound method (bug pylint 2594) + a factory is well inferred as a bound method (bug pylint 2594). """ ast_nodes = builder.extract_node( """ @@ -2565,7 +2565,7 @@ def test_enums_type_annotation_no_value(annotation) -> None: def test_enums_value2member_map_() -> None: - """Check the `_value2member_map_` member is present in an Enum class""" + """Check the `_value2member_map_` member is present in an Enum class.""" node = builder.extract_node( """ from enum import Enum @@ -2755,7 +2755,7 @@ class TestFrameNodes: @staticmethod @pytest.mark.skipif(not PY38_PLUS, reason="needs assignment expressions") def test_frame_node(): - """Test if the frame of FunctionDef, ClassDef and Module is correctly set""" + """Test if the frame of FunctionDef, ClassDef and Module is correctly set.""" module = builder.parse( """ def func(): @@ -2795,7 +2795,7 @@ class TestFrameNodes: @staticmethod def test_non_frame_node(): - """Test if the frame of non frame nodes is set correctly""" + """Test if the frame of non frame nodes is set correctly.""" module = builder.parse( """ VAR_ONE = 1 |
