7 |
7 |
|
8 |
8 |
from quixote import cleanup
|
9 |
9 |
from quixote.http_request import Upload
|
10 |
|
from qommon.template import Template
|
|
10 |
import qommon.errors
|
|
11 |
from qommon.template import Template, TemplateError
|
11 |
12 |
from qommon.form import PicklableUpload
|
12 |
13 |
from wcs.qommon.http_request import HTTPRequest
|
13 |
14 |
from wcs import fields, formdef
|
... | ... | |
1290 |
1291 |
formdata.data = {'0': time.strptime('2015-05-12', '%Y-%m-%d')}
|
1291 |
1292 |
formdata.store()
|
1292 |
1293 |
assert formdef.data_class().get(formdata.id).digest == 'plop plop'
|
|
1294 |
|
|
1295 |
def test_mathematics_operators(pub, variable_test_data):
|
|
1296 |
formdef = FormDef.select()[0]
|
|
1297 |
formdata = formdef.data_class().select()[0]
|
|
1298 |
for mode in (None, 'lazy'):
|
|
1299 |
pub.substitutions.reset()
|
|
1300 |
pub.substitutions.feed(formdef)
|
|
1301 |
with pub.substitutions.temporary_feed(formdata, force_mode=mode):
|
|
1302 |
# no arg
|
|
1303 |
with pytest.raises(Exception,
|
|
1304 |
match=r'.*Could not find variable at start.*'):
|
|
1305 |
WorkflowStatusItem.compute('{{ |decimal}}', raises=True)
|
|
1306 |
|
|
1307 |
# no param
|
|
1308 |
with pytest.raises(Exception,
|
|
1309 |
match=r'.*add requires 2 arguments, 1 provided'):
|
|
1310 |
WorkflowStatusItem.compute('{{ 0|add }}', raises=True)
|
|
1311 |
with pytest.raises(Exception,
|
|
1312 |
match=r'.*add requires 2 arguments, 1 provided'):
|
|
1313 |
WorkflowStatusItem.compute('{{ 0|add: }}', raises=True)
|
|
1314 |
|
|
1315 |
# string as param
|
|
1316 |
assert WorkflowStatusItem.compute('{{ "1,1"|decimal }}', raises=True) == '1.1'
|
|
1317 |
assert WorkflowStatusItem.compute('{{ "not a number"|decimal }}', raises=True) == ''
|
|
1318 |
|
|
1319 |
# strings as arg
|
|
1320 |
assert WorkflowStatusItem.compute('{{ 0.3|add:"1" }}', raises=True) == '1.3'
|
|
1321 |
assert WorkflowStatusItem.compute('{{ 1.4|add:"not a number" }}', raises=True) == '1.4'
|
|
1322 |
|
|
1323 |
# decimal
|
|
1324 |
assert WorkflowStatusItem.compute('{{ ""|decimal }}', raises=True) == ''
|
|
1325 |
assert WorkflowStatusItem.compute('{{ 0|decimal }}', raises=True) == '0'
|
|
1326 |
assert WorkflowStatusItem.compute('{{ 2.1|decimal }}', raises=True) == '2.1'
|
|
1327 |
assert WorkflowStatusItem.compute('{{ 2.2|decimal:2 }}', raises=True) == '2.20'
|
|
1328 |
|
|
1329 |
# add
|
|
1330 |
assert WorkflowStatusItem.compute('{{ 0|add:"" }}', raises=True) == '0'
|
|
1331 |
assert WorkflowStatusItem.compute('{{ ""|add:0 }}', raises=True) == '0'
|
|
1332 |
assert WorkflowStatusItem.compute('{{ 3.1|add:"" }}', raises=True) == '3.1'
|
|
1333 |
assert WorkflowStatusItem.compute('{{ ""|add:3.2 }}', raises=True) == '3.2'
|
|
1334 |
assert WorkflowStatusItem.compute('{{ 4|add:-0.7 }}', raises=True) == '3.3'
|
|
1335 |
|
|
1336 |
# subtract
|
|
1337 |
assert WorkflowStatusItem.compute('{{ 4.1|subtract:"" }}', raises=True) == '4.1'
|
|
1338 |
assert WorkflowStatusItem.compute('{{ ""|subtract:-4.2 }}', raises=True) == '4.2'
|
|
1339 |
assert WorkflowStatusItem.compute('{{ 5|subtract:0.7 }}', raises=True) == '4.3'
|
|
1340 |
|
|
1341 |
# multiply
|
|
1342 |
assert WorkflowStatusItem.compute('{{ "5,1"|multiply:"" }}', raises=True) == ''
|
|
1343 |
assert WorkflowStatusItem.compute('{{ ""|multiply:"5.2"}}', raises=True) == ''
|
|
1344 |
assert WorkflowStatusItem.compute('{{ "2.5"|multiply:2 }}', raises=True) == '5.0'
|
|
1345 |
assert WorkflowStatusItem.compute('{{ "3"|multiply:2 }}', raises=True) == '6'
|
|
1346 |
|
|
1347 |
# divide
|
|
1348 |
assert WorkflowStatusItem.compute('{{ 6.1|divide:"" }}', raises=True) == ''
|
|
1349 |
assert WorkflowStatusItem.compute('{{ ""|divide:6.2}}', raises=True) == ''
|
|
1350 |
assert WorkflowStatusItem.compute('{{ 2|divide:3|decimal:2 }}', raises=True) == '0.67'
|