Skip to content

Commit 6b4eb78

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 1aa3f01 commit 6b4eb78

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/brain/test_gi.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import warnings
6+
from importlib.util import find_spec
7+
8+
import pytest
9+
10+
from astroid import Uninferable, extract_node
11+
from astroid.bases import BoundMethod
12+
from astroid.manager import AstroidManager
13+
14+
HAS_GI = find_spec("gi")
15+
16+
17+
@pytest.mark.skipif(HAS_GI is None, reason="These tests require the gi library.")
18+
class TestBrainGi:
19+
AstroidManager.brain["extension_package_whitelist"] = {"gi"} # noqa: RUF012
20+
21+
@staticmethod
22+
def test_import() -> None:
23+
"""Regression test for https://github.com/pylint-dev/astroid/issues/2190"""
24+
src = """
25+
import gi
26+
gi.require_version('Gtk', '3.0')
27+
from gi.repository import Gtk
28+
29+
cell = Gtk.CellRendererText()
30+
cell.props.xalign = 1.0
31+
32+
Gtk.Builder().connect_signals
33+
"""
34+
with warnings.catch_warnings():
35+
# gi uses pkgutil.get_loader
36+
warnings.filterwarnings("ignore", category=DeprecationWarning)
37+
node = extract_node(src)
38+
attribute_node = node.inferred()[0]
39+
if attribute_node is Uninferable:
40+
pytest.skip("Gtk3 may not be installed?")
41+
assert isinstance(attribute_node, BoundMethod)

0 commit comments

Comments
 (0)