|
19 | 19 | # This test covers existing single input file, directory, a file list, and multiple files
|
20 | 20 | # We store absolute path into input_directory and file names into input_file
|
21 | 21 | params_input = [
|
22 |
| - (["good_data.chi"], [".", "good_data.chi"]), # single good file, same directory |
23 |
| - (["input_dir/good_data.chi"], ["input_dir", "good_data.chi"]), # single good file, input directory |
| 22 | + (["good_data.chi"], ["good_data.chi"]), # single good file, same directory |
| 23 | + (["input_dir/good_data.chi"], ["input_dir/good_data.chi"]), # single good file, input directory |
24 | 24 | ( # glob current directory
|
25 | 25 | ["."],
|
26 |
| - [ |
27 |
| - ".", |
28 |
| - ["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"], |
29 |
| - ], |
| 26 | + ["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"], |
30 | 27 | ),
|
31 | 28 | ( # glob input directory
|
32 | 29 | ["./input_dir"],
|
33 | 30 | [
|
34 |
| - "input_dir", |
35 |
| - ["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"], |
| 31 | + "input_dir/good_data.chi", |
| 32 | + "input_dir/good_data.xy", |
| 33 | + "input_dir/good_data.txt", |
| 34 | + "input_dir/unreadable_file.txt", |
| 35 | + "input_dir/binary.pkl", |
36 | 36 | ],
|
37 | 37 | ),
|
38 | 38 | ( # list of files provided (we skip if encountering invalid files)
|
39 | 39 | ["good_data.chi", "good_data.xy", "unreadable_file.txt", "missing_file.txt"],
|
40 |
| - [ |
41 |
| - ".", |
42 |
| - ["good_data.chi", "good_data.xy", "unreadable_file.txt"], |
43 |
| - ], |
| 40 | + ["good_data.chi", "good_data.xy", "unreadable_file.txt"], |
44 | 41 | ),
|
45 | 42 | ( # list of files provided (with invalid files and files in different directories)
|
46 |
| - ["input_dir/good_data.chi", "good_data.xy", "missing_file.txt"], |
47 |
| - [ |
48 |
| - ".", |
49 |
| - ["input_dir/good_data.chi", "good_data.xy"], |
50 |
| - ], |
| 43 | + ["input_dir/good_data.chi", "good_data.chi", "missing_file.txt"], |
| 44 | + ["input_dir/good_data.chi", "good_data.chi"], |
51 | 45 | ),
|
52 | 46 | ( # file_list.txt list of files provided
|
53 | 47 | ["file_list_dir/file_list.txt"],
|
54 |
| - [".", ["good_data.chi", "good_data.xy", "good_data.txt"]], |
| 48 | + ["good_data.chi", "good_data.xy", "good_data.txt"], |
55 | 49 | ),
|
56 | 50 | ( # file_list_example2.txt list of files provided in different directories
|
57 | 51 | ["file_list_dir/file_list_example2.txt"],
|
58 |
| - [".", ["input_dir/good_data.chi", "good_data.xy", "input_dir/good_data.txt"]], |
| 52 | + ["input_dir/good_data.chi", "good_data.xy", "input_dir/good_data.txt"], |
59 | 53 | ),
|
60 | 54 | ]
|
61 | 55 |
|
62 | 56 |
|
63 | 57 | @pytest.mark.parametrize("inputs, expected", params_input)
|
64 | 58 | def test_set_input_files(inputs, expected, user_filesystem):
|
65 |
| - expected_input_directory = Path(user_filesystem) / expected[0] |
66 |
| - expected_input_files = expected[1] |
| 59 | + expected_input_directory = [] |
| 60 | + for expected_path in expected: |
| 61 | + expected_input_directory.append(Path(user_filesystem) / expected_path) |
67 | 62 |
|
68 | 63 | cli_inputs = ["2.5"] + inputs
|
69 | 64 | actual_args = get_args(cli_inputs)
|
70 | 65 | actual_args = set_input_files(actual_args)
|
71 |
| - assert actual_args.input_directory == expected_input_directory |
72 |
| - assert set(actual_args.input_file) == set(expected_input_files) |
| 66 | + assert set(actual_args.input_directory) == set(expected_input_directory) |
73 | 67 |
|
74 | 68 |
|
75 | 69 | # This test is for existing single input file or directory absolute path not in cwd
|
76 | 70 | # Here we are in user_filesystem/input_dir, testing for a file or directory in user_filesystem
|
77 | 71 | params_input_not_cwd = [
|
78 |
| - (["good_data.chi"], [".", "good_data.chi"]), |
79 |
| - (["."], [".", ["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"]]), |
| 72 | + (["good_data.chi"], ["good_data.chi"]), |
| 73 | + (["."], ["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"]), |
80 | 74 | ]
|
81 | 75 |
|
82 | 76 |
|
83 | 77 | @pytest.mark.parametrize("inputs, expected", params_input_not_cwd)
|
84 | 78 | def test_set_input_files_not_cwd(inputs, expected, user_filesystem):
|
85 |
| - expected_input_directory = Path(user_filesystem) / expected[0] |
86 |
| - expected_input_files = expected[1] |
| 79 | + expected_input_directory = [] |
| 80 | + for expected_path in expected: |
| 81 | + expected_input_directory.append(Path(user_filesystem) / expected_path) |
87 | 82 | actual_input = [str(Path(user_filesystem) / inputs[0])]
|
88 | 83 | os.chdir("input_dir")
|
89 | 84 |
|
90 | 85 | cli_inputs = ["2.5"] + actual_input
|
91 | 86 | actual_args = get_args(cli_inputs)
|
92 | 87 | actual_args = set_input_files(actual_args)
|
93 |
| - assert actual_args.input_directory == expected_input_directory |
94 |
| - assert set(actual_args.input_file) == set(expected_input_files) |
| 88 | + assert set(actual_args.input_directory) == set(expected_input_directory) |
95 | 89 |
|
96 | 90 |
|
97 | 91 | # This test covers non-existing single input file or directory, in this case we raise an error with message
|
98 | 92 | params_input_bad = [
|
99 |
| - (["non_existing_file.xy"], "Please specify valid input file or directory."), |
100 |
| - (["./input_dir/non_existing_file.xy"], "Please specify valid input file or directory."), |
101 |
| - (["./non_existing_dir"], "Please specify valid input file or directory."), |
| 93 | + (["non_existing_file.xy"], "Please specify at least one valid input file or directory."), |
| 94 | + (["./input_dir/non_existing_file.xy"], "Please specify at least one valid input file or directory."), |
| 95 | + (["./non_existing_dir"], "Please specify at least one valid input file or directory."), |
102 | 96 | ]
|
103 | 97 |
|
104 | 98 |
|
|
0 commit comments