Skip to content

Commit da40d3d

Browse files
committedMar 10, 2013
[sextante] improved automated test-creation tools
1 parent bd50bf0 commit da40d3d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
 

‎python/plugins/sextante/gui/TestTools.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* *
1717
***************************************************************************
1818
"""
19-
2019
__author__ = 'Victor Olaya'
2120
__date__ = 'February 2013'
2221
__copyright__ = '(C) 2013, Victor Olaya'
2322
# This will get replaced with a git SHA1 when you do a git archive
2423
__revision__ = '$Format:%H$'
2524

25+
import os
2626
from sextante.core.Sextante import Sextante
2727
from sextante.outputs.OutputNumber import OutputNumber
2828
from sextante.outputs.OutputString import OutputString
@@ -42,16 +42,20 @@ def createTest(item):
4242
execcommand = "sextante.runalg("
4343
i = 0
4444
for token in tokens:
45-
if i < alg.getVisibleParametersCount():
45+
if i < alg.getVisibleParametersCount() + 1:
46+
if os.path.exists(token[1:-1]):
47+
token = '"' + os.path.basename(token[1:-1])[:-4] + '"'
4648
execcommand+=token + ","
4749
else:
4850
execcommand+="None,"
4951
i+=1
5052
s += "\toutputs=" + execcommand[:-1] + ")\n"
5153

5254
i = -1 * len(alg.outputs)
53-
for out in alg.outputs:
55+
for out in alg.outputs:
5456
filename = tokens[i][1:-1]
57+
if (filename == str(None)):
58+
raise Exception("Cannot create unit test for that algorithm.\nThe output cannot be a temporary file")
5559
s+="\toutput=outputs['" + out.name + "']\n"
5660
if isinstance(out, (OutputNumber, OutputString)):
5761
s+="self.assertTrue(" + str(out) + ", output)\n"
@@ -69,8 +73,8 @@ def createTest(item):
6973
s+="\texpectedtypes=[" + ",".join([str(f.typeName()) for f in fields]) + "]\n"
7074
s+="\tnames=[str(f.name()) for f in fields]\n"
7175
s+="\ttypes=[str(f.typeName()) for f in fields]\n"
72-
s+="\tself.assertEqual(exceptednames, names)\n"
73-
s+="\tself.assertEqual(exceptedtypes, types)\n"
76+
s+="\tself.assertEqual(expectednames, names)\n"
77+
s+="\tself.assertEqual(expectedtypes, types)\n"
7478
features = QGisLayers.features(layer)
7579
numfeat = len(features)
7680
s+="\tfeatures=sextante.getfeatures(layer))\n"
@@ -80,9 +84,9 @@ def createTest(item):
8084
attrs = feature.attributes()
8185
s+="\tfeature=features.next()\n"
8286
s+="\tattrs=feature.attributes()\n"
83-
s+="\texpectedvalues=[" + ",".join([str(attr.toString()) for attr in attrs]) + "]\n"
87+
s+="\texpectedvalues=[" + ",".join(['"' + str(attr.toString()) + '"' for attr in attrs]) + "]\n"
8488
s+="\tvalues=[str(attr.toString()) for attr in attrs]\n"
85-
s+="\tself.assertEqual(exceptedtypes, types)\n"
89+
s+="\tself.assertEqual(expectedtypes, types)\n"
8690

8791
dlg = ShowTestDialog(s)
8892
dlg.exec_()

0 commit comments

Comments
 (0)