Skip to content

Commit 4b5cb06

Browse files
committed
Add a test for brain_gi
Just a simple one, that checks if the correct Gtk version gets installed. Note this test is checks for the linked regression only if both Gtk3 and Gtk4 are installed. Otherwise, it checks if brain_gi works at all.
1 parent 4ad1c29 commit 4b5cb06

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/brain/test_gi.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
2+
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
3+
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
4+
5+
from importlib.util import find_spec
6+
import warnings
7+
8+
import pytest
9+
10+
from astroid import Uninferable, extract_node
11+
from astroid.bases import BoundMethod
12+
from astroid.const import PY312_PLUS
13+
from astroid.manager import AstroidManager
14+
from astroid.nodes import FunctionDef
15+
16+
HAS_GI = find_spec("gi")
17+
18+
19+
@pytest.mark.skipif(HAS_GI is None, reason="These tests require the gi library.")
20+
class TestBrainGi:
21+
AstroidManager.brain["extension_package_whitelist"] = {"gi"} # noqa: RUF012
22+
23+
@staticmethod
24+
def test_import() -> None:
25+
"""Regression test for https://github.com/pylint-dev/astroid/issues/2190
26+
"""
27+
src = """
28+
import gi
29+
gi.require_version('Gtk', '3.0')
30+
from gi.repository import Gtk
31+
32+
cell = Gtk.CellRendererText()
33+
cell.props.xalign = 1.0
34+
35+
Gtk.Builder().connect_signals
36+
"""
37+
with warnings.catch_warnings():
38+
# gi uses pkgutil.get_loader
39+
warnings.filterwarnings("ignore", category=DeprecationWarning)
40+
node = extract_node(src)
41+
attribute_node = node.inferred()[0]
42+
if attribute_node is Uninferable:
43+
pytest.skip("Gtk3 may not be installed?")
44+
assert isinstance(attribute_node, BoundMethod)
45+
46+

0 commit comments

Comments
 (0)