Skip to content

Commit fe058bf

Browse files
Initial pass with pydocstringformatter over tests (#1949)
Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit e259af2)
1 parent aa93a97 commit fe058bf

29 files changed

+197
-252
lines changed

tests/test_brain_regex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_regex_flags(self) -> None:
2626

2727
@test_utils.require_version(minver="3.9")
2828
def test_regex_pattern_and_match_subscriptable(self):
29-
"""Test regex.Pattern and regex.Match are subscriptable in PY39+"""
29+
"""Test regex.Pattern and regex.Match are subscriptable in PY39+."""
3030
node1 = builder.extract_node(
3131
"""
3232
import regex

tests/unittest_brain_ctypes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
],
5858
)
5959
def test_ctypes_redefined_types_members(c_type, builtin_type, type_code):
60-
"""
61-
Test that the "value" and "_type_" member of each redefined types are correct
60+
"""Test that the "value" and "_type_" member of each redefined types are
61+
correct.
6262
"""
6363
src = f"""
6464
import ctypes
@@ -102,7 +102,8 @@ def test_cdata_member_access() -> None:
102102

103103
def test_other_ctypes_member_untouched() -> None:
104104
"""
105-
Test that other ctypes members, which are not touched by the brain, are correctly inferred
105+
Test that other ctypes members, which are not touched by the brain, are correctly
106+
inferred.
106107
"""
107108
src = """
108109
import ctypes

tests/unittest_brain_dataclasses.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class A:
7474
@parametrize_module
7575
def test_inference_field_default(module: str):
7676
"""Test inference of dataclass attribute with a field call default
77-
(default keyword argument given)."""
77+
(default keyword argument given).
78+
"""
7879
klass, instance = astroid.extract_node(
7980
f"""
8081
from {module} import dataclass
@@ -105,7 +106,8 @@ class A:
105106
@parametrize_module
106107
def test_inference_field_default_factory(module: str):
107108
"""Test inference of dataclass attribute with a field call default
108-
(default_factory keyword argument given)."""
109+
(default_factory keyword argument given).
110+
"""
109111
klass, instance = astroid.extract_node(
110112
f"""
111113
from {module} import dataclass
@@ -406,7 +408,7 @@ class A:
406408

407409
@parametrize_module
408410
def test_init_empty(module: str):
409-
"""Test init for a dataclass with no attributes"""
411+
"""Test init for a dataclass with no attributes."""
410412
node = astroid.extract_node(
411413
f"""
412414
from {module} import dataclass
@@ -424,7 +426,7 @@ class A:
424426

425427
@parametrize_module
426428
def test_init_no_defaults(module: str):
427-
"""Test init for a dataclass with attributes and no defaults"""
429+
"""Test init for a dataclass with attributes and no defaults."""
428430
node = astroid.extract_node(
429431
f"""
430432
from {module} import dataclass
@@ -451,7 +453,7 @@ class A:
451453

452454
@parametrize_module
453455
def test_init_defaults(module: str):
454-
"""Test init for a dataclass with attributes and some defaults"""
456+
"""Test init for a dataclass with attributes and some defaults."""
455457
node = astroid.extract_node(
456458
f"""
457459
from {module} import dataclass
@@ -486,7 +488,7 @@ class A:
486488

487489
@parametrize_module
488490
def test_init_initvar(module: str):
489-
"""Test init for a dataclass with attributes and an InitVar"""
491+
"""Test init for a dataclass with attributes and an InitVar."""
490492
node = astroid.extract_node(
491493
f"""
492494
from {module} import dataclass
@@ -602,7 +604,8 @@ class B(A):
602604

603605
@parametrize_module
604606
def test_init_attributes_from_superclasses(module: str):
605-
"""Test init for a dataclass that inherits and overrides attributes from superclasses.
607+
"""Test init for a dataclass that inherits and overrides attributes from
608+
superclasses.
606609
607610
Based on https://github.com/PyCQA/pylint/issues/3201
608611
"""
@@ -636,7 +639,9 @@ class B(A):
636639

637640
@parametrize_module
638641
def test_invalid_init(module: str):
639-
"""Test that astroid doesn't generate an initializer when attribute order is invalid."""
642+
"""Test that astroid doesn't generate an initializer when attribute order is
643+
invalid.
644+
"""
640645
node = astroid.extract_node(
641646
f"""
642647
from {module} import dataclass
@@ -655,7 +660,9 @@ class A:
655660

656661
@parametrize_module
657662
def test_annotated_enclosed_field_call(module: str):
658-
"""Test inference of dataclass attribute with a field call in another function call"""
663+
"""Test inference of dataclass attribute with a field call in another function
664+
call.
665+
"""
659666
node = astroid.extract_node(
660667
f"""
661668
from {module} import dataclass, field

tests/unittest_brain_numpy_core_einsumfunc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def _inferred_numpy_func_call(func_name: str, *func_args: str) -> nodes.Function
2929

3030
@pytest.mark.skipif(not HAS_NUMPY, reason="This test requires the numpy library.")
3131
def test_numpy_function_calls_inferred_as_ndarray() -> None:
32-
"""
33-
Test that calls to numpy functions are inferred as numpy.ndarray
34-
"""
32+
"""Test that calls to numpy functions are inferred as numpy.ndarray."""
3533
method = "einsum"
3634
inferred_values = list(
3735
_inferred_numpy_func_call(method, "ii, np.arange(25).reshape(5, 5)")

tests/unittest_brain_numpy_core_fromnumeric.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
1818
class BrainNumpyCoreFromNumericTest(unittest.TestCase):
19-
"""
20-
Test the numpy core fromnumeric brain module
21-
"""
19+
"""Test the numpy core fromnumeric brain module."""
2220

2321
numpy_functions = (("sum", "[1, 2]"),)
2422

@@ -33,9 +31,7 @@ def _inferred_numpy_func_call(self, func_name, *func_args):
3331
return node.infer()
3432

3533
def test_numpy_function_calls_inferred_as_ndarray(self):
36-
"""
37-
Test that calls to numpy functions are inferred as numpy.ndarray
38-
"""
34+
"""Test that calls to numpy functions are inferred as numpy.ndarray."""
3935
licit_array_types = (".ndarray",)
4036
for func_ in self.numpy_functions:
4137
with self.subTest(typ=func_):

tests/unittest_brain_numpy_core_function_base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
1818
class BrainNumpyCoreFunctionBaseTest(unittest.TestCase):
19-
"""
20-
Test the numpy core numeric brain module
21-
"""
19+
"""Test the numpy core numeric brain module."""
2220

2321
numpy_functions = (
2422
("linspace", "1, 100"),
@@ -37,9 +35,7 @@ def _inferred_numpy_func_call(self, func_name, *func_args):
3735
return node.infer()
3836

3937
def test_numpy_function_calls_inferred_as_ndarray(self):
40-
"""
41-
Test that calls to numpy functions are inferred as numpy.ndarray
42-
"""
38+
"""Test that calls to numpy functions are inferred as numpy.ndarray."""
4339
licit_array_types = (".ndarray",)
4440
for func_ in self.numpy_functions:
4541
with self.subTest(typ=func_):

tests/unittest_brain_numpy_core_multiarray.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
1818
class BrainNumpyCoreMultiarrayTest(unittest.TestCase):
19-
"""
20-
Test the numpy core multiarray brain module
21-
"""
19+
"""Test the numpy core multiarray brain module."""
2220

2321
numpy_functions_returning_array = (
2422
("array", "[1, 2]"),
@@ -82,9 +80,7 @@ def _inferred_numpy_no_alias_func_call(self, func_name, *func_args):
8280
return node.infer()
8381

8482
def test_numpy_function_calls_inferred_as_ndarray(self):
85-
"""
86-
Test that calls to numpy functions are inferred as numpy.ndarray
87-
"""
83+
"""Test that calls to numpy functions are inferred as numpy.ndarray."""
8884
for infer_wrapper in (
8985
self._inferred_numpy_func_call,
9086
self._inferred_numpy_no_alias_func_call,
@@ -106,9 +102,7 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
106102
)
107103

108104
def test_numpy_function_calls_inferred_as_bool(self):
109-
"""
110-
Test that calls to numpy functions are inferred as bool
111-
"""
105+
"""Test that calls to numpy functions are inferred as bool."""
112106
for infer_wrapper in (
113107
self._inferred_numpy_func_call,
114108
self._inferred_numpy_no_alias_func_call,
@@ -130,9 +124,7 @@ def test_numpy_function_calls_inferred_as_bool(self):
130124
)
131125

132126
def test_numpy_function_calls_inferred_as_dtype(self):
133-
"""
134-
Test that calls to numpy functions are inferred as numpy.dtype
135-
"""
127+
"""Test that calls to numpy functions are inferred as numpy.dtype."""
136128
for infer_wrapper in (
137129
self._inferred_numpy_func_call,
138130
self._inferred_numpy_no_alias_func_call,
@@ -154,9 +146,7 @@ def test_numpy_function_calls_inferred_as_dtype(self):
154146
)
155147

156148
def test_numpy_function_calls_inferred_as_none(self):
157-
"""
158-
Test that calls to numpy functions are inferred as None
159-
"""
149+
"""Test that calls to numpy functions are inferred as None."""
160150
for infer_wrapper in (
161151
self._inferred_numpy_func_call,
162152
self._inferred_numpy_no_alias_func_call,
@@ -178,9 +168,7 @@ def test_numpy_function_calls_inferred_as_none(self):
178168
)
179169

180170
def test_numpy_function_calls_inferred_as_tuple(self):
181-
"""
182-
Test that calls to numpy functions are inferred as tuple
183-
"""
171+
"""Test that calls to numpy functions are inferred as tuple."""
184172
for infer_wrapper in (
185173
self._inferred_numpy_func_call,
186174
self._inferred_numpy_no_alias_func_call,

tests/unittest_brain_numpy_core_numeric.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
2222
class BrainNumpyCoreNumericTest(unittest.TestCase):
23-
"""
24-
Test the numpy core numeric brain module
25-
"""
23+
"""Test the numpy core numeric brain module."""
2624

2725
numpy_functions = (
2826
("zeros_like", "[1, 2]"),
@@ -42,9 +40,7 @@ def _inferred_numpy_func_call(self, func_name, *func_args):
4240
return node.infer()
4341

4442
def test_numpy_function_calls_inferred_as_ndarray(self):
45-
"""
46-
Test that calls to numpy functions are inferred as numpy.ndarray
47-
"""
43+
"""Test that calls to numpy functions are inferred as numpy.ndarray."""
4844
licit_array_types = (".ndarray",)
4945
for func_ in self.numpy_functions:
5046
with self.subTest(typ=func_):

tests/unittest_brain_numpy_core_numerictypes.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
2323
class NumpyBrainCoreNumericTypesTest(unittest.TestCase):
24-
"""
25-
Test of all the missing types defined in numerictypes module.
26-
"""
24+
"""Test of all the missing types defined in numerictypes module."""
2725

2826
all_types = [
2927
"uint16",
@@ -87,18 +85,14 @@ def _inferred_numpy_attribute(self, attrib):
8785
return next(node.value.infer())
8886

8987
def test_numpy_core_types(self):
90-
"""
91-
Test that all defined types have ClassDef type.
92-
"""
88+
"""Test that all defined types have ClassDef type."""
9389
for typ in self.all_types:
9490
with self.subTest(typ=typ):
9591
inferred = self._inferred_numpy_attribute(typ)
9692
self.assertIsInstance(inferred, nodes.ClassDef)
9793

9894
def test_generic_types_have_methods(self):
99-
"""
100-
Test that all generic derived types have specified methods
101-
"""
95+
"""Test that all generic derived types have specified methods."""
10296
generic_methods = [
10397
"all",
10498
"any",
@@ -210,9 +204,7 @@ def test_generic_types_have_methods(self):
210204
self.assertTrue(meth in {m.name for m in inferred.methods()})
211205

212206
def test_generic_types_have_attributes(self):
213-
"""
214-
Test that all generic derived types have specified attributes
215-
"""
207+
"""Test that all generic derived types have specified attributes."""
216208
generic_attr = [
217209
"base",
218210
"data",
@@ -270,9 +262,7 @@ def test_generic_types_have_attributes(self):
270262
self.assertNotEqual(len(inferred.getattr(attr)), 0)
271263

272264
def test_number_types_have_unary_operators(self):
273-
"""
274-
Test that number types have unary operators
275-
"""
265+
"""Test that number types have unary operators."""
276266
unary_ops = ("__neg__",)
277267

278268
for type_ in (
@@ -301,9 +291,7 @@ def test_number_types_have_unary_operators(self):
301291
self.assertNotEqual(len(inferred.getattr(attr)), 0)
302292

303293
def test_array_types_have_unary_operators(self):
304-
"""
305-
Test that array types have unary operators
306-
"""
294+
"""Test that array types have unary operators."""
307295
unary_ops = ("__neg__", "__invert__")
308296

309297
for type_ in ("ndarray",):
@@ -346,9 +334,7 @@ def test_datetime_astype_return(self):
346334
f"This test requires the numpy library with a version above {NUMPY_VERSION_TYPE_HINTS_SUPPORT}",
347335
)
348336
def test_generic_types_are_subscriptables(self):
349-
"""
350-
Test that all types deriving from generic are subscriptables
351-
"""
337+
"""Test that all types deriving from generic are subscriptables."""
352338
for type_ in (
353339
"bool_",
354340
"bytes_",
@@ -401,19 +387,20 @@ def test_generic_types_are_subscriptables(self):
401387
class NumpyBrainUtilsTest(unittest.TestCase):
402388
"""
403389
This class is dedicated to test that astroid does not crash
404-
if numpy module is not available
390+
if numpy module is not available.
405391
"""
406392

407393
def test_get_numpy_version_do_not_crash(self):
408394
"""
409-
Test that the function _get_numpy_version doesn't crash even if numpy is not installed
395+
Test that the function _get_numpy_version doesn't crash even if numpy is not
396+
installed.
410397
"""
411398
self.assertEqual(_get_numpy_version(), ("0", "0", "0"))
412399

413400
def test_numpy_object_uninferable(self):
414401
"""
415402
Test that in case numpy is not available, then a numpy object is uninferable
416-
but the inference doesn't lead to a crash
403+
but the inference doesn't lead to a crash.
417404
"""
418405
src = """
419406
import numpy as np

0 commit comments

Comments
 (0)