summaryrefslogtreecommitdiff
path: root/tests/test_stdlib.py
blob: 4027faa375ed7d1aa9795ce0b3fa9ff40f5017b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt

"""Tests for modules in the stdlib."""

from astroid import nodes
from astroid.builder import _extract_single_node


class TestSys:
    """Tests for the sys module."""

    def test_sys_builtin_module_names(self) -> None:
        """Test that we can gather the elements of a living tuple object."""
        node = _extract_single_node(
            """
        import sys
        sys.builtin_module_names
        """
        )
        inferred = list(node.infer())
        assert len(inferred) == 1
        assert isinstance(inferred[0], nodes.Tuple)
        assert inferred[0].elts

    def test_sys_modules(self) -> None:
        """Test that we can gather the items of a living dict object."""
        node = _extract_single_node(
            """
        import sys
        sys.modules
        """
        )
        inferred = list(node.infer())
        assert len(inferred) == 1
        assert isinstance(inferred[0], nodes.Dict)
        assert inferred[0].items