Skip to content
Permalink
Browse files

Add a Python repr for QgsError

  • Loading branch information
nyalldawson committed Oct 23, 2018
1 parent adec719 commit 4212cca56ef8ed792b8525532045ad5880e4ad05
Showing with 21 additions and 1 deletion.
  1. +7 −0 python/core/auto_generated/qgserror.sip.in
  2. +9 −0 src/core/qgserror.h
  3. +5 −1 tests/src/python/test_python_repr.py
@@ -126,6 +126,13 @@ messageList return the list of current error messages
:return: current list of error messages
%End


SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsError: %1>" ).arg( sipCpp->message( QgsErrorMessage::Text ) );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};

/************************************************************************
@@ -132,6 +132,15 @@ class CORE_EXPORT QgsError
*/
QList<QgsErrorMessage> messageList() const { return mMessageList; }


#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsError: %1>" ).arg( sipCpp->message( QgsErrorMessage::Text ) );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

private:
//! List of messages
QList<QgsErrorMessage> mMessageList;
@@ -17,7 +17,7 @@
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, QgsExpression, QgsField
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle, QgsExpression, QgsField, QgsError

start_app()

@@ -121,6 +121,10 @@ def testQgsFieldRepr(self):
f = QgsField('field_name', QVariant.Double, 'double')
self.assertEqual(f.__repr__(), "<QgsField: field_name (double)>")

def testQgsErrorRepr(self):
e = QgsError('you done wrong son', 'dad')
self.assertEqual(e.__repr__(), "<QgsError: dad you done wrong son>")


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

0 comments on commit 4212cca

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