Skip to content
Permalink
Browse files
Add equality operator to QgsReadWriteContext::ReadWriteMessage
  • Loading branch information
nyalldawson committed May 24, 2021
1 parent 5f9d7b4 commit e4a12e5fd02e41ea31ea075313e42c7a45819b0d
@@ -45,6 +45,16 @@ Returns the message level
Returns the stack of categories of the message
%End

bool operator==( const QgsReadWriteContext::ReadWriteMessage &other ) const;

bool operator!=( const QgsReadWriteContext::ReadWriteMessage &other ) const;

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

};

QgsReadWriteContext();
@@ -57,6 +57,24 @@ class CORE_EXPORT QgsReadWriteContext
//! Returns the stack of categories of the message
QStringList categories() const {return mCategories;}

bool operator==( const QgsReadWriteContext::ReadWriteMessage &other ) const
{
return mMessage == other.mMessage && mLevel == other.mLevel && mCategories == other.mCategories;
}

bool operator!=( const QgsReadWriteContext::ReadWriteMessage &other ) const
{
return !( *this == other );
}

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

private:
QString mMessage;
Qgis::MessageLevel mLevel;
@@ -49,6 +49,16 @@ def testEnterCategory(self):
self.assertEqual(messages[4].message(), 'msg4')
self.assertEqual(messages[4].categories(), [])

def test_message_equality(self):
"""
Test QgsReadWriteContext.ReadWriteMessage equality operator
"""
m1 = QgsReadWriteContext.ReadWriteMessage('m1', Qgis.Info, ['cat1', 'cat2'])
self.assertEqual(m1, QgsReadWriteContext.ReadWriteMessage('m1', Qgis.Info, ['cat1', 'cat2']))
self.assertNotEqual(m1, QgsReadWriteContext.ReadWriteMessage('m2', Qgis.Info, ['cat1', 'cat2']))
self.assertNotEqual(m1, QgsReadWriteContext.ReadWriteMessage('m1', Qgis.Warning, ['cat1', 'cat2']))
self.assertNotEqual(m1, QgsReadWriteContext.ReadWriteMessage('m1', Qgis.Info, ['cat3', 'cat2']))


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

0 comments on commit e4a12e5

Please sign in to comment.