Skip to content

Commit

Permalink
Tests - Run pyupgrade on some Python tests files, with 3.7 minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and nyalldawson committed Jan 30, 2023
1 parent 7d81fdd commit 025c708
Show file tree
Hide file tree
Showing 63 changed files with 32 additions and 97 deletions.
5 changes: 2 additions & 3 deletions tests/src/python/test_qgsannotation.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for annotations.
From build dir, run: ctest -R PyQgsAnnotation -V
Expand Down Expand Up @@ -288,7 +287,7 @@ def renderAnnotationInLayout(self, test_name, annotation):
return result

def imageCheck(self, name, reference_image, image):
self.report += "<h2>Render {}</h2>\n".format(name)
self.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'annotation_' + name + ".png"
image.save(file_name, "PNG")
Expand All @@ -299,7 +298,7 @@ def imageCheck(self, name, reference_image, image):
checker.setColorTolerance(2)
result = checker.runTest(name, 20)
self.report += checker.report()
print((self.report))
print(self.report)
return result


Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgsannotationitemeditoperation.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationItemEditOperation
From build dir, run: ctest -R QgsAnnotationItemEditOperation -V
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgsannotationitemnode.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationItemNode
From build dir, run: ctest -R PyQgsAnnotationLayer -V
Expand Down
5 changes: 2 additions & 3 deletions tests/src/python/test_qgsannotationlayer.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationLayer.
From build dir, run: ctest -R PyQgsAnnotationLayer -V
Expand Down Expand Up @@ -255,7 +254,7 @@ def testProjectMainAnnotationLayer(self):

# save project to xml
tmpDir = QTemporaryDir()
tmpFile = "{}/project.qgs".format(tmpDir.path())
tmpFile = f"{tmpDir.path()}/project.qgs"
self.assertTrue(p.write(tmpFile))

# test that annotation layer is cleared with project
Expand Down Expand Up @@ -610,7 +609,7 @@ def test_render_via_job_with_transform(self):
result))

def imageCheck(self, name, reference_image, image):
TestQgsAnnotationLayer.report += "<h2>Render {}</h2>\n".format(name)
TestQgsAnnotationLayer.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'patch_' + name + ".png"
image.save(file_name, "PNG")
Expand Down
3 changes: 1 addition & 2 deletions tests/src/python/test_qgsannotationlineitem.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationLineItem.
From build dir, run: ctest -R PyQgsAnnotationLineItem -V
Expand Down Expand Up @@ -252,7 +251,7 @@ def testRenderWithTransform(self):
self.assertTrue(self.imageCheck('linestring_item_transform', 'linestring_item_transform', image))

def imageCheck(self, name, reference_image, image):
TestQgsAnnotationLineItem.report += "<h2>Render {}</h2>\n".format(name)
TestQgsAnnotationLineItem.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'patch_' + name + ".png"
image.save(file_name, "PNG")
Expand Down
3 changes: 1 addition & 2 deletions tests/src/python/test_qgsannotationmarkeritem.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationMarkerItem.
From build dir, run: ctest -R PyQgsAnnotationMarkerItem -V
Expand Down Expand Up @@ -212,7 +211,7 @@ def testRenderWithTransform(self):
self.assertTrue(self.imageCheck('marker_item_transform', 'marker_item_transform', image))

def imageCheck(self, name, reference_image, image):
TestQgsAnnotationMarkerItem.report += "<h2>Render {}</h2>\n".format(name)
TestQgsAnnotationMarkerItem.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'patch_' + name + ".png"
image.save(file_name, "PNG")
Expand Down
3 changes: 1 addition & 2 deletions tests/src/python/test_qgsannotationpointtextitem.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationPointTextItem.
From build dir, run: ctest -R PyQgsAnnotationPointTextItem -V
Expand Down Expand Up @@ -287,7 +286,7 @@ def testRenderWithTransform(self):
self.assertTrue(self.imageCheck('pointtext_item_transform', 'pointtext_item_transform', image))

