Skip to content

Commit

Permalink
Python __repr__ test output
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 19, 2018
1 parent 763dfd2 commit ff1988f
Show file tree
Hide file tree
Showing 31 changed files with 52 additions and 51 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscircle.sip.in
Expand Up @@ -255,7 +255,7 @@ Returns true if the circle contains the ``point``.

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QString( "<QgsCircle %1>" ).arg( sipCpp->toString() );
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
};
Expand Down
Expand Up @@ -164,7 +164,7 @@ Sets the circular string's points

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

Expand Down
Expand Up @@ -168,7 +168,7 @@ Appends first point if not already closed.

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscurvepolygon.sip.in
Expand Up @@ -218,7 +218,7 @@ Returns approximate rotation angle for a vertex. Usually average angle between a

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsellipse.sip.in
Expand Up @@ -250,7 +250,7 @@ Members will be truncated to the specified precision.

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -1292,7 +1292,7 @@ Exports the geometry to WKT

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -319,7 +319,7 @@ of the curve.

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmulticurve.sip.in
Expand Up @@ -58,7 +58,7 @@ Returns a copy of the multi curve, where each component curve has had its line d

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

Expand Down
Expand Up @@ -55,7 +55,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmultipoint.sip.in
Expand Up @@ -57,7 +57,7 @@ Multi point geometry collection.

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmultipolygon.sip.in
Expand Up @@ -56,7 +56,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -428,7 +428,7 @@ Angle undefined. Always returns 0.0

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgspolygon.sip.in
Expand Up @@ -67,7 +67,7 @@ negative if the point lies outside the polygon.

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsrectangle.sip.in
Expand Up @@ -324,7 +324,7 @@ Converts the rectangle to a 3D box, with the specified

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgspointxy.sip.in
Expand Up @@ -230,7 +230,7 @@ Multiply x and y by the given value

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

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircle.h
Expand Up @@ -250,7 +250,7 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCircle %1>" ).arg( sipCpp->toString() );
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircularstring.h
Expand Up @@ -149,7 +149,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCircularString %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscompoundcurve.h
Expand Up @@ -149,7 +149,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCompoundCurve %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscurvepolygon.h
Expand Up @@ -207,7 +207,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCurvePolygon %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsellipse.h
Expand Up @@ -243,7 +243,7 @@ class CORE_EXPORT QgsEllipse
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsEllipse %1>" ).arg( sipCpp->toString() );
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -1251,7 +1251,7 @@ class CORE_EXPORT QgsGeometry
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsGeometry %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgslinestring.h
Expand Up @@ -349,7 +349,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsLineString %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmulticurve.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMulitCurve %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsMulitCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultilinestring.h
Expand Up @@ -68,7 +68,7 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiLineString %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultipoint.h
Expand Up @@ -69,7 +69,7 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiPoint %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultipolygon.h
Expand Up @@ -68,7 +68,7 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiPolygon %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgspoint.h
Expand Up @@ -498,7 +498,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsPoint %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgspolygon.h
Expand Up @@ -87,7 +87,7 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsPolygon %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsrectangle.h
Expand Up @@ -544,7 +544,7 @@ class CORE_EXPORT QgsRectangle
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsRectangle %1>" ).arg( sipCpp->asWktCoordinates() );
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspointxy.h
Expand Up @@ -297,7 +297,7 @@ class CORE_EXPORT QgsPointXY
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsPointXY %1>" ).arg( sipCpp->asWkt() );
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End

Expand Down
43 changes: 22 additions & 21 deletions tests/src/python/test_python_repr.py
Expand Up @@ -13,63 +13,64 @@
__revision__ = '$Format:%H$'

import qgis # NOQA
import os

from qgis.testing import unittest, start_app
from qgis.core import QgsGeometry, QgsPoint, QgsPointXY, QgsCircle, QgsCircularString, QgsCompoundCurve, QgsCurve,\
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsMultiLineString, QgsMultiPoint, QgsMultiPolygon,\
QgsPolygon, QgsRectangle

import sip
from qgis.core import QgsGeometry, QgsPoint, QgsPointXY, QgsCircle, QgsCircularString, QgsCompoundCurve,\
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle

start_app()


class TestCoreAdditions(unittest.TestCase):
class TestPython__repr__(unittest.TestCase):

def TestQgsGeometryRepr(self):
p = QgsPointXY(123.456, 987.654)
g = QgsGeometry.fromPointXY(p)
self.assertTrue(g.__repr__().startswith('<QgsGeometry: Point (123.456)'))

def TestQgsPointRepr(self):
p = QgsPoint(123.456, 987.654, 100)
print(p)
self.assertTrue(p.__repr__().startswith('<QgsPoint: PointZ (123.456)'))

def TestQgsPointXYRepr(self):
p = QgsPointXY(123.456, 987.654)
print(p)
self.assertTrue(p.__repr__().startswith('<QgsPointXY: POINT(123.456'))

