Skip to content

Commit

Permalink
Add a test for brain_gi
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marmarek committed Jun 25, 2024
1 parent 1aa3f01 commit 6b4eb78
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/brain/test_gi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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

import warnings
from importlib.util import find_spec

import pytest

from astroid import Uninferable, extract_node
from astroid.bases import BoundMethod
from astroid.manager import AstroidManager

HAS_GI = find_spec("gi")


@pytest.mark.skipif(HAS_GI is None, reason="These tests require the gi library.")
class TestBrainGi:
AstroidManager.brain["extension_package_whitelist"] = {"gi"} # noqa: RUF012

@staticmethod
def test_import() -> None:
"""Regression test for https://github.com/pylint-dev/astroid/issues/2190"""
src = """
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
cell = Gtk.CellRendererText()
cell.props.xalign = 1.0
Gtk.Builder().connect_signals
"""
with warnings.catch_warnings():
# gi uses pkgutil.get_loader
warnings.filterwarnings("ignore", category=DeprecationWarning)
node = extract_node(src)
attribute_node = node.inferred()[0]
if attribute_node is Uninferable:
pytest.skip("Gtk3 may not be installed?")
assert isinstance(attribute_node, BoundMethod)

0 comments on commit 6b4eb78

Please sign in to comment.