Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start on a compliance test suite for raster data providers, cleanups #60539

Merged
merged 5 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ Returns a cleansed ``key``
QVariant &operator[]( const QString &key );


bool operator==( const QgsHttpHeaders &other ) const;
bool operator!=( const QgsHttpHeaders &other ) const;

void insert( const QString &key, const QVariant &value );
%Docstring
insert a ``key`` with the specific ``value``
Expand Down
49 changes: 49 additions & 0 deletions python/PyQt6/core/auto_generated/qgsdatasourceuri.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,43 @@ The ``sql`` represents a subset filter string to be applied to the source, and s
form of a SQL "where" clause (e.g. "VALUE > 5", "CAT IN (1,2,3)").

.. seealso:: :py:func:`sql`
%End

void setHost( const QString &host );
%Docstring
Sets the ``host`` name stored in the URI.

.. seealso:: :py:func:`host`

.. versionadded:: 3.42
%End

QString host() const;
%Docstring
Returns the host name stored in the URI.

.. seealso:: :py:func:`setHost`
%End

QString database() const;
%Docstring
Returns the database name stored in the URI.
%End

void setPort( const QString &port );
%Docstring
Sets the ``port`` stored in the URI.

.. seealso:: :py:func:`port`

.. versionadded:: 3.42
%End

QString port() const;
%Docstring
Returns the port stored in the URI.

.. seealso:: :py:func:`setPort`
%End

QString driver() const;
Expand All @@ -278,16 +302,38 @@ Sets the ``driver`` name stored in the URI.
QString password() const;
%Docstring
Returns the password stored in the URI.
%End

void setSslMode( SslMode mode );
%Docstring
Sets the SSL ``mode`` associated with the URI.

.. seealso:: :py:func:`sslMode`

.. versionadded:: 3.42
%End

SslMode sslMode() const;
%Docstring
Returns the SSL mode associated with the URI.

.. seealso:: :py:func:`setSslMode`
%End

void setService( const QString &service );
%Docstring
Sets the ``service`` name associated with the URI.

.. seealso:: :py:func:`service`

.. versionadded:: 3.42
%End

QString service() const;
%Docstring
Returns the service name associated with the URI.

.. seealso:: :py:func:`setService`
%End

QString keyColumn() const;
Expand Down Expand Up @@ -383,6 +429,9 @@ Sets headers to ``headers``
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

bool operator==( const QgsDataSourceUri &other ) const;
bool operator!=( const QgsDataSourceUri &other ) const;

};

