Skip to content

Commit

Permalink
[tests] Fix layout test by using standard QGIS test font
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor authored and nyalldawson committed May 22, 2024
1 parent f350540 commit 99899e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions tests/src/python/test_qgsprofilesourceregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
QgsCoordinateReferenceSystem,
QgsDoubleRange,
QgsFeedback,
QgsFillSymbol,
QgsFontUtils,
QgsGeometry,
QgsLayout,
QgsLayoutItemElevationProfile,
Expand Down Expand Up @@ -61,7 +63,7 @@ def __init__(self):
self.max_z = -100

self.marker_symbol = QgsMarkerSymbol.createSimple(
{'name': 'square', 'size': 1, 'color': '#00ff00',
{'name': 'square', 'size': 2, 'color': '#00ff00',
'outline_style': 'no'})

def asFeatures(self, type, feedback):
Expand Down Expand Up @@ -195,14 +197,20 @@ def createProfileGenerator(self, request):
class TestQgsProfileSourceRegistry(QgisTestCase):

def test_register_unregister_source(self):
self.assertEqual(QgsApplication.profileSourceRegistry().profileSources(), [])
initial_sources = QgsApplication.profileSourceRegistry().profileSources()

source = MyProfileSource()
QgsApplication.profileSourceRegistry().registerProfileSource(source)
self.assertEqual(len(QgsApplication.profileSourceRegistry().profileSources()), 1)
self.assertEqual(QgsApplication.profileSourceRegistry().profileSources()[0], source)
self.assertEqual(
len(QgsApplication.profileSourceRegistry().profileSources()),
len(initial_sources) + 1
)
self.assertEqual(QgsApplication.profileSourceRegistry().profileSources()[-1], source)
QgsApplication.profileSourceRegistry().unregisterProfileSource(source)
self.assertEqual(QgsApplication.profileSourceRegistry().profileSources(), [])
self.assertEqual(
QgsApplication.profileSourceRegistry().profileSources(),
initial_sources
)

def test_generate_profile_from_custom_source(self):
curve = QgsLineString()
Expand Down Expand Up @@ -361,6 +369,7 @@ def test_layout_item_profile_custom_source(self):
profile_item.setProfileCurve(curve)
profile_item.setCrs(QgsCoordinateReferenceSystem("EPSG:2056"))

profile_item.plot().setXMinimum(-100)
profile_item.plot().setXMaximum(curve.length() + 100)
profile_item.plot().setYMaximum(1300)

Expand All @@ -371,10 +380,12 @@ def test_layout_item_profile_custom_source(self):
QgsLineSymbol.createSimple({'color': '#ffffaa', 'width': 2}))

format = QgsTextFormat()
format.setSize(10)
format.setFont(QgsFontUtils.getStandardTestFont("Bold"))
format.setSize(20)
format.setNamedStyle("Bold")
format.setColor(QColor(0, 0, 0))
profile_item.plot().xAxis().setTextFormat(format)
profile_item.plot().xAxis().setLabelInterval(1000)
profile_item.plot().xAxis().setLabelInterval(2000)

profile_item.plot().yAxis().setGridIntervalMajor(1000)
profile_item.plot().yAxis().setGridIntervalMinor(500)
Expand All @@ -385,6 +396,9 @@ def test_layout_item_profile_custom_source(self):
profile_item.plot().yAxis().setTextFormat(format)
profile_item.plot().yAxis().setLabelInterval(500)

profile_item.plot().setChartBorderSymbol(
QgsFillSymbol.createSimple({'style': 'no', 'color': '#aaffaa', 'width_border': 2}))

self.assertTrue(
self.render_layout_check('custom_profile', layout)
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 99899e9

Please sign in to comment.