Skip to content

Commit

Permalink
Update tests for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent f7bfb9c commit e0d29e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
40 changes: 20 additions & 20 deletions tests/src/python/test_qgsmapunitscale.py
Expand Up @@ -27,32 +27,32 @@ def testConstructor(self):
self.assertEqual(c.minScale, 0)
self.assertEqual(c.maxScale, 0)

c = QgsMapUnitScale(0.0001, 0.005)
self.assertEqual(c.minScale, 0.0001)
self.assertEqual(c.maxScale, 0.005)
c = QgsMapUnitScale(10000, 200)
self.assertEqual(c.minScale, 10000)
self.assertEqual(c.maxScale, 200)

def testEquality(self):
# test equality operator

c1 = QgsMapUnitScale(0.0001, 0.005)
c1 = QgsMapUnitScale(10000, 200)
c1.minSizeMMEnabled = True
c1.minSizeMM = 3
c1.maxSizeMMEnabled = True
c1.maxSizeMM = 8
c2 = QgsMapUnitScale(0.0001, 0.005)
c2 = QgsMapUnitScale(10000, 200)
c2.minSizeMMEnabled = True
c2.minSizeMM = 3
c2.maxSizeMMEnabled = True
c2.maxSizeMM = 8
self.assertEqual(c1, c2)

c2.minScale = 0.0004
c2.minScale = 2500.0
self.assertNotEqual(c1, c2)
c2.minScale = 0.0001
c2.minScale = 10000

c2.maxScale = 0.007
c2.maxScale = 142.857
self.assertNotEqual(c1, c2)
c2.maxScale = 0.005
c2.maxScale = 200

c2.minSizeMMEnabled = False
self.assertNotEqual(c1, c2)
Expand Down Expand Up @@ -90,29 +90,29 @@ def testMapUnitsPerPixel(self):
self.assertAlmostEqual(mup, 2.0, places=5)

# add a minimum scale less than the renderer scale, so should be no change
c.minScale = 1 / 350000000.0
c.minScale = 350000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 2.0, places=5)

# minimum scale greater than the renderer scale, so should be limited to minScale
c.minScale = 1 / 150000000.0
c.minScale = 150000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 1.0276160, places=5)
c.minScale = 1 / 50000000.0
c.minScale = 50000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 0.3425386, places=5)
c.minScale = 1 / 350000000.0
c.minScale = 350000000.0

# add a maximum scale greater than the renderer scale, so should be no change
c.maxScale = 1 / 150000000.0
c.maxScale = 150000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 2.0, places=5)

# maximum scale less than the renderer scale, so should be limited to maxScale
c.maxScale = 1 / 350000000.0
c.maxScale = 350000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 2.3977706, places=5)
c.maxScale = 1 / 500000000.0
c.maxScale = 500000000.0
mup = c.computeMapUnitsPerPixel(r)
self.assertAlmostEqual(mup, 3.4253867, places=5)

Expand All @@ -126,8 +126,8 @@ def testEncodeDecode(self):
# test encoding and decoding QgsMapUnitScale

s = QgsMapUnitScale()
s.minScale = 50
s.maxScale = 100
s.minScale = 100
s.maxScale = 50
s.minSizeMMEnabled = True
s.minSizeMM = 3
s.maxSizeMMEnabled = False
Expand All @@ -140,8 +140,8 @@ def testEncodeDecode(self):
# check old style encoding
encode = '9,78.3'
r = QgsSymbolLayerUtils.decodeMapUnitScale(encode)
self.assertEqual(r.minScale, 9)
self.assertEqual(r.maxScale, 78.3)
self.assertAlmostEqual(r.minScale, 1.0 / 9, 3)
self.assertAlmostEqual(r.maxScale, 1.0 / 78.3, 3)
self.assertFalse(r.minSizeMMEnabled)
self.assertEqual(r.minSizeMM, 0)
self.assertFalse(r.maxSizeMMEnabled)
Expand Down
12 changes: 6 additions & 6 deletions tests/src/python/test_qgsrendercontext.py
Expand Up @@ -76,7 +76,7 @@ def testConvertSingleUnit(self):
self.assertAlmostEqual(sf, 1.0, places=5)

# minimum scale greater than the renderer scale, so should be limited to minScale
c.minScale = 1 / 150000000.0
c.minScale = 150000000.0
sf = r.convertToPainterUnits(1, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(sf, 3.89250455, places=5)
# only conversion from mapunits should be affected
Expand All @@ -91,7 +91,7 @@ def testConvertSingleUnit(self):
c.minScale = 0

# maximum scale less than the renderer scale, so should be limited to maxScale
c.maxScale = 1 / 350000000.0
c.maxScale = 350000000.0
sf = r.convertToPainterUnits(1, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(sf, 0.5, places=5)
# only conversion from mapunits should be affected
Expand Down Expand Up @@ -215,7 +215,7 @@ def testConvertToMapUnits(self):
c.maxSizeMMEnabled = False

# test with minimum scale set
c.minScale = 1 / 150000000.0
c.minScale = 150000000.0
size = r.convertToMapUnits(2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 15.57001821, places=5)
# only conversion from mapunits should be affected
Expand All @@ -230,7 +230,7 @@ def testConvertToMapUnits(self):
c.minScale = 0

# test with maximum scale set
c.maxScale = 1 / 1550000000.0
c.maxScale = 1550000000.0
size = r.convertToMapUnits(2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 1.50677595625, places=5)
# only conversion from mapunits should be affected
Expand Down Expand Up @@ -269,7 +269,7 @@ def testPixelSizeScaleFactor(self):
self.assertAlmostEqual(sf, 1.0, places=5)

# minimum scale greater than the renderer scale, so should be limited to minScale
c.minScale = 1 / 150000000.0
c.minScale = 150000000.0
sf = r.convertToPainterUnits(1, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(sf, 3.8925045, places=5)
# only conversion from mapunits should be affected
Expand All @@ -284,7 +284,7 @@ def testPixelSizeScaleFactor(self):
c.minScale = 0

# maximum scale less than the renderer scale, so should be limited to maxScale
c.maxScale = 1 / 350000000.0
c.maxScale = 350000000.0
sf = r.convertToPainterUnits(1, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(sf, 0.5, places=5)
# only conversion from mapunits should be affected
Expand Down

0 comments on commit e0d29e7

Please sign in to comment.