|
3 | 3 | import numpy as np |
4 | 4 | import pytest |
5 | 5 |
|
6 | | -from .utils import fun_addtwo, fun_addvar, moment, fun_div |
| 6 | +from .utils import ( |
| 7 | + fun_addtwo, |
| 8 | + fun_addvar, |
| 9 | + moment, |
| 10 | + fun_div, |
| 11 | + fun_dict, |
| 12 | + fun_file, |
| 13 | + fun_file_list, |
| 14 | +) |
7 | 15 |
|
8 | 16 | from ..core import TaskBase |
9 | 17 | from ..submitter import Submitter |
@@ -283,6 +291,32 @@ def test_task_init_6(): |
283 | 291 | assert nn.state.states_val == [] |
284 | 292 |
|
285 | 293 |
|
| 294 | +@pytest.mark.parametrize("plugin", Plugins) |
| 295 | +def test_task_init_7(plugin, tmpdir): |
| 296 | + """ task with a dictionary of files as an input, checking checksum""" |
| 297 | + file1 = tmpdir.join("file1.txt") |
| 298 | + with open(file1, "w") as f: |
| 299 | + f.write("hello") |
| 300 | + |
| 301 | + file2 = tmpdir.join("file2.txt") |
| 302 | + with open(file2, "w") as f: |
| 303 | + f.write("from pydra\n") |
| 304 | + |
| 305 | + nn1 = fun_file_list(name="NA", filename_list=[file1, file2]) |
| 306 | + output_dir1 = nn1.output_dir |
| 307 | + |
| 308 | + # changing the content of the file |
| 309 | + file2 = tmpdir.join("file2.txt") |
| 310 | + with open(file2, "w") as f: |
| 311 | + f.write("from pydra") |
| 312 | + |
| 313 | + nn2 = fun_file_list(name="NA", filename_list=[file1, file2]) |
| 314 | + output_dir2 = nn2.output_dir |
| 315 | + |
| 316 | + # the checksum should be different - content of file2 is different |
| 317 | + assert output_dir1.name != output_dir2.name |
| 318 | + |
| 319 | + |
286 | 320 | def test_task_error(): |
287 | 321 | func = fun_div(name="div", a=1, b=0) |
288 | 322 | with pytest.raises(ZeroDivisionError): |
@@ -382,6 +416,64 @@ def test_task_nostate_2(plugin): |
382 | 416 | assert nn.output_dir.exists() |
383 | 417 |
|
384 | 418 |
|
| 419 | +@pytest.mark.parametrize("plugin", Plugins) |
| 420 | +def test_task_nostate_3(plugin): |
| 421 | + """ task with a dictionary as an input""" |
| 422 | + nn = fun_dict(name="NA", d={"a": "ala", "b": "bala"}) |
| 423 | + assert nn.inputs.d == {"a": "ala", "b": "bala"} |
| 424 | + |
| 425 | + with Submitter(plugin=plugin) as sub: |
| 426 | + sub(nn) |
| 427 | + |
| 428 | + # checking the results |
| 429 | + results = nn.result() |
| 430 | + assert results.output.out == "a:ala_b:bala" |
| 431 | + # checking the output_dir |
| 432 | + assert nn.output_dir.exists() |
| 433 | + |
| 434 | + |
| 435 | +@pytest.mark.parametrize("plugin", Plugins) |
| 436 | +def test_task_nostate_4(plugin, tmpdir): |
| 437 | + """ task with a dictionary as an input""" |
| 438 | + file1 = tmpdir.join("file.txt") |
| 439 | + with open(file1, "w") as f: |
| 440 | + f.write("hello from pydra\n") |
| 441 | + |
| 442 | + nn = fun_file(name="NA", filename=file1) |
| 443 | + |
| 444 | + with Submitter(plugin=plugin) as sub: |
| 445 | + sub(nn) |
| 446 | + |
| 447 | + # checking the results |
| 448 | + results = nn.result() |
| 449 | + assert results.output.out == "hello from pydra\n" |
| 450 | + # checking the output_dir |
| 451 | + assert nn.output_dir.exists() |
| 452 | + |
| 453 | + |
| 454 | +@pytest.mark.parametrize("plugin", Plugins) |
| 455 | +def test_task_nostate_5(plugin, tmpdir): |
| 456 | + """ task with a dictionary of files as an input""" |
| 457 | + file1 = tmpdir.join("file1.txt") |
| 458 | + with open(file1, "w") as f: |
| 459 | + f.write("hello") |
| 460 | + |
| 461 | + file2 = tmpdir.join("file2.txt") |
| 462 | + with open(file2, "w") as f: |
| 463 | + f.write("from pydra\n") |
| 464 | + |
| 465 | + nn = fun_file_list(name="NA", filename_list=[file1, file2]) |
| 466 | + |
| 467 | + with Submitter(plugin=plugin) as sub: |
| 468 | + sub(nn) |
| 469 | + |
| 470 | + # checking the results |
| 471 | + results = nn.result() |
| 472 | + assert results.output.out == "hello from pydra\n" |
| 473 | + # checking the output_dir |
| 474 | + assert nn.output_dir.exists() |
| 475 | + |
| 476 | + |
385 | 477 | # Testing caching for tasks without states |
386 | 478 |
|
387 | 479 |
|
|
0 commit comments