Skip to content
Permalink
Browse files

[pyqgis] __repr__ method for QgsExpression, QgsField (#7464)

* [pyqgis] __repr__ method for QgsExpression, QgsField

* add tests for __repr__ methods

* Fix test
  • Loading branch information
3nids committed Jul 28, 2018
1 parent e19e1de commit c0dd00615ae107a53a93c84ff514795b5d03c1c3
@@ -586,6 +586,12 @@ value. The value may be null.
.. versionadded:: 3.0
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};


@@ -330,6 +330,12 @@ by manual field configuration.
:return: the value
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsField: %1 (%2)>" ).arg( sipCpp->name() ).arg( sipCpp->typeName() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

}; // class QgsField


@@ -609,6 +609,14 @@ class CORE_EXPORT QgsExpression
*/
static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value );

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

private:
void initGeomCalculator();

@@ -335,6 +335,14 @@ class CORE_EXPORT QgsField
*/
QgsEditorWidgetSetup editorWidgetSetup() const;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsField: %1 (%2)>" ).arg( sipCpp->name() ).arg( sipCpp->typeName() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

private:

QSharedDataPointer<QgsFieldPrivate> d;
@@ -14,9 +14,10 @@

import qgis # NOQA

from PyQt5.QtCore import QVariant
from qgis.testing import unittest, start_app
from qgis.core import QgsGeometry, QgsPoint, QgsPointXY, QgsCircle, QgsCircularString, QgsCompoundCurve,\
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle, QgsExpression, QgsField

start_app()

@@ -112,6 +113,14 @@ def testQgsRectangleRepr(self):
r = QgsRectangle(1, 2, 3, 4)
self.assertEqual(r.__repr__(), '<QgsRectangle: 1 2, 3 4>')

def testQgsExpressionRepr(self):
e = QgsExpression('my expression')
self.assertEqual(e.__repr__(), "<QgsExpression: 'my expression'>")

def testQgsFieldRepr(self):
f = QgsField('field_name', QVariant.Double, 'double')
self.assertEqual(f.__repr__(), "<QgsField: field_name (double)>")


if __name__ == "__main__":
unittest.main()

0 comments on commit c0dd006

Please sign in to comment.
You can’t perform that action at this time.