15
15
from wpsremote import computational_job_input_action_cmd_param
16
16
from wpsremote import computational_job_input_action_create_json_file
17
17
from wpsremote import computational_job_input_action_update_json_file
18
+ from wpsremote import computational_job_input_action_copyfile
18
19
from wpsremote import mockutils
19
20
20
21
__author__ = "Alessio Fabiani"
@@ -60,15 +61,46 @@ def test_two_params(self):
60
61
self .assertEquals (p1 .get_value_string (), "1" )
61
62
self .assertEquals (p2 .get_value_string (), "abc" )
62
63
64
+ def test_set_float_param (self ):
65
+ p1 = computation_job_param .ComputationJobParam ("mypar" , "float" , "par title" , "par descr" )
66
+ p1 .set_value ("1.37" )
67
+ self .assertEquals (p1 .get_value_string (), "1.37" )
68
+
69
+ def test_set_wrong_float_param (self ):
70
+ p1 = computation_job_param .ComputationJobParam ("mypar" , "float" , "par title" , "par descr" )
71
+ self .assertRaises (TypeError , lambda : p1 .set_value ("not float" ))
72
+
73
+ def test_set_url_param (self ):
74
+ p1 = computation_job_param .ComputationJobParam ("mypar" , "url" , "par title" , "par descr" )
75
+ p1 .set_value ("https://www.google.com/" )
76
+ self .assertEquals (p1 .get_value_string (), "https://www.google.com/" )
77
+
78
+ def test_set_wrong_url_param (self ):
79
+ p1 = computation_job_param .ComputationJobParam ("mypar" , "url" , "par title" , "par descr" )
80
+ self .assertRaises (Exception , lambda : p1 .set_value ("https://www.google.com/%" ))
81
+
82
+ def test_set_datetime_param (self ):
83
+ p1 = computation_job_param .ComputationJobParam (
84
+ "mypar" , "datetime" , "par title" , "par descr" ,
85
+ formatter = "%Y-%m-%d"
86
+ )
87
+ p1 .set_value ("2019-10-21" )
88
+ self .assertEquals (p1 .get_value_string (), "2019-10-21" )
89
+
90
+ def test_set_wrong_datetime_param (self ):
91
+ p1 = computation_job_param .ComputationJobParam (
92
+ "mypar" , "datetime" , "par title" , "par descr"
93
+ )
94
+ self .assertIsNone (p1 .get_value_string ())
95
+
63
96
def test_cmd_line_action (self ):
64
97
inputs = computation_job_inputs .ComputationJobInputs ()
65
98
inputs .add_input (computation_job_param .ComputationJobParam ("mypar1" , "int" , "par 1" , "par descr 1" ))
66
99
67
100
actions = computational_job_input_actions .ComputationalJobInputActions ()
68
101
actions .add_actions (
69
- computational_job_input_action_cmd_param .ComputationalJobInputActionCmdParam (
70
- "mypar1" , "--name=value" ))
71
-
102
+ computational_job_input_action_cmd_param .ComputationalJobInputActionCmdParam (
103
+ "mypar1" , "--name=value" ))
72
104
inputs .set_values ({"mypar1" : "1" })
73
105
actions .execute (inputs )
74
106
@@ -194,6 +226,22 @@ class = param
194
226
195
227
self .assertEquals (actions .get_cmd_line (), "--mypar1=1" )
196
228
229
+ def test_read_param_from_dict (self ):
230
+ input_dict = {
231
+ "mypar1" : {
232
+ "class" : "param" ,
233
+ "type" : "int" ,
234
+ "description" : "mypar descr"
235
+ }
236
+ }
237
+ inputs = computation_job_inputs .ComputationJobInputs .create_from_dict (input_dict )
238
+ actions = computational_job_input_action_cmd_param .ComputationalJobInputActionCmdParam (
239
+ "mypar1" , "--name=value"
240
+ )
241
+ inputs .set_values ({"mypar1" : "1" })
242
+ actions .set_inputs (inputs )
243
+ self .assertEquals (actions .get_cmd_line (), "--mypar1=1" )
244
+
197
245
def test_read_action_from_ini (self ):
198
246
ini_text = '''[Action1]
199
247
input_ref = mypar1
@@ -218,6 +266,24 @@ class = cmdline
218
266
219
267
self .assertEquals (actions .get_cmd_line (), "--mypar1=1" )
220
268
269
+ def test_read_action_from_dict (self ):
270
+ input_dict = {
271
+ "Action1" : {
272
+ "input_ref" : "mypar1" ,
273
+ "class" : "cmdline" ,
274
+ "template" : "--name=value"
275
+ }
276
+ }
277
+ inputs = computation_job_inputs .ComputationJobInputs ()
278
+ inputs .add_input (
279
+ computation_job_param .ComputationJobParam ("mypar1" , "int" , "par 1" , "par descr" )
280
+ )
281
+ actions = computational_job_input_actions . \
282
+ ComputationalJobInputActions .create_from_dict (input_dict )
283
+ inputs .set_values ({"mypar1" : "1" })
284
+ actions .execute (inputs )
285
+ self .assertEquals (actions .get_cmd_line (), "--mypar1=1" )
286
+
221
287
def test_2_cmdpar_from_ini (self ):
222
288
223
289
ini_text = '''[Input1]
@@ -258,6 +324,39 @@ class = cmdline
258
324
259
325
self .assertEquals (actions .get_cmd_line (), '-w . oaaOnDemand' )
260
326
327
+ def test_2_cmdpar_from_dict (self ):
328
+ inputs_dict = {
329
+ "workingdir" : {
330
+ "class" : "param" ,
331
+ "type" : "string" ,
332
+ "description" : "OAA process working directory"
333
+ },
334
+ "etlExecutionType" : {
335
+ "class" : "const" ,
336
+ "type" : "string" ,
337
+ "description" : "parameter to choose what type of execution is performed by etl.py script" ,
338
+ "value" : "oaaOnDemand"
339
+ }
340
+ }
341
+ actions_dict = {
342
+ "Action1" : {
343
+ "input_ref" : "workingdir" ,
344
+ "class" : "cmdline" ,
345
+ "alias" : "w" ,
346
+ "template" : "-name value"
347
+ },
348
+ "Action2" : {
349
+ "input_ref" : "etlExecutionType" ,
350
+ "class" : "cmdline" ,
351
+ "template" : "value" ,
352
+ }
353
+ }
354
+ inputs = computation_job_inputs .ComputationJobInputs .create_from_dict (inputs_dict )
355
+ actions = computational_job_input_actions .ComputationalJobInputActions .create_from_dict (actions_dict )
356
+ inputs .set_values ({'workingdir' : '.' })
357
+ actions .execute (inputs )
358
+ self .assertEquals (actions .get_cmd_line (), '-w . oaaOnDemand' )
359
+
261
360
def test_cmdpar_order (self ):
262
361
263
362
ini_text = '''[Input2]
@@ -280,8 +379,7 @@ class = param
280
379
class = cmdline
281
380
input_ref = workingdir
282
381
alias = w
283
- template = -name value
284
- '''
382
+ template = -name value'''
285
383
286
384
config = ConfigParser .ConfigParser ()
287
385
import StringIO
@@ -300,6 +398,39 @@ class = cmdline
300
398
301
399
self .assertEquals (actions .get_cmd_line (), '-w . --k=2.4' )
302
400
401
+ def test_cmdpar_order_from_dict (self ):
402
+ inputs_dict = {
403
+ "coeff" : {
404
+ "class" : "param" ,
405
+ "type" : "float" ,
406
+ "description" : "this is a coeff"
407
+ },
408
+ "workingdir" : {
409
+ "class" : "param" ,
410
+ "type" : "string" ,
411
+ "description" : "process working directory"
412
+ }
413
+ }
414
+ actions_dict = {
415
+ "Action1" : {
416
+ "input_ref" : "workingdir" ,
417
+ "class" : "cmdline" ,
418
+ "alias" : "w" ,
419
+ "template" : "-name value"
420
+ },
421
+ "Action2" : {
422
+ "input_ref" : "coeff" ,
423
+ "class" : "cmdline" ,
424
+ "alias" : "k" ,
425
+ "template" : "--name=value" ,
426
+ }
427
+ }
428
+ inputs = computation_job_inputs .ComputationJobInputs .create_from_dict (inputs_dict )
429
+ actions = computational_job_input_actions .ComputationalJobInputActions .create_from_dict (actions_dict )
430
+ inputs .set_values ({'workingdir' : '.' , 'coeff' : 2.4 })
431
+ actions .execute (inputs )
432
+ self .assertEquals (actions .get_cmd_line (), '-w . --k=2.4' )
433
+
303
434
def test_update_json_list_in_file (self ):
304
435
target_json_file = path .path ("./json_out.json" )
305
436
if target_json_file .exists ():
@@ -346,6 +477,21 @@ def test_update_json_list_in_file_two_times(self):
346
477
self .assertTrue (75.5 , j ['Config' ]['latLim' ][0 ])
347
478
self .assertTrue (76.5 , j ['Config' ]['latLim' ][1 ])
348
479
480
+ def test_copyfile (self ):
481
+ target_json_file = path .path ("./copy_of_source_json.json" )
482
+ if target_json_file .exists ():
483
+ target_json_file .remove ()
484
+ source_template_json_file = path .path (r"./src/wpsremote/xmpp_data/test/CMREOAA_MainConfigFile_template.json" )
485
+ action = computational_job_input_action_copyfile .ComputationalJobInputActionCopyFile (
486
+ source = source_template_json_file , target = target_json_file
487
+ )
488
+ action .set_inputs ("test" )
489
+ self .assertTrue (target_json_file .exists ())
490
+ target_json_text = target_json_file .text ()
491
+ source_json_text = source_template_json_file .text ()
492
+ self .assertEqual (target_json_text , source_json_text )
493
+ target_json_file .remove ()
494
+
349
495
json_text1 = '''{
350
496
"Asset": {
351
497
"Pfa": 0.001,
0 commit comments