Skip to content
Permalink
Browse files

Merge pull request #9278 from nyalldawson/backports36

  • Loading branch information
nyalldawson committed Feb 25, 2019
2 parents a95f872 + d180038 commit bb5a3602186b9113707a859fd0c45819b08bbfb3
@@ -176,7 +176,7 @@ def _create_param(self, type, output=False, **kwargs):
if parentname == name:
raise ProcessingAlgFactoryException("{} can't depend on itself. "
"We know QGIS is smart but it's not that smart".format(name))
if parentname not in self._inputs or parentname not in self._outputs:
if parentname not in self._inputs and parentname not in self._outputs:
raise ProcessingAlgFactoryException("Can't find parent named {}".format(parentname))

kwargs['description'] = kwargs.pop("label", "")
@@ -211,7 +211,8 @@ def has_outputs(self):
"""
True if this alg wrapper has outputs defined.
"""
return bool(self._outputs)
dests = [p for p in self._inputs.values() if p.isDestination()]
return bool(self._outputs) or bool(dests)

@property
def has_inputs(self):
@@ -474,18 +474,19 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
int index = 0;
while ( index < action.size() )
{
QRegExp rx = QRegExp( "\\[%([^\\]]+)%\\]" );
static const QRegularExpression sRegEx{ QStringLiteral( "\\[%(.*?)%\\]" ) };

int pos = rx.indexIn( action, index );
if ( pos < 0 )
const QRegularExpressionMatch match = sRegEx.match( action, index );
if ( !match.hasMatch() )
break;

int start = index;
index = pos + rx.matchedLength();
QString to_replace = rx.cap( 1 ).trimmed();
QgsDebugMsg( "Found expression: " + to_replace );
const int pos = action.indexOf( sRegEx, index );
const int start = index;
index = pos + match.capturedLength( 0 );
const QString toReplace = match.captured( 1 ).trimmed();
QgsDebugMsg( "Found expression: " + toReplace );

QgsExpression exp( to_replace );
QgsExpression exp( toReplace );
if ( exp.hasParserError() )
{
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
@@ -3404,6 +3404,26 @@ class TestQgsExpression: public QObject
QCOMPARE( zustaendigkeitskataster->dataProvider()->featureCount(), 4l );
}

void testReplaceExpressionText_data()
{
QTest::addColumn<QString>( "input" );
QTest::addColumn<QString>( "expected" );
QTest::newRow( "no exp" ) << "some text" << "some text";
QTest::newRow( "simple exp" ) << "some text [% 1 + 2 %]" << "some text 3";
QTest::newRow( "multiple exp" ) << "some [% 3+ 7 %] text [% 1 + 2 %]" << "some 10 text 3";
QTest::newRow( "complex" ) << "some [%map('a', 1, 'b', 2)['a']%] text [%map('a', 1, 'b', 2)['b']%]" << "some 1 text 2";
QTest::newRow( "complex2" ) << "some [% 'my text]' %] text" << "some my text] text";
}

void testReplaceExpressionText()
{
QFETCH( QString, input );
QFETCH( QString, expected );

QgsExpressionContext context;
QCOMPARE( QgsExpression::replaceExpressionText( input, &context ), expected );
}

};

QGSTEST_MAIN( TestQgsExpression )
@@ -37,6 +37,19 @@ def testalg(instance, parameters, context, feedback, inputs):
"""


def define_new_no_outputs_but_sink_instead(newid=1):
@alg(name=ARGNAME.format(newid), label=alg.tr("Test func"), group="unittest",
group_label=alg.tr("Test label"))
@alg.help(HELPSTRING.format(newid))
@alg.input(type=alg.SOURCE, name="INPUT", label="Input layer")
@alg.input(type=alg.DISTANCE, name="DISTANCE", label="Distance", default=30)
@alg.input(type=alg.SINK, name="SINK", label="Output layer")
def testalg(instance, parameters, context, feedback, inputs):
"""
Given a distance will split a line layer into segments of the distance
"""


def define_new_doc_string(newid=1):
@alg(name=ARGNAME.format(newid), label=alg.tr("Test func"), group="unittest",
group_label=alg.tr("Test label"))
@@ -75,6 +88,15 @@ def test_can_have_no_inputs(self):
define_new_no_inputs()


class AlgNoOutputsButSinkInstead(unittest.TestCase):

def setUp(self):
cleanup()

def test_can_have_no_outputs_if_there_is_destination(self):
define_new_no_outputs_but_sink_instead()


class AlgInstanceTests(unittest.TestCase):
"""
Tests to check the createInstance method will work as expected.

0 comments on commit bb5a360

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