Merge pull request #7171 from 3nids/sip_python_repr

create Python __repr__ methods for QgsPoint and QgsPointXY
This commit is contained in:
Denis Rouzaud 2018-06-19 09:56:28 -08:00 committed by GitHub
commit d36015070c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 358 additions and 12 deletions

View File

@ -253,6 +253,11 @@ Returns true if the circle contains the ``point``.
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
};
/************************************************************************

View File

@ -162,6 +162,12 @@ Sets the circular string's points
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual QgsRectangle calculateBoundingBox() const;

View File

@ -166,6 +166,12 @@ Appends first point if not already closed.
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual QgsRectangle calculateBoundingBox() const;

View File

@ -216,6 +216,12 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual int childCount() const;

View File

@ -248,6 +248,12 @@ returns a string representation of the ellipse.
Members will be truncated to the specified precision.
%End
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
};

View File

@ -1290,6 +1290,12 @@ Exports the geometry to WKT
precision parameter added in QGIS 2.4
%End
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
QString asJson( int precision = 17 ) const;
%Docstring
Exports the geometry to a GeoJSON string.

View File

@ -317,6 +317,12 @@ of the curve.
virtual QgsLineString *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual QgsRectangle calculateBoundingBox() const;

View File

@ -56,6 +56,11 @@ Returns a copy of the multi curve, where each component curve has had its line d
virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMulitCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
};

View File

@ -53,6 +53,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual bool wktOmitChildType() const;

View File

@ -55,6 +55,12 @@ Multi point geometry collection.
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual bool wktOmitChildType() const;

View File

@ -54,6 +54,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual bool wktOmitChildType() const;

View File

@ -426,6 +426,12 @@ Angle undefined. Always returns 0.0
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:
virtual int childCount() const;

View File

@ -65,6 +65,12 @@ negative if the point lies outside the polygon.
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
protected:

View File

@ -322,6 +322,12 @@ Converts the rectangle to a 3D box, with the specified
operator QVariant() const;
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
};

View File

@ -230,8 +230,7 @@ Multiply x and y by the given value
SIP_PYOBJECT __repr__();
%MethodCode
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

View File

@ -694,7 +694,7 @@ while ($LINE_IDX < $LINE_COUNT){
}
# SIP_SKIP
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_OPERATOR_/ ){
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_SPECIAL_/ ){
dbg_info('SIP SKIP!');
# if multiline definition, remove previous lines
if ( $MULTILINE_DEFINITION != MULTILINE_NO){
@ -711,9 +711,18 @@ while ($LINE_IDX < $LINE_COUNT){
detect_and_remove_following_body_or_initializerlist();
# line skipped, go to next iteration
if ($LINE =~ m/SIP_PYTHON_OPERATOR_(\w+)\(\s*(\w+)\s*\)/ ){
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
dbg_info("PYTHON OPERATOR $pyop");
if ($LINE =~ m/SIP_PYTHON_SPECIAL_(\w+)\(\s*(".*"|\w+)\s*\)/ ){
my $method_or_code = $2;
dbg_info("PYTHON SPECIAL method or code: $method_or_code");
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: ";
if ( $method_or_code =~ m/^"(.*)"$/ ){
$pyop .= $1;
}
else
{
$pyop .= "self.${method_or_code}()";
}
dbg_info("PYTHON SPECIAL $pyop");
if ($python_output ne ''){
push @OUTPUT_PYTHON, "$pyop\n";
}

View File

@ -39,6 +39,16 @@ count=0
modules=(core gui analysis server)
for module in "${modules[@]}"; do
# clean auto_additions and auto_generated folders
rm -rf python/${module}/auto_additions/*.py
rm -rf python/${module}/auto_generated/*.py
# put back __init__.py
echo '"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""' > python/${module}/auto_additions/__init__.py
while read -r sipfile; do
echo "$sipfile.in"
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)

View File

@ -247,6 +247,13 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
};
#endif // QGSCIRCLE_H

View File

@ -146,6 +146,14 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
QgsRectangle calculateBoundingBox() const override;

View File

@ -146,6 +146,14 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
QgsRectangle calculateBoundingBox() const override;

View File

@ -204,6 +204,14 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
int childCount() const override;

View File

@ -240,6 +240,14 @@ class CORE_EXPORT QgsEllipse
*/
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
QgsPoint mCenter;
double mSemiMajorAxis = 0.0;

View File

@ -1248,6 +1248,14 @@ class CORE_EXPORT QgsGeometry
*/
QString asWkt( int precision = 17 ) const;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
/**
* Exports the geometry to a GeoJSON string.
*/

View File

@ -346,6 +346,14 @@ class CORE_EXPORT QgsLineString: public QgsCurve
QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
QgsRectangle calculateBoundingBox() const override;

View File

@ -73,6 +73,13 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMulitCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
};

View File

@ -65,6 +65,14 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
bool wktOmitChildType() const override;