def imageCheck(self, name, reference_image, image):
TestQgsAnnotationPointTextItem.report += "<h2>Render {}</h2>\n".format(name)
TestQgsAnnotationPointTextItem.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'patch_' + name + ".png"
image.save(file_name, "PNG")
Expand Down
3 changes: 1 addition & 2 deletions tests/src/python/test_qgsannotationpolygonitem.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationPolygonItem.
From build dir, run: ctest -R PyQgsAnnotationPolygonItem -V
Expand Down Expand Up @@ -265,7 +264,7 @@ def testRenderWithTransform(self):
self.assertTrue(self.imageCheck('polygon_item_transform', 'polygon_item_transform', image))

def imageCheck(self, name, reference_image, image):
TestQgsAnnotationPolygonItem.report += "<h2>Render {}</h2>\n".format(name)
TestQgsAnnotationPolygonItem.report += f"<h2>Render {name}</h2>\n"
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'patch_' + name + ".png"
image.save(file_name, "PNG")
Expand Down
2 changes: 0 additions & 2 deletions tests/src/python/test_qgsconditionalformatwidgets.py
@@ -1,5 +1,3 @@

# -*- coding: utf-8 -*-
"""QGIS Unit tests for the conditional format widgets.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
2 changes: 0 additions & 2 deletions tests/src/python/test_qgsconditionalstyle.py
@@ -1,5 +1,3 @@

# -*- coding: utf-8 -*-
"""QGIS Unit tests for the memory layer provider.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
7 changes: 3 additions & 4 deletions tests/src/python/test_qgsconnectionregistry.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsConnectionRegistry.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -43,11 +42,11 @@ def setUpClass(cls):
start_app()
QgsSettings().clear()

gpkg_original_path = '{}/qgis_server/test_project_wms_grouped_layers.gpkg'.format(TEST_DATA_DIR)
gpkg_original_path = f'{TEST_DATA_DIR}/qgis_server/test_project_wms_grouped_layers.gpkg'
cls.basetestpath = tempfile.mkdtemp()
cls.gpkg_path = '{}/test_gpkg.gpkg'.format(cls.basetestpath)
cls.gpkg_path = f'{cls.basetestpath}/test_gpkg.gpkg'
shutil.copy(gpkg_original_path, cls.gpkg_path)
vl = QgsVectorLayer('{}|layername=cdb_lines'.format(cls.gpkg_path), 'test', 'ogr')
vl = QgsVectorLayer(f'{cls.gpkg_path}|layername=cdb_lines', 'test', 'ogr')
assert vl.isValid()

@classmethod
Expand Down
11 changes: 5 additions & 6 deletions tests/src/python/test_qgslayout.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayout
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -403,14 +402,14 @@ def testSelectedItems(self):

self.assertFalse(l.selectedLayoutItems())
item1.setSelected(True)
self.assertEqual(set(l.selectedLayoutItems()), set([item1]))
self.assertEqual(set(l.selectedLayoutItems()), {item1})
item2.setSelected(True)
self.assertEqual(set(l.selectedLayoutItems()), set([item1, item2]))
self.assertEqual(set(l.selectedLayoutItems()), {item1, item2})
item3.setSelected(True)
self.assertEqual(set(l.selectedLayoutItems()), set([item1, item2, item3]))
self.assertEqual(set(l.selectedLayoutItems()), {item1, item2, item3})
item3.setLocked(True)
self.assertEqual(set(l.selectedLayoutItems(False)), set([item1, item2]))
self.assertEqual(set(l.selectedLayoutItems(True)), set([item1, item2, item3]))
self.assertEqual(set(l.selectedLayoutItems(False)), {item1, item2})
self.assertEqual(set(l.selectedLayoutItems(True)), {item1, item2, item3})

def testSelections(self):
p = QgsProject()
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutaligner.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutAligner
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutatlas.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutAtlas
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutatlasclippingsettings.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMapAtlasClippingSettings.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutcombobox.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutComboBox
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutelevationprofile.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemElevationProfile.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
19 changes: 9 additions & 10 deletions tests/src/python/test_qgslayoutexporter.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutExporter
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -98,14 +97,14 @@ def pdfToPng(pdf_file_path, rendered_file_path, page, dpi=96):
else:
return False, ''

