def test_representValue(self): layer = QgsVectorLayer("point?field=int:integer&field=double:double&field=long:long", "layer", "memory") self.assertTrue(layer.isValid()) QgsProject.instance().addMapLayers([layer]) fieldFormatter = QgsRangeFieldFormatter() # Precision is ignored for integers and longlongs self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123000'), '123,000') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9,999,999') # no scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123,000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9,999,999') # no scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, '123'), '123.0') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123,000.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0.000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0.127') # Check with Italian locale QLocale.setDefault(QLocale('it')) self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9.999.999') # scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123.000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9.999.999') # scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123.000,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0,000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0,127') # Check with custom locale without thousand separator custom = QLocale('en') custom.setNumberOptions(QLocale.OmitGroupSeparator) QLocale.setDefault(custom) self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9999999') # scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9999999') # scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000.00') QgsProject.instance().removeAllMapLayers()
def test_representValue(self): layer = QgsVectorLayer("point?field=int:integer&field=double:double", "layer", "memory") self.assertTrue(layer.isValid()) QgsProject.instance().addMapLayers([layer]) fieldFormatter = QgsRangeFieldFormatter() # Precision is ignored for integers self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123000'), '123000') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, '123'), '123.0') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0.000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0.127') QgsSettings().setValue("locale/overrideFlag", True) QgsSettings().setValue("locale/userLocale", 'it') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0,000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0,127') QgsProject.instance().removeAllMapLayers()
def test_representValue(self): layer = QgsVectorLayer("point?field=int:integer&field=double:double&field=long:long", "layer", "memory") self.assertTrue(layer.isValid()) QgsProject.instance().addMapLayers([layer]) fieldFormatter = QgsRangeFieldFormatter() # Precision is ignored for integers and longlongs self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123000'), '123,000') self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9,999,999') # no scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123,000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9,999,999') # no scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, '123'), '123.0') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123,000.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0.000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123.00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0.12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0.13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0.127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0.127') # Check with Italian locale QLocale.setDefault(QLocale('it')) self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9.999.999') # scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123.000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9.999.999') # scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123.000,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0,000') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123,00') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0,12') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0,13') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0,127') self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0,127') # Check with custom locale without thousand separator custom = QLocale('en') custom.setNumberOptions(QLocale.OmitGroupSeparator) QLocale.setDefault(custom) self.assertEqual(fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '9999999'), '9999999') # scientific notation for integers! self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123'), '123') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '123000'), '123000') self.assertEqual(fieldFormatter.representValue(layer, 2, {'Precision': 1}, None, '9999999'), '9999999') # scientific notation for long longs! self.assertEqual(fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000.00') QgsProject.instance().removeAllMapLayers()
def test_representValue(self): layer = QgsVectorLayer("point?field=int:integer&field=double:double", "layer", "memory") self.assertTrue(layer.isValid()) QgsProject.instance().addMapLayers([layer]) fieldFormatter = QgsRangeFieldFormatter() # Precision is ignored for integers self.assertEqual( fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123'), '123') self.assertEqual( fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, '123000'), '123000') self.assertEqual( fieldFormatter.representValue(layer, 0, {'Precision': 1}, None, None), 'NULL') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, None), 'NULL') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 1}, None, '123'), '123.0') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000.00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0.00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123.00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0.12') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0.13') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0.000') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0.127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0.127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123.00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0.12') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0.13') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0.127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0.127') QgsSettings().setValue("locale/overrideFlag", True) QgsSettings().setValue("locale/userLocale", 'it') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, None), 'NULL') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123000'), '123000,00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0'), '0,00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '123'), '123,00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.123'), '0,12') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '0.127'), '0,13') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0'), '0,000') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '0.127'), '0,127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '1.27e-1'), '0,127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-123'), '-123,00') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.123'), '-0,12') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 2}, None, '-0.127'), '-0,13') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-0.127'), '-0,127') self.assertEqual( fieldFormatter.representValue(layer, 1, {'Precision': 3}, None, '-1.27e-1'), '-0,127') QgsProject.instance().removeAllMapLayers()