summaryrefslogtreecommitdiff
path: root/tests/brain/test_signal.py
blob: a9d4e8610a414ebc14aef5b4ee22812d1cfd91d0 (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
39
40
41
42
43
# 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

"""Unit Tests for the signal brain module."""


import sys

import pytest

from astroid import builder, nodes

# Define signal enums
ENUMS = ["Signals", "Handlers", "Sigmasks"]
if sys.platform == "win32":
    ENUMS.remove("Sigmasks")  # Sigmasks do not exist on Windows


@pytest.mark.parametrize("enum_name", ENUMS)
def test_enum(enum_name):
    """Tests that the signal module enums are handled by the brain."""
    # Extract node for signal module enum from code
    node = builder.extract_node(
        f"""
        import signal
        signal.{enum_name}
        """
    )

    # Check the extracted node
    assert isinstance(node, nodes.NodeNG)
    node_inf = node.inferred()[0]
    assert isinstance(node_inf, nodes.ClassDef)
    assert node_inf.display_type() == "Class"
    assert node_inf.is_subtype_of("enum.IntEnum")
    assert node_inf.qname() == f"signal.{enum_name}"

    # Check enum members
    for member in node_inf.body:
        assert isinstance(member, nodes.Assign)
        for target in member.targets:
            assert isinstance(target, nodes.AssignName)