/************************************************************************
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/network/qgshttpheaders.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ Returns a cleansed ``key``
QVariant &operator[]( const QString &key );


bool operator==( const QgsHttpHeaders &other ) const;
bool operator!=( const QgsHttpHeaders &other ) const;

void insert( const QString &key, const QVariant &value );
%Docstring
insert a ``key`` with the specific ``value``
Expand Down
49 changes: 49 additions & 0 deletions python/core/auto_generated/qgsdatasourceuri.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,43 @@ The ``sql`` represents a subset filter string to be applied to the source, and s
form of a SQL "where" clause (e.g. "VALUE > 5", "CAT IN (1,2,3)").

.. seealso:: :py:func:`sql`
%End

void setHost( const QString &host );
%Docstring
Sets the ``host`` name stored in the URI.

.. seealso:: :py:func:`host`

.. versionadded:: 3.42
%End

QString host() const;
%Docstring
Returns the host name stored in the URI.

.. seealso:: :py:func:`setHost`
%End

QString database() const;
%Docstring
Returns the database name stored in the URI.
%End

void setPort( const QString &port );
%Docstring
Sets the ``port`` stored in the URI.

.. seealso:: :py:func:`port`

.. versionadded:: 3.42
%End

QString port() const;
%Docstring
Returns the port stored in the URI.

.. seealso:: :py:func:`setPort`
%End

QString driver() const;
Expand All @@ -278,16 +302,38 @@ Sets the ``driver`` name stored in the URI.
QString password() const;
%Docstring
Returns the password stored in the URI.
%End

void setSslMode( SslMode mode );
%Docstring
Sets the SSL ``mode`` associated with the URI.

.. seealso:: :py:func:`sslMode`

.. versionadded:: 3.42
%End

SslMode sslMode() const;
%Docstring
Returns the SSL mode associated with the URI.

.. seealso:: :py:func:`setSslMode`
%End

void setService( const QString &service );
%Docstring
Sets the ``service`` name associated with the URI.

.. seealso:: :py:func:`service`

.. versionadded:: 3.42
%End

QString service() const;
%Docstring
Returns the service name associated with the URI.

.. seealso:: :py:func:`setService`
%End

QString keyColumn() const;
Expand Down Expand Up @@ -383,6 +429,9 @@ Sets headers to ``headers``
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

bool operator==( const QgsDataSourceUri &other ) const;
bool operator!=( const QgsDataSourceUri &other ) const;

};

/************************************************************************
Expand Down
31 changes: 31 additions & 0 deletions python/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import sys
import tempfile
import unittest
import hashlib
from pathlib import Path
from typing import Optional, Tuple, Union
from warnings import warn
Expand Down Expand Up @@ -339,6 +340,36 @@ def strip_std_ignorable_errors(output: str) -> str:
]
)

@staticmethod
def sanitize_local_url(endpoint: str, query: str) -> str:
"""
Sanitizes a URL to a local file path. Matches logic in c++ code so that
remote URLs can be mocked to local test files.
"""
if not os.path.exists(endpoint):
os.makedirs(endpoint)

if query.startswith("/query"):
query = query[len("/query") :]
endpoint = endpoint + "_query"

if len(endpoint + query) > 150:
ret = endpoint + hashlib.md5(query.encode()).hexdigest()
# print('Before: ' + endpoint + query)
# print('After: ' + ret)
return ret
return endpoint + query.replace("?", "_").replace("&", "_").replace(
"<", "_"
).replace(">", "_").replace('"', "_").replace("'", "_").replace(
" ", "_"
).replace(
":", "_"
).replace(
"/", "_"
).replace(
"\n", "_"
)

def assertLayersEqual(self, layer_expected, layer_result, **kwargs):
"""
:param layer_expected: The first layer to compare
Expand Down
10 changes: 10 additions & 0 deletions src/core/network/qgshttpheaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,13 @@ void QgsHttpHeaders::insert( const QString &key, const QVariant &val )
}
mHeaders.insert( k2, val );
}

bool QgsHttpHeaders::operator==( const QgsHttpHeaders &other ) const
{
return mHeaders == other.mHeaders;
}

bool QgsHttpHeaders::operator!=( const QgsHttpHeaders &other ) const
{
return !( *this == other );
}
3 changes: 3 additions & 0 deletions src/core/network/qgshttpheaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class CORE_EXPORT QgsHttpHeaders

QgsHttpHeaders &operator = ( const QMap<QString, QVariant> &headers ) SIP_SKIP;

bool operator==( const QgsHttpHeaders &other ) const;
bool operator!=( const QgsHttpHeaders &other ) const;

/**
* \brief insert a \a key with the specific \a value
* \param key a key to add
Expand Down
60 changes: 60 additions & 0 deletions src/core/qgsdatasourceuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,26 @@ QString QgsDataSourceUri::database() const
return mDatabase;
}

void QgsDataSourceUri::setPort( const QString &port )
{
mPort = port;
}

QString QgsDataSourceUri::password() const
{
return mPassword;
}

void QgsDataSourceUri::setSslMode( SslMode mode )
{
mSSLmode = mode;
}

void QgsDataSourceUri::setService( const QString &service )
{
mService = service;
}

void QgsDataSourceUri::setPassword( const QString &password )
{
mPassword = password;
Expand Down Expand Up @@ -436,6 +451,11 @@ void QgsDataSourceUri::setSql( const QString &sql )
mSql = sql;
}

void QgsDataSourceUri::setHost( const QString &host )
{
mHost = host;
}

void QgsDataSourceUri::clearSchema()
{
mSchema.clear();
Expand Down Expand Up @@ -980,3 +1000,43 @@ QSet<QString> QgsDataSourceUri::parameterKeys() const
paramKeys.insert( QLatin1String( "srid" ) );
return paramKeys;
}

bool QgsDataSourceUri::operator==( const QgsDataSourceUri &other ) const
{
// cheap comparisons first:
if ( mUseEstimatedMetadata != other.mUseEstimatedMetadata ||
mSelectAtIdDisabled != other.mSelectAtIdDisabled ||
mSelectAtIdDisabledSet != other.mSelectAtIdDisabledSet ||
mSSLmode != other.mSSLmode ||
mWkbType != other.mWkbType )
{
return false;
}

if ( mHost != other.mHost ||
mPort != other.mPort ||
mDriver != other.mDriver ||
mService != other.mService ||
mDatabase != other.mDatabase ||
mSchema != other.mSchema ||
mTable != other.mTable ||
mGeometryColumn != other.mGeometryColumn ||
mSql != other.mSql ||
mAuthConfigId != other.mAuthConfigId ||
mUsername != other.mUsername ||
mPassword != other.mPassword ||
mKeyColumn != other.mKeyColumn ||
mSrid != other.mSrid ||
mParams != other.mParams ||
mHttpHeaders != other.mHttpHeaders )
{
return false;
}

return true;
}

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