View File

@ -66,6 +66,14 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
bool wktOmitChildType() const override;

View File

@ -65,6 +65,14 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
bool wktOmitChildType() const override;

View File

@ -495,6 +495,14 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
int childCount() const override;

View File

@ -84,6 +84,14 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
protected:
friend class QgsCurvePolygon;

View File

@ -541,6 +541,14 @@ class CORE_EXPORT QgsRectangle
return QVariant::fromValue( *this );
}
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif
private:
double mXmin = 0.0;

View File

@ -198,9 +198,19 @@
#define SIP_DOC_TEMPLATE
/*
* Define the __bool__ operator using the given method
* sipify.pl will take care of creating the injection in qgis/{module}/__init__.py
* Define Python special method (bool, repr, etc.) using the given method or code
* sipify.pl will create a dedicated python file named according to the class
* and located in python/{module}/auto_additions/{classname}.py
* a simple method name can be provided (e.g. isValid) and sipify will create the proper code
* or some Python code can be provided:
*
* SIP_PYTHON_SPECIAL_BOOL( isValid )
* => sipify => MyClass.__bool__ = lambda self: self.isValid()
*
* SIP_PYTHON_SPECIAL_REPR( "'<MyClass {}>'format(self.toString())'" )
* => sipify => MyClass.__repr__ = lambda self: '<MyClass {}>'format(self.toString())'
*/
#define SIP_PYTHON_OPERATOR_BOOL(method)
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
#define SIP_PYTHON_SPECIAL_REPR(method_or_code)
#endif // QGIS_SIP_H

View File

@ -95,7 +95,7 @@ class CORE_EXPORT QgsDefaultValue
* Checks if a default value is set. Alias for isValid().
* \returns false if the expression is a null string.
*/
operator bool() const SIP_PYTHON_OPERATOR_BOOL( isValid );
operator bool() const SIP_PYTHON_SPECIAL_BOOL( isValid );
private:
QString mExpression;

View File

@ -297,8 +297,7 @@ class CORE_EXPORT QgsPointXY
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End

View File

@ -16,6 +16,15 @@ modules=(core gui analysis server)
code=0
for module in "${modules[@]}"; do
# clean auto_additions and auto_generated folders
rm -rf python/${module}/auto_additions/*.py
rm -rf python/${module}/auto_generated/*.py
# put back __init__.py
echo '"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""' > python/${module}/auto_additions/__init__.py
module_init=${DIR}/python/${module}/__init__.py
cp ${module_init} ${DIR}/${module}.temp
while read -r sipfile; do

View File

@ -9,6 +9,7 @@ IF (WITH_SERVER)
ENDIF (WITH_SERVER)
ADD_PYTHON_TEST(PyCoreAdittions test_core_additions.py)
ADD_PYTHON_TEST(PyPythonRepr test_python_repr.py)
ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)

View File

@ -0,0 +1,117 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for core additions
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Denis Rouzaud'
__date__ = '05.06.2018'
__copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis # NOQA
from qgis.testing import unittest, start_app
from qgis.core import QgsGeometry, QgsPoint, QgsPointXY, QgsCircle, QgsCircularString, QgsCompoundCurve,\
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle
start_app()
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)
self.assertTrue(p.__repr__().startswith('<QgsPoint: PointZ (123.456)'))
def TestQgsPointXYRepr(self):
p = QgsPointXY(123.456, 987.654)
self.assertTrue(p.__repr__().startswith('<QgsPointXY: POINT(123.456'))
def TestQgsCircleRepr(self):
c = QgsCircle(QgsPoint(1, 1), 2.0)
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))
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)
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)
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)
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)])
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)
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(
[
[QgsPointXY(0, 0), QgsPointXY(1, 0), QgsPointXY(1, 1), QgsPointXY(2, 1), QgsPointXY(2, 0), ],
[QgsPointXY(3, 0), QgsPointXY(3, 1), QgsPointXY(5, 1), QgsPointXY(5, 0), QgsPointXY(6, 0), ]
]
)
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)
self.assertEqual(mp.constGet().__repr__(), '<QgsMultiPoint: MultiPoint ((10 30),(40 20),(30 10),(20 10))>')
def TestQgsMultipolygonRepr(self):
mp = QgsGeometry.fromMultiPolygonXY([
[[QgsPointXY(1, 1),
QgsPointXY(2, 2),
QgsPointXY(1, 2),
QgsPointXY(1, 1)]],
[[QgsPointXY(2, 2),
QgsPointXY(3, 3),
QgsPointXY(3, 1),
QgsPointXY(2, 2)]]
])
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(
[[QgsPointXY(0, 0),
QgsPointXY(2, 0),
QgsPointXY(2, 2),
QgsPointXY(0, 2),
QgsPointXY(0, 0)]])
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)
self.assertEqual(r.constGet().__repr__(), '<QgsRectangle: 1 2, 3 4>')
if __name__ == "__main__":
unittest.main()