|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -from __future__ import print_function, unicode_literals |
3 | 2 | # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
4 | 3 | # vi: set ft=python sts=4 ts=4 sw=4 et: |
| 4 | +from __future__ import print_function, unicode_literals |
5 | 5 | import os |
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | from nipype.interfaces import utility |
9 | 9 | import nipype.pipeline.engine as pe |
10 | 10 |
|
11 | 11 |
|
12 | | -def test_rename(tmpdir): |
13 | | - os.chdir(str(tmpdir)) |
14 | | - |
15 | | - # Test very simple rename |
16 | | - _ = open("file.txt", "w").close() |
17 | | - rn = utility.Rename(in_file="file.txt", format_string="test_file1.txt") |
18 | | - res = rn.run() |
19 | | - outfile = str(tmpdir.join("test_file1.txt")) |
20 | | - assert res.outputs.out_file == outfile |
21 | | - assert os.path.exists(outfile) |
22 | | - |
23 | | - # Now a string-formatting version |
24 | | - rn = utility.Rename(in_file="file.txt", format_string="%(field1)s_file%(field2)d", keep_ext=True) |
25 | | - # Test .input field creation |
26 | | - assert hasattr(rn.inputs, "field1") |
27 | | - assert hasattr(rn.inputs, "field2") |
28 | | - |
29 | | - # Set the inputs |
30 | | - rn.inputs.field1 = "test" |
31 | | - rn.inputs.field2 = 2 |
32 | | - res = rn.run() |
33 | | - outfile = str(tmpdir.join("test_file2.txt")) |
34 | | - assert res.outputs.out_file == outfile |
35 | | - assert os.path.exists(outfile) |
36 | | - |
37 | | - |
38 | 12 | def test_function(tmpdir): |
39 | 13 | os.chdir(str(tmpdir)) |
40 | 14 |
|
@@ -89,48 +63,6 @@ def test_function_with_imports(tmpdir): |
89 | 63 | node.run() |
90 | 64 |
|
91 | 65 |
|
92 | | -@pytest.mark.parametrize("args, expected", [ |
93 | | - ({} , ([0], [1,2,3])), |
94 | | - ({"squeeze" : True}, (0 , [1,2,3])) |
95 | | - ]) |
96 | | -def test_split(tmpdir, args, expected): |
97 | | - os.chdir(str(tmpdir)) |
98 | | - |
99 | | - node = pe.Node(utility.Split(inlist=list(range(4)), |
100 | | - splits=[1, 3], |
101 | | - **args), |
102 | | - name='split_squeeze') |
103 | | - res = node.run() |
104 | | - assert res.outputs.out1 == expected[0] |
105 | | - assert res.outputs.out2 == expected[1] |
106 | | - |
107 | | - |
108 | | -def test_csvReader(tmpdir): |
109 | | - header = "files,labels,erosion\n" |
110 | | - lines = ["foo,hello,300.1\n", |
111 | | - "bar,world,5\n", |
112 | | - "baz,goodbye,0.3\n"] |
113 | | - for x in range(2): |
114 | | - name = str(tmpdir.join("testfile.csv")) |
115 | | - with open(name, 'w') as fid: |
116 | | - reader = utility.CSVReader() |
117 | | - if x % 2 == 0: |
118 | | - fid.write(header) |
119 | | - reader.inputs.header = True |
120 | | - fid.writelines(lines) |
121 | | - fid.flush() |
122 | | - reader.inputs.in_file = name |
123 | | - out = reader.run() |
124 | | - if x % 2 == 0: |
125 | | - assert out.outputs.files == ['foo', 'bar', 'baz'] |
126 | | - assert out.outputs.labels == ['hello', 'world', 'goodbye'] |
127 | | - assert out.outputs.erosion == ['300.1', '5', '0.3'] |
128 | | - else: |
129 | | - assert out.outputs.column_0 == ['foo', 'bar', 'baz'] |
130 | | - assert out.outputs.column_1 == ['hello', 'world', 'goodbye'] |
131 | | - assert out.outputs.column_2 == ['300.1', '5', '0.3'] |
132 | | - |
133 | | - |
134 | 66 | def test_aux_connect_function(tmpdir): |
135 | 67 | """ This tests excution nodes with multiple inputs and auxiliary |
136 | 68 | function inside the Workflow connect function. |
|
0 commit comments