print("exportToPdf call: {0}".format(' '.join(call)))
print("exportToPdf call: {}".format(' '.join(call)))
try:
subprocess.check_call(call)
except subprocess.CalledProcessError as e:
assert False, ("exportToPdf failed!\n"
"cmd: {0}\n"
"returncode: {1}\n"
"message: {2}".format(e.cmd, e.returncode, e.message))
"cmd: {}\n"
"returncode: {}\n"
"message: {}".format(e.cmd, e.returncode, e.message))


def svgToPng(svg_file_path, rendered_file_path, width):
Expand Down Expand Up @@ -154,7 +153,7 @@ def checkImage(self, name, reference_image, rendered_image, size_tolerance=0):
checker.setSizeTolerance(size_tolerance, size_tolerance)
result = checker.runTest(name, 20)
self.report += checker.report()
print((self.report))
print(self.report)
return result

def testRenderPage(self):
Expand Down Expand Up @@ -398,7 +397,7 @@ def testExportToImage(self):

page2_path = os.path.join(self.basetestpath, 'test_exporttoimagesizebadaspect_2.png')
im = QImage(page2_path)
self.assertTrue(self.checkImage('exporttoimagesize_badaspect', 'exporttoimagedpi_page2', page2_path), '{}x{}'.format(im.width(), im.height()))
self.assertTrue(self.checkImage('exporttoimagesize_badaspect', 'exporttoimagedpi_page2', page2_path), f'{im.width()}x{im.height()}')

def testExportToPdf(self):
md = QgsProject.instance().metadata()
Expand Down Expand Up @@ -718,7 +717,7 @@ def testExportToSvgTextRenderFormat(self):
self.assertTrue(os.path.exists(svg_file_path))

# expect svg to contain a text object with the scale
with open(svg_file_path, 'r') as f:
with open(svg_file_path) as f:
lines = ''.join(f.readlines())
self.assertIn('<text', lines)
self.assertIn('>1:666<', lines)
Expand All @@ -730,7 +729,7 @@ def testExportToSvgTextRenderFormat(self):
self.assertTrue(os.path.exists(svg_file_path))

# expect svg NOT to contain a text object with the scale
with open(svg_file_path, 'r') as f:
with open(svg_file_path) as f:
lines = ''.join(f.readlines())
self.assertNotIn('<text', lines)
self.assertNotIn('>1:666<', lines)
Expand Down Expand Up @@ -820,7 +819,7 @@ def testExportWorldFile(self):
self.assertTrue(os.path.exists(rendered_file_path))
self.assertTrue(os.path.exists(world_file_path))

lines = tuple(open(world_file_path, 'r'))
lines = tuple(open(world_file_path))
values = [float(f) for f in lines]
self.assertAlmostEqual(values[0], 0.794117647059, 2)
self.assertAlmostEqual(values[1], 0.0, 2)
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutframe.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutFrame.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutgridsettings.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutGridSettings.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutguides.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutGuide/QgsLayoutGuideCollection.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayouthtml.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemHtml.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
3 changes: 1 addition & 2 deletions tests/src/python/test_qgslayoutitem.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItem.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -37,7 +36,7 @@
start_app()


class LayoutItemTestCase(object):
class LayoutItemTestCase:
'''
This is a collection of generic tests for QgsLayoutItem subclasses.
To make use of it, subclass it and set self.item_class to a QgsLayoutItem subclass you want to test.
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutitemcombobox.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemComboBox
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutitempropertiesdialog.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemPropertiesDialog
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutlabel.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemLabel.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutlegend.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemLegend.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmanager.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutManager.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmanagermodel.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutManagerModel.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmap.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMap.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmapgrid.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMapGrid.
.. note. This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmapitemclippingsettings.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMapItemClipPathSettings.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmapoverview.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMap.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutmarker.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMarker.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutnortharrowhandler.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutNorthArrowHandler.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutpage.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemPage.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutpagecollection.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutPageCollection
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutpicture.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutPicture.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutpolygon.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemPolygon.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutpolyline.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemPolyline.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutscalebar.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemScaleBar.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutshape.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemShape.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion tests/src/python/test_qgslayoutsnapper.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutSnapper.
.. note:: This program is free software; you can redistribute it and/or modify
Expand Down

0 comments on commit 025c708

Please sign in to comment.