Skip to content
Permalink
Browse files

Python __repr__ test output

  • Loading branch information
3nids committed Jun 19, 2018
1 parent 763dfd2 commit ff1988f11d47db8a0b97875db06c84aced38eacc
Showing with 52 additions and 51 deletions.
  1. +1 −1 python/core/auto_generated/geometry/qgscircle.sip.in
  2. +1 −1 python/core/auto_generated/geometry/qgscircularstring.sip.in
  3. +1 −1 python/core/auto_generated/geometry/qgscompoundcurve.sip.in
  4. +1 −1 python/core/auto_generated/geometry/qgscurvepolygon.sip.in
  5. +1 −1 python/core/auto_generated/geometry/qgsellipse.sip.in
  6. +1 −1 python/core/auto_generated/geometry/qgsgeometry.sip.in
  7. +1 −1 python/core/auto_generated/geometry/qgslinestring.sip.in
  8. +1 −1 python/core/auto_generated/geometry/qgsmulticurve.sip.in
  9. +1 −1 python/core/auto_generated/geometry/qgsmultilinestring.sip.in
  10. +1 −1 python/core/auto_generated/geometry/qgsmultipoint.sip.in
  11. +1 −1 python/core/auto_generated/geometry/qgsmultipolygon.sip.in
  12. +1 −1 python/core/auto_generated/geometry/qgspoint.sip.in
  13. +1 −1 python/core/auto_generated/geometry/qgspolygon.sip.in
  14. +1 −1 python/core/auto_generated/geometry/qgsrectangle.sip.in
  15. +1 −1 python/core/auto_generated/qgspointxy.sip.in
  16. +1 −1 src/core/geometry/qgscircle.h
  17. +1 −1 src/core/geometry/qgscircularstring.h
  18. +1 −1 src/core/geometry/qgscompoundcurve.h
  19. +1 −1 src/core/geometry/qgscurvepolygon.h
  20. +1 −1 src/core/geometry/qgsellipse.h
  21. +1 −1 src/core/geometry/qgsgeometry.h
  22. +1 −1 src/core/geometry/qgslinestring.h
  23. +1 −1 src/core/geometry/qgsmulticurve.h
  24. +1 −1 src/core/geometry/qgsmultilinestring.h
  25. +1 −1 src/core/geometry/qgsmultipoint.h
  26. +1 −1 src/core/geometry/qgsmultipolygon.h
  27. +1 −1 src/core/geometry/qgspoint.h
  28. +1 −1 src/core/geometry/qgspolygon.h
  29. +1 −1 src/core/geometry/qgsrectangle.h
  30. +1 −1 src/core/qgspointxy.h
  31. +22 −21 tests/src/python/test_python_repr.py
@@ -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
};
@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

@@ -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(
@@ -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([
@@ -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(
@@ -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__":

0 comments on commit ff1988f

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