|
| 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