summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2023-04-22 21:03:04 +0200
committerGitHub <noreply@github.com>2023-04-22 21:03:04 +0200
commitd4529f5617e1b952c3fc167dd714efb090d72081 (patch)
treeb09df00cd83e5186d8f607017f02274e27f0950c /tests
parent8805036d679f41ee54efd08294849dbe12db487d (diff)
downloadastroid-git-d4529f5617e1b952c3fc167dd714efb090d72081.tar.gz
Fix constructors of ``ClassDef`` (#2130)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_inference.py2
-rw-r--r--tests/test_manager.py21
-rw-r--r--tests/test_scoped_nodes.py20
3 files changed, 36 insertions, 7 deletions
diff --git a/tests/test_inference.py b/tests/test_inference.py
index 7fcbb10c..b81a3e17 100644
--- a/tests/test_inference.py
+++ b/tests/test_inference.py
@@ -1264,7 +1264,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
assert i0.pytype() == "types.UnionType"
assert i0.display_type() == "UnionType"
assert str(i0) == "UnionType(UnionType)"
- assert repr(i0) == f"<UnionType(UnionType) l.None at 0x{id(i0)}>"
+ assert repr(i0) == f"<UnionType(UnionType) l.0 at 0x{id(i0)}>"
i1 = ast_nodes[1].inferred()[0]
assert isinstance(i1, UnionType)
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 4f76d09c..ef0c0699 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -25,7 +25,7 @@ from astroid.exceptions import (
from astroid.interpreter._import import util
from astroid.modutils import EXT_LIB_DIRS, module_in_path
from astroid.nodes import Const
-from astroid.nodes.scoped_nodes import ClassDef
+from astroid.nodes.scoped_nodes import ClassDef, Module
from . import resources
@@ -420,12 +420,27 @@ class ClearCacheTest(unittest.TestCase):
baseline_cache_infos = [lru.cache_info() for lru in lrus]
# Generate some hits and misses
- ClassDef().lookup("garbage")
+ module = Module("", file="", path=[], package=False)
+ ClassDef(
+ "",
+ lineno=0,
+ col_offset=0,
+ end_lineno=0,
+ end_col_offset=0,
+ parent=module,
+ ).lookup("garbage")
module_in_path("unittest", "garbage_path")
util.is_namespace("unittest")
astroid.interpreter.objectmodel.ObjectModel().attributes()
with pytest.raises(AttributeInferenceError):
- ClassDef().getattr("garbage")
+ ClassDef(
+ "",
+ lineno=0,
+ col_offset=0,
+ end_lineno=0,
+ end_col_offset=0,
+ parent=module,
+ ).getattr("garbage")
# Did the hits or misses actually happen?
incremented_cache_infos = [lru.cache_info() for lru in lrus]
diff --git a/tests/test_scoped_nodes.py b/tests/test_scoped_nodes.py
index 3795df56..3e8256dd 100644
--- a/tests/test_scoped_nodes.py
+++ b/tests/test_scoped_nodes.py
@@ -2912,7 +2912,14 @@ def test_deprecation_of_doc_attribute() -> None:
node_module = nodes.Module(name="MyModule")
node_module.postinit(body=[], doc_node=doc_node)
assert node_module.doc_node == doc_node
- node_class = nodes.ClassDef(name="MyClass")
+ node_class = nodes.ClassDef(
+ name="MyClass",
+ lineno=0,
+ col_offset=0,
+ end_lineno=0,
+ end_col_offset=0,
+ parent=nodes.Unknown(),
+ )
node_class.postinit(bases=[], body=[], decorators=[], doc_node=doc_node)
assert node_class.doc_node == doc_node
node_func = nodes.FunctionDef(
@@ -2946,7 +2953,14 @@ def test_deprecation_of_doc_attribute() -> None:
doc_node = nodes.Const("Docstring")
with pytest.warns(DeprecationWarning) as records:
node_module = nodes.Module(name="MyModule", doc="Docstring")
- node_class = nodes.ClassDef(name="MyClass", doc="Docstring")
+ node_class = nodes.ClassDef(
+ name="MyClass",
+ lineno=0,
+ col_offset=0,
+ end_lineno=0,
+ end_col_offset=0,
+ parent=nodes.Unknown(),
+ )
node_func = nodes.FunctionDef(
name="MyFunction",
lineno=0,
@@ -2955,4 +2969,4 @@ def test_deprecation_of_doc_attribute() -> None:
end_lineno=0,
end_col_offset=0,
)
- assert len(records) == 2
+ assert len(records) == 1