Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove any trace of distutils use as it is going to be removed in python 3.12 (fixes #51532) #51630

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmake/FindSIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
print("sip_version_num:%d" % sipbuild.version.SIP_VERSION)
print("sip_version_str:%s" % sipbuild.version.SIP_VERSION_STR)

from distutils.sysconfig import get_python_lib
python_modules_dir = get_python_lib(plat_specific=1)
import sysconfig
if "deb_system" in sysconfig.get_scheme_names():
python_modules_dir = sysconfig.get_path("purelib", "deb_system")
else:
python_modules_dir = sysconfig.get_path("purelib")
print("default_sip_dir:%s" % python_modules_dir)
except ImportError: # Code for SIP v4
import sipconfig
Expand Down
80 changes: 24 additions & 56 deletions tests/src/python/test_qgslayertreeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import os

from distutils.version import StrictVersion

from qgis.core import (
QgsLayerTreeModel,
QgsProject,
Expand All @@ -30,18 +28,9 @@
from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)
from qgis.PyQt.QtCore import QStringListModel
from qgis.PyQt.QtTest import QSignalSpy

from qgis.PyQt.QtTest import QSignalSpy, QAbstractItemModelTester
from qgis.PyQt.Qt import PYQT_VERSION_STR

USE_MODEL_TESTER = False


if StrictVersion(PYQT_VERSION_STR) >= StrictVersion('5.11'):
from qgis.PyQt.QtTest import QAbstractItemModelTester
USE_MODEL_TESTER = True


app = start_app()
TEST_DATA_DIR = unitTestDataPath()

Expand All @@ -67,8 +56,7 @@ def __init__(self, methodName):
"layer5", "memory")
self.project.addMapLayers([self.layer, self.layer2, self.layer3])
self.model = QgsLayerTreeModel(self.project.layerTreeRoot())
if USE_MODEL_TESTER:
self.tester = QAbstractItemModelTester(self.model)
self.tester = QAbstractItemModelTester(self.model)

self.groupname = "group"
self.subgroupname = "sub-group"
Expand Down Expand Up @@ -97,16 +85,14 @@ def testSetModel(self):

# should work
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
self.assertEqual(view.layerTreeModel(), self.model)

def testSetCurrentLayer(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
current_layer_changed_spy = QSignalSpy(view.currentLayerChanged)
self.assertFalse(view.currentLayer())
view.setCurrentLayer(self.layer3)
Expand All @@ -122,8 +108,7 @@ def testSetCurrentLayer(self):
def testDefaultActions(self):
view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)

# show in overview action
Expand All @@ -147,8 +132,7 @@ def testMoveOutOfGroupActionLayer(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
self.layer.name(),
Expand Down Expand Up @@ -176,8 +160,7 @@ def testMoveToTopActionLayer(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.project.layerTreeRoot().layerOrder(), [
self.layer, self.layer2, self.layer3])
Expand All @@ -196,8 +179,7 @@ def testMoveToTopActionGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
self.layer.name(),
Expand Down Expand Up @@ -230,8 +212,7 @@ def testMoveToTopActionEmbeddedGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
self.layer.name(),
Expand Down Expand Up @@ -263,8 +244,7 @@ def testMoveToTopActionLayerAndGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
self.layer.name(),
Expand Down Expand Up @@ -297,8 +277,7 @@ def testMoveToBottomActionLayer(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.project.layerTreeRoot().layerOrder(), [
self.layer, self.layer2, self.layer3])
Expand All @@ -317,8 +296,7 @@ def testMoveToBottomActionGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname,
Expand Down Expand Up @@ -351,8 +329,7 @@ def testMoveToBottomActionEmbeddedGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
self.layer.name(),
Expand Down Expand Up @@ -384,8 +361,7 @@ def testMoveToBottomActionLayerAndGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname,
Expand Down Expand Up @@ -422,8 +398,7 @@ def testAddGroupActionLayer(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname,
Expand Down Expand Up @@ -457,8 +432,7 @@ def testAddGroupActionLayers(self):
groupname = group.name()

view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname,
Expand Down Expand Up @@ -496,8 +470,7 @@ def testAddGroupActionGroup(self):
group.addLayer(self.layer5)
groupname = group.name()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname,
Expand Down Expand Up @@ -534,8 +507,7 @@ def testAddGroupActionGroups(self):
groupname2 = group2.name()

view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
actions = QgsLayerTreeViewDefaultActions(view)
self.assertEqual(self.nodeOrder(self.project.layerTreeRoot().children()), [
groupname2,
Expand Down Expand Up @@ -572,8 +544,7 @@ def testSetLayerVisible(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
self.project.layerTreeRoot().findLayer(
self.layer).setItemVisibilityChecked(True)
self.project.layerTreeRoot().findLayer(
Expand All @@ -599,8 +570,7 @@ def testProxyModel(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
proxy_tester = QAbstractItemModelTester(view.model())
tree_model = view.layerTreeModel()
proxy_model = view.proxyModel()

Expand Down Expand Up @@ -665,9 +635,8 @@ def testProxyModelCurrentIndex(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
tree_tester = QAbstractItemModelTester(view.layerTreeModel())
proxy_tester = QAbstractItemModelTester(view.model())
tree_tester = QAbstractItemModelTester(view.layerTreeModel())

view.setCurrentLayer(self.layer3)
self.layer3.setFlags(self.layer.Private)
Expand All @@ -677,9 +646,8 @@ def testNode2IndexMethods(self):

view = QgsLayerTreeView()
view.setModel(self.model)
if USE_MODEL_TESTER:
proxy_tester = QAbstractItemModelTester(view.model())
tree_tester = QAbstractItemModelTester(view.layerTreeModel())
proxy_tester = QAbstractItemModelTester(view.model())
tree_tester = QAbstractItemModelTester(view.layerTreeModel())

tree_model = view.layerTreeModel()
proxy_model = view.proxyModel()
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgsrasterattributetablemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import qgis # NOQA

import os
from distutils.version import StrictVersion
from qgis.PyQt.QtCore import QVariant, QModelIndex
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.Qt import Qt, PYQT_VERSION_STR
Expand Down
7 changes: 1 addition & 6 deletions tests/src/python/test_qgssymbollayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from osgeo import ogr
import os

from distutils.version import StrictVersion
from qgis.PyQt.Qt import PYQT_VERSION_STR
from qgis.PyQt.QtCore import Qt, QObject, QDir, QFile, QIODevice, QPointF, QSize, QTemporaryDir
from qgis.PyQt.QtXml import QDomDocument
Expand Down Expand Up @@ -89,11 +88,7 @@

TEST_DATA_DIR = unitTestDataPath()

if StrictVersion(PYQT_VERSION_STR) < StrictVersion('5.7'):
from qgis.PyQt.QtCore import pyqtWrapperType
EXPECTED_TYPE = pyqtWrapperType
else:
EXPECTED_TYPE = type(QObject)
EXPECTED_TYPE = type(QObject)


class TestQgsSymbolLayer(unittest.TestCase):
Expand Down