コード例 #1
0
 def testQgsRendererRange_1(self):
     """Test QgsRendererRange getter/setter functions"""
     range = QgsRendererRange()
     self.assertTrue(range)
     lower = 123.45
     upper = 234.56
     label = "Test label"
     symbol = createMarkerSymbol()
     range.setLowerValue(lower)
     self.assertEqual(range.lowerValue(), lower, "Lower value getter/setter failed")
     range.setUpperValue(upper)
     self.assertEqual(range.upperValue(), upper, "Upper value getter/setter failed")
     range.setLabel(label)
     self.assertEqual(range.label(), label, "Label getter/setter failed")
     range.setRenderState(True)
     self.assertTrue(range.renderState(), "Render state getter/setter failed")
     range.setRenderState(False)
     self.assertFalse(range.renderState(), "Render state getter/setter failed")
     range.setSymbol(symbol.clone())
     self.assertEqual(symbol.dump(), range.symbol().dump(), "Symbol getter/setter failed")
     range2 = QgsRendererRange(lower, upper, symbol.clone(), label, False)
     self.assertEqual(range2.lowerValue(), lower, "Lower value from constructor failed")
     self.assertEqual(range2.upperValue(), upper, "Upper value from constructor failed")
     self.assertEqual(range2.label(), label, "Label from constructor failed")
     self.assertEqual(range2.symbol().dump(), symbol.dump(), "Symbol from constructor failed")
     self.assertFalse(range2.renderState(), "Render state getter/setter failed")
コード例 #2
0
 def testQgsRendererRange_1(self):
     """Test QgsRendererRange getter/setter functions"""
     range = QgsRendererRange()
     self.assertTrue(range)
     lower = 123.45
     upper = 234.56
     label = "Test label"
     symbol = createMarkerSymbol()
     range.setLowerValue(lower)
     self.assertEqual(range.lowerValue(), lower, "Lower value getter/setter failed")
     range.setUpperValue(upper)
     self.assertEqual(range.upperValue(), upper, "Upper value getter/setter failed")
     range.setLabel(label)
     self.assertEqual(range.label(), label, "Label getter/setter failed")
     range.setRenderState(True)
     self.assertTrue(range.renderState(), "Render state getter/setter failed")
     range.setRenderState(False)
     self.assertFalse(range.renderState(), "Render state getter/setter failed")
     range.setSymbol(symbol.clone())
     self.assertEqual(symbol.dump(), range.symbol().dump(), "Symbol getter/setter failed")
     range2 = QgsRendererRange(lower, upper, symbol.clone(), label, False)
     self.assertEqual(range2.lowerValue(), lower, "Lower value from constructor failed")
     self.assertEqual(range2.upperValue(), upper, "Upper value from constructor failed")
     self.assertEqual(range2.label(), label, "Label from constructor failed")
     self.assertEqual(range2.symbol().dump(), symbol.dump(), "Symbol from constructor failed")
     self.assertFalse(range2.renderState(), "Render state getter/setter failed")
