16
16
* *
17
17
***************************************************************************
18
18
"""
19
-
20
19
__author__ = 'Victor Olaya'
21
20
__date__ = 'February 2013'
22
21
__copyright__ = '(C) 2013, Victor Olaya'
23
22
# This will get replaced with a git SHA1 when you do a git archive
24
23
__revision__ = '$Format:%H$'
25
24
25
+ import os
26
26
from sextante .core .Sextante import Sextante
27
27
from sextante .outputs .OutputNumber import OutputNumber
28
28
from sextante .outputs .OutputString import OutputString
@@ -42,16 +42,20 @@ def createTest(item):
42
42
execcommand = "sextante.runalg("
43
43
i = 0
44
44
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 ] + '"'
46
48
execcommand += token + ","
47
49
else :
48
50
execcommand += "None,"
49
51
i += 1
50
52
s += "\t outputs=" + execcommand [:- 1 ] + ")\n "
51
53
52
54
i = - 1 * len (alg .outputs )
53
- for out in alg .outputs :
55
+ for out in alg .outputs :
54
56
filename = tokens [i ][1 :- 1 ]
57
+ if (filename == str (None )):
58
+ raise Exception ("Cannot create unit test for that algorithm.\n The output cannot be a temporary file" )
55
59
s += "\t output=outputs['" + out .name + "']\n "
56
60
if isinstance (out , (OutputNumber , OutputString )):
57
61
s += "self.assertTrue(" + str (out ) + ", output)\n "
@@ -69,8 +73,8 @@ def createTest(item):
69
73
s += "\t expectedtypes=[" + "," .join ([str (f .typeName ()) for f in fields ]) + "]\n "
70
74
s += "\t names=[str(f.name()) for f in fields]\n "
71
75
s += "\t types=[str(f.typeName()) for f in fields]\n "
72
- s += "\t self.assertEqual(exceptednames , names)\n "
73
- s += "\t self.assertEqual(exceptedtypes , types)\n "
76
+ s += "\t self.assertEqual(expectednames , names)\n "
77
+ s += "\t self.assertEqual(expectedtypes , types)\n "
74
78
features = QGisLayers .features (layer )
75
79
numfeat = len (features )
76
80
s += "\t features=sextante.getfeatures(layer))\n "
@@ -80,9 +84,9 @@ def createTest(item):
80
84
attrs = feature .attributes ()
81
85
s += "\t feature=features.next()\n "
82
86
s += "\t attrs=feature.attributes()\n "
83
- s += "\t expectedvalues=[" + "," .join ([str (attr .toString ()) for attr in attrs ]) + "]\n "
87
+ s += "\t expectedvalues=[" + "," .join (['"' + str (attr .toString ()) + '"' for attr in attrs ]) + "]\n "
84
88
s += "\t values=[str(attr.toString()) for attr in attrs]\n "
85
- s += "\t self.assertEqual(exceptedtypes , types)\n "
89
+ s += "\t self.assertEqual(expectedtypes , types)\n "
86
90
87
91
dlg = ShowTestDialog (s )
88
92
dlg .exec_ ()
0 commit comments