def TestQgsCircleRepr(self):
c = QgsCircle(QgsPoint(1, 1), 2.0)
print(c)
self.assertEqual(c.__repr__(), '<QgsCircle: Circle (Center: Point (1 1), Radius: 2, Azimuth: 0)>')

def TestQgsCircularstringRepr(self):
cs = QgsCircularString(QgsPoint(1, 2), QgsPoint(2, 3), QgsPoint(3, 4))
print(cs)
self.assertEqual(cs.__repr__(), '<QgsCompoundCurve: CompoundCurve (CircularString (1 2, 2 3, 3 4))>')

def TestQgsCompoundcurveRepr(self):
cs = QgsCircularString(QgsPoint(1, 2), QgsPoint(2, 3), QgsPoint(3, 4))
cc = QgsCompoundCurve()
cc.addCurve(cs)
print(cc)
self.assertEqual(cc.__repr__(), '<QgsCompoundCurve: CompoundCurve (CircularString (1 2, 2 3, 3 4))>')

def TestQgsCurvepolygonRepr(self):
cp = QgsCurvePolygon()
cs = QgsCircularString(QgsPoint(1, 10), QgsPoint(2, 11), QgsPoint(1, 10))
cp.setExteriorRing(cs)
print(cp)
self.assertEqual(cp.__repr__(), '<QgsCurvePolygon: CurvePolygon (CircularString (1 10, 2 11, 1 10))>')

def TestQgsEllipseRepr(self):
e = QgsEllipse(QgsPoint(1, 2), 2.0, 3.0)
print(e)
self.assertEqual(e.__repr__(), '<QgsEllipse: Ellipse (Center: Point (1 2), Semi-Major Axis: 3, Semi-Minor Axis: 2, Azimuth: 180)>')

def TestQgsLineStringRepr(self):
ls = QgsLineString([QgsPoint(10, 2), QgsPoint(10, 1), QgsPoint(5, 1)])
print(ls)
self.assertEqual(ls.__repr__(), '<QgsLineString: LineString (10 2, 10 1, 5 1)>')

def TestQgsMulticurveRepr(self):
mc = QgsMultiCurve()
cs = QgsCircularString(QgsPoint(1, 10), QgsPoint(2, 11), QgsPoint(3, 12))
mc.addGeometry(cs)
cs2 = QgsCircularString(QgsPoint(4, 20), QgsPoint(5, 22), QgsPoint(6, 24))
mc.addGeometry(cs2)
print(mc)
self.assertEqual(mc.__repr__(), '<QgsMulitCurve: MultiCurve (CircularString (1 10, 2 11, 3 12),CircularString (4 20, 5 22, 6 24))>')

def TestQgsMultilineStringRepr(self):
ml = QgsGeometry.fromMultiPolylineXY(
Expand All @@ -78,12 +79,12 @@ def TestQgsMultilineStringRepr(self):
[QgsPointXY(3, 0), QgsPointXY(3, 1), QgsPointXY(5, 1), QgsPointXY(5, 0), QgsPointXY(6, 0), ]
]
)
print(ml)
self.assertEqual(ml.constGet().__repr__(), '<QgsMultiLineString: MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0),(3 0, 3 1, 5 1, 5 0, 6 0))>')

def TestQgsMultiPointRepr(self):
wkt = "MultiPoint ((10 30),(40 20),(30 10),(20 10))"
mp = QgsGeometry.fromWkt(wkt)
print(mp)
self.assertEqual(mp.constGet().__repr__(), '<QgsMultiPoint: MultiPoint ((10 30),(40 20),(30 10),(20 10))>')

def TestQgsMultipolygonRepr(self):
mp = QgsGeometry.fromMultiPolygonXY([
Expand All @@ -96,7 +97,7 @@ def TestQgsMultipolygonRepr(self):
QgsPointXY(3, 1),
QgsPointXY(2, 2)]]
])
print(mp)
self.assertEqual(mp.constGet().__repr__(), '<QgsMultiPolygon: MultiPolygon (((1 1, 2 2, 1 2, 1 1)),((2 2, 3 3, 3 1, 2 2)))>')

def TestQgsPolygonRepr(self):
p = QgsGeometry.fromPolygonXY(
Expand All @@ -105,11 +106,11 @@ def TestQgsPolygonRepr(self):
QgsPointXY(2, 2),
QgsPointXY(0, 2),
QgsPointXY(0, 0)]])
print(p)
self.assertEqual(p.constGet().__repr__(), '<QgsPolygon: Polygon ((0 0, 2 0, 2 2, 0 2, 0 0))>')

def TestQgsRectangleRepr(self):
r = QgsRectangle(1, 2, 3, 4)
print(r)
self.assertEqual(r.constGet().__repr__(), '<QgsRectangle: 1 2, 3 4>')


if __name__ == "__main__":
Expand Down

0 comments on commit ff1988f

Please sign in to comment.