Skip to content

Commit

Permalink
[teyit] Add teyit to the pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jul 11, 2022
1 parent 3dfbcb5 commit 1436f71
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ repos:
exclude: .github/|tests/testdata
- id: end-of-file-fixer
exclude: tests/testdata
- repo: https://github.com/isidentical/teyit
rev: 0.4.3
hooks:
- id: teyit
exclude: tests/testdata
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
Expand Down
4 changes: 2 additions & 2 deletions tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class X(namedtuple("X", ["a", "b", "c"])):
# See: https://github.com/PyCQA/pylint/issues/5982
self.assertNotIn("X", klass.locals)
for anc in klass.ancestors():
self.assertFalse(anc.parent is None)
self.assertIsNotNone(anc.parent)

def test_namedtuple_inference(self) -> None:
klass = builder.extract_node(
Expand Down Expand Up @@ -1505,7 +1505,7 @@ class X(NamedTuple("X", [("a", int), ("b", str), ("c", bytes)])):
[anc.name for anc in klass.ancestors()], ["X", "tuple", "object"]
)
for anc in klass.ancestors():
self.assertFalse(anc.parent is None)
self.assertIsNotNone(anc.parent)

def test_namedtuple_can_correctly_access_methods(self) -> None:
klass, called = builder.extract_node(
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest_brain_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def getter():
"""
)
inferred_property = list(class_with_property.value.infer())[0]
self.assertTrue(isinstance(inferred_property, objects.Property))
self.assertIsInstance(inferred_property, objects.Property)
self.assertTrue(hasattr(inferred_property, "args"))


Expand Down
10 changes: 6 additions & 4 deletions tests/unittest_brain_numpy_core_fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
for func_ in self.numpy_functions:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_numpy_func_call(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {func_[0]:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg=f"Illicit type for {func_[0]:s} ({inferred_values[-1].pytype()})",
)

Expand Down
10 changes: 6 additions & 4 deletions tests/unittest_brain_numpy_core_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
for func_ in self.numpy_functions:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_numpy_func_call(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {func_[0]:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand Down
50 changes: 30 additions & 20 deletions tests/unittest_brain_numpy_core_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
for func_ in self.numpy_functions_returning_array:
with self.subTest(typ=func_):
inferred_values = list(infer_wrapper(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values, func_[0]
),
)
self.assertTrue(
inferred_values[-1].pytype() == ".ndarray",
self.assertEqual(
inferred_values[-1].pytype(),
".ndarray",
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand All @@ -116,14 +118,16 @@ def test_numpy_function_calls_inferred_as_bool(self):
for func_ in self.numpy_functions_returning_bool:
with self.subTest(typ=func_):
inferred_values = list(infer_wrapper(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values, func_[0]
),
)
self.assertTrue(
inferred_values[-1].pytype() == "builtins.bool",
self.assertEqual(
inferred_values[-1].pytype(),
"builtins.bool",
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand All @@ -140,14 +144,16 @@ def test_numpy_function_calls_inferred_as_dtype(self):
for func_ in self.numpy_functions_returning_dtype:
with self.subTest(typ=func_):
inferred_values = list(infer_wrapper(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values, func_[0]
),
)
self.assertTrue(
inferred_values[-1].pytype() == "numpy.dtype",
self.assertEqual(
inferred_values[-1].pytype(),
"numpy.dtype",
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand All @@ -164,14 +170,16 @@ def test_numpy_function_calls_inferred_as_none(self):
for func_ in self.numpy_functions_returning_none:
with self.subTest(typ=func_):
inferred_values = list(infer_wrapper(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values, func_[0]
),
)
self.assertTrue(
inferred_values[-1].pytype() == "builtins.NoneType",
self.assertEqual(
inferred_values[-1].pytype(),
"builtins.NoneType",
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand All @@ -188,14 +196,16 @@ def test_numpy_function_calls_inferred_as_tuple(self):
for func_ in self.numpy_functions_returning_tuple:
with self.subTest(typ=func_):
inferred_values = list(infer_wrapper(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values, func_[0]
),
)
self.assertTrue(
inferred_values[-1].pytype() == "builtins.tuple",
self.assertEqual(
inferred_values[-1].pytype(),
"builtins.tuple",
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand Down
10 changes: 6 additions & 4 deletions tests/unittest_brain_numpy_core_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
for func_ in self.numpy_functions:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_numpy_func_call(*func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {func_[0]:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg="Illicit type for {:s} ({})".format(
func_[0], inferred_values[-1].pytype()
),
Expand Down
12 changes: 6 additions & 6 deletions tests/unittest_brain_numpy_core_numerictypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_generic_types_have_methods(self):
inferred = self._inferred_numpy_attribute(type_)
for meth in generic_methods:
with self.subTest(meth=meth):
self.assertTrue(meth in {m.name for m in inferred.methods()})
self.assertIn(meth, {m.name for m in inferred.methods()})

def test_generic_types_have_attributes(self):
"""
Expand Down Expand Up @@ -330,12 +330,12 @@ def test_datetime_astype_return(self):
)
licit_array_types = ".ndarray"
inferred_values = list(node.infer())
self.assertTrue(
len(inferred_values) == 1,
msg="Too much inferred value for datetime64.astype",
self.assertEqual(
len(inferred_values), 1, msg="Too much inferred value for datetime64.astype"
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg="Illicit type for {:s} ({})".format(
"datetime64.astype", inferred_values[-1].pytype()
),
Expand Down
36 changes: 20 additions & 16 deletions tests/unittest_brain_numpy_core_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,16 @@ def test_numpy_core_umath_functions_return_type(self):
for func_ in ndarray_returning_func:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_numpy_func_call(func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg="Too much inferred values ({}) for {:s}".format(
inferred_values[-1].pytype(), func_
),
)
self.assertTrue(
inferred_values[0].pytype() == ".ndarray",
self.assertEqual(
inferred_values[0].pytype(),
".ndarray",
msg=f"Illicit type for {func_:s} ({inferred_values[-1].pytype()})",
)

Expand All @@ -236,26 +238,28 @@ def test_numpy_core_umath_functions_return_type_tuple(self):
for func_ in ndarray_returning_func:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_numpy_func_call(func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred values ({inferred_values}) for {func_:s}",
)
self.assertTrue(
inferred_values[-1].pytype() == "builtins.tuple",
self.assertEqual(
inferred_values[-1].pytype(),
"builtins.tuple",
msg=f"Illicit type for {func_:s} ({inferred_values[-1].pytype()})",
)
self.assertTrue(
len(inferred_values[0].elts) == 2,
self.assertEqual(
len(inferred_values[0].elts),
2,
msg=f"{func_} should return a pair of values. That's not the case.",
)
for array in inferred_values[-1].elts:
effective_infer = [m.pytype() for m in array.inferred()]
self.assertTrue(
".ndarray" in effective_infer,
msg=(
f"Each item in the return of {func_} should be inferred"
f" as a ndarray and not as {effective_infer}"
),
self.assertIn(
".ndarray",
effective_infer,
msg=f"Each item in the return of {func_} should be inferred"
f" as a ndarray and not as {effective_infer}",
)


Expand Down
20 changes: 12 additions & 8 deletions tests/unittest_brain_numpy_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
for func_ in self.ndarray_returning_ndarray_methods:
with self.subTest(typ=func_):
inferred_values = list(self._inferred_ndarray_method_call(func_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {func_:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg=f"Illicit type for {func_:s} ({inferred_values[-1].pytype()})",
)

Expand All @@ -151,12 +153,14 @@ def test_numpy_ndarray_attribute_inferred_as_ndarray(self):
for attr_ in ("real", "imag", "shape", "T"):
with self.subTest(typ=attr_):
inferred_values = list(self._inferred_ndarray_attribute(attr_))
self.assertTrue(
len(inferred_values) == 1,
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {attr_:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg=f"Illicit type for {attr_:s} ({inferred_values[-1].pytype()})",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4543,7 +4543,7 @@ def test_lambda(self) -> None:
)
inferred = next(node.infer())
self.assertIsInstance(inferred, nodes.Const)
self.assertIs(inferred.value, False)
self.assertFalse(inferred.value)


class BoolOpTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/unittest_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class A(A):
def test_method(self) -> None:
method = self.module["YOUPI"]["method"]
my_dict = next(method.ilookup("MY_DICT"))
self.assertTrue(isinstance(my_dict, nodes.Dict), my_dict)
self.assertIsInstance(my_dict, nodes.Dict, my_dict)
none = next(method.ilookup("None"))
self.assertIsNone(none.value)
self.assertRaises(
Expand All @@ -97,7 +97,7 @@ def test_method(self) -> None:
def test_function_argument_with_default(self) -> None:
make_class = self.module2["make_class"]
base = next(make_class.ilookup("base"))
self.assertTrue(isinstance(base, nodes.ClassDef), base.__class__)
self.assertIsInstance(base, nodes.ClassDef, base.__class__)
self.assertEqual(base.name, "YO")
self.assertEqual(base.root().name, "data.module")

Expand Down
4 changes: 2 additions & 2 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,14 @@ def test_builtins_inference_after_clearing_cache(self) -> None:
astroid.MANAGER.clear_cache()
isinstance_call = astroid.extract_node("isinstance(1, int)")
inferred = next(isinstance_call.infer())
self.assertIs(inferred.value, True)
self.assertTrue(inferred.value)

def test_builtins_inference_after_clearing_cache_manually(self) -> None:
# Not recommended to manipulate this, so we detect it and call clear_cache() instead
astroid.MANAGER.brain["astroid_cache"].clear()
isinstance_call = astroid.extract_node("isinstance(1, int)")
inferred = next(isinstance_call.infer())
self.assertIs(inferred.value, True)
self.assertTrue(inferred.value)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def test_load_module_set_attribute(self) -> None:
m = modutils.load_module_from_modpath(["xml", "etree", "ElementTree"])
self.assertTrue(hasattr(xml, "etree"))
self.assertTrue(hasattr(xml.etree, "ElementTree"))
self.assertTrue(m is xml.etree.ElementTree)
self.assertIs(m, xml.etree.ElementTree)


class ExtensionPackageWhitelistTest(unittest.TestCase):
Expand Down
Loading

0 comments on commit 1436f71

Please sign in to comment.