コード例 #3
0
    def testQgsRendererRangeLabelFormat_2(self):
        """Test QgsRendererRangeLabelFormat number format"""
        format = QgsRendererRangeLabelFormat()
        # Tests have precision, trim, value, expected
        # (Note: Not sure what impact of locale is on these tests)
        tests = (
            (2, False, 1.0, '1.00'),
            (2, True, 1.0, '1'),
            (2, False, 1.234, '1.23'),
            (2, True, 1.234, '1.23'),
            (2, False, 1.236, '1.24'),
            (2, False, -1.236, '-1.24'),
            (2, False, -0.004, '0.00'),
            (2, True, 1.002, '1'),
            (2, True, 1.006, '1.01'),
            (2, True, 1.096, '1.1'),
            (3, True, 1.096, '1.096'),
            (-2, True, 1496.45, '1500'),
            (-2, True, 149.45, '100'),
            (-2, True, 79.45, '100'),
            (-2, True, 49.45, '0'),
            (-2, True, -49.45, '0'),
            (-2, True, -149.45, '-100'),
        )
        for f in tests:
            precision, trim, value, expected = f
            format.setPrecision(precision)
            format.setTrimTrailingZeroes(trim)
            result = format.formatNumber(value)
            self.assertEqual(
                result, expected,
                "Number format error {0}:{1}:{2} => {3}".format(
                    precision, trim, value, result))

        # Label tests - label format, expected result.
        # Labels will be evaluated with lower=1.23 upper=2.34, precision=2
        ltests = (
            ("%1 - %2", "1.23 - 2.34"),
            ("%1", "1.23"),
            ("%2", "2.34"),
            ("%2%", "2.34%"),
            ("%1%1", "1.231.23"),
            ("from %1 to %2 meters", "from 1.23 to 2.34 meters"),
            ("from %2 to %1 meters", "from 2.34 to 1.23 meters"),
        )
        format.setPrecision(2)
        format.setTrimTrailingZeroes(False)
        lower = 1.232
        upper = 2.339
        for t in ltests:
            label, expected = t
            format.setFormat(label)
            result = format.labelForLowerUpper(lower, upper)
            self.assertEqual(
                result, expected,
                "Label format error {0} => {1}".format(label, result))

        range = QgsRendererRange()
        range.setLowerValue(lower)
        range.setUpperValue(upper)
        label = ltests[0][0]
        format.setFormat(label)
        result = format.labelForRange(range)
        self.assertEqual(
            result, ltests[0][1],
            "Label for range error {0} => {1}".format(label, result))
コード例 #4
0
    def testQgsRendererRangeLabelFormat_2(self):
        """Test QgsRendererRangeLabelFormat number format"""
        format = QgsRendererRangeLabelFormat()
        # Tests have precision, trim, value, expected
        # (Note: Not sure what impact of locale is on these tests)
        tests = (
            (2, False, 1.0, '1.00'),
            (2, True, 1.0, '1'),
            (2, False, 1.234, '1.23'),
            (2, True, 1.234, '1.23'),
            (2, False, 1.236, '1.24'),
            (2, False, -1.236, '-1.24'),
            (2, False, -0.004, '0.00'),
            (2, True, 1.002, '1'),
            (2, True, 1.006, '1.01'),
            (2, True, 1.096, '1.1'),
            (3, True, 1.096, '1.096'),
            (-2, True, 1496.45, '1500'),
            (-2, True, 149.45, '100'),
            (-2, True, 79.45, '100'),
            (-2, True, 49.45, '0'),
            (-2, True, -49.45, '0'),
            (-2, True, -149.45, '-100'),
        )
        for f in tests:
            precision, trim, value, expected = f
            format.setPrecision(precision)
            format.setTrimTrailingZeroes(trim)
            result = format.formatNumber(value)
            self.assertEqual(result, expected,
                             "Number format error {0}:{1}:{2} => {3}".format(
                                 precision, trim, value, result))

        # Label tests - label format, expected result.
        # Labels will be evaluated with lower=1.23 upper=2.34, precision=2
        ltests = (
            ("%1 - %2", "1.23 - 2.34"),
            ("%1", "1.23"),
            ("%2", "2.34"),
            ("%2%", "2.34%"),
            ("%1%1", "1.231.23"),
            ("from %1 to %2 meters", "from 1.23 to 2.34 meters"),
            ("from %2 to %1 meters", "from 2.34 to 1.23 meters"),
        )
        format.setPrecision(2)
        format.setTrimTrailingZeroes(False)
        lower = 1.232
        upper = 2.339
        for t in ltests:
            label, expected = t
            format.setFormat(label)
            result = format.labelForLowerUpper(lower, upper)
            self.assertEqual(result, expected, "Label format error {0} => {1}".format(
                label, result))

        range = QgsRendererRange()
        range.setLowerValue(lower)
        range.setUpperValue(upper)
        label = ltests[0][0]
        format.setFormat(label)
        result = format.labelForRange(range)
        self.assertEqual(result, ltests[0][1], "Label for range error {0} => {1}".format(
                         label, result))