summaryrefslogtreecommitdiff
path: root/tests/unittest_python3.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittest_python3.py')
-rw-r--r--tests/unittest_python3.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/unittest_python3.py b/tests/unittest_python3.py
index 9f60833e..bf0a0b33 100644
--- a/tests/unittest_python3.py
+++ b/tests/unittest_python3.py
@@ -5,7 +5,9 @@
import unittest
from textwrap import dedent
-from astroid import nodes
+import pytest
+
+from astroid import exceptions, nodes
from astroid.builder import AstroidBuilder, extract_node
from astroid.test_utils import require_version
@@ -285,6 +287,33 @@ class Python3TC(unittest.TestCase):
self.assertIsInstance(value, nodes.Const)
self.assertEqual(value.value, expected)
+ @staticmethod
+ def test_unpacking_in_dict_getitem_with_ref() -> None:
+ node = extract_node(
+ """
+ a = {1: 2}
+ {**a, 2: 3} #@
+ """
+ )
+ assert isinstance(node, nodes.Dict)
+
+ for key, expected in ((1, 2), (2, 3)):
+ value = node.getitem(nodes.Const(key))
+ assert isinstance(value, nodes.Const)
+ assert value.value == expected
+
+ @staticmethod
+ def test_unpacking_in_dict_getitem_uninferable() -> None:
+ node = extract_node("{**a, 2: 3}")
+ assert isinstance(node, nodes.Dict)
+
+ with pytest.raises(exceptions.AstroidIndexError):
+ node.getitem(nodes.Const(1))
+
+ value = node.getitem(nodes.Const(2))
+ assert isinstance(value, nodes.Const)
+ assert value.value == 3
+
def test_format_string(self) -> None:
code = "f'{greetings} {person}'"
node = extract_node(code)