7
7
from diffpy .labpdfproc .labpdfprocapp import get_args
8
8
from diffpy .labpdfproc .tools import (
9
9
expand_list_file ,
10
+ expand_wildcard_file ,
10
11
known_sources ,
11
12
load_user_metadata ,
12
13
set_input_lists ,
54
55
["input_dir/file_list_example2.txt" ],
55
56
["input_dir/good_data.chi" , "good_data.xy" , "input_dir/good_data.txt" ],
56
57
),
57
- ( # wildcard pattern, same directory
58
+ ( # wildcard pattern, matching files with .chi extension in the same directory
58
59
["./*.chi" ],
59
60
["good_data.chi" ],
60
61
),
61
- ( # wildcard pattern, input directory
62
+ ( # wildcard pattern, matching files with .chi extension in the input directory
62
63
["input_dir/*.chi" ],
63
64
["input_dir/good_data.chi" ],
64
65
),
65
- ( # mixture of valid wildcard patterns
66
- ["good_data*" , "./*.pkl" , "unreadable*.txt" , "input_dir/*.chi" ],
66
+ ( # wildcard pattern, matching files starting with good_data
67
+ ["good_data*" ],
68
+ ["good_data.chi" , "good_data.xy" , "good_data.txt" ],
69
+ ),
70
+ ( # wildcard pattern, matching files or directories starting with input
71
+ ["input*" ],
67
72
[
68
- "good_data.chi" ,
69
- "good_data.xy" ,
70
- "good_data.txt" ,
71
- "unreadable_file.txt" ,
72
- "binary.pkl" ,
73
73
"input_dir/good_data.chi" ,
74
+ "input_dir/good_data.xy" ,
75
+ "input_dir/good_data.txt" ,
76
+ "input_dir/unreadable_file.txt" ,
77
+ "input_dir/binary.pkl" ,
74
78
],
75
79
),
80
+ ( # wildcard pattern, matching files or directories starting with unreadable and ending with .txt extension
81
+ ["unreadable*.txt" ],
82
+ ["unreadable_file.txt" ],
83
+ ),
84
+ ( # wildcard pattern, matching directories starting with input and all files under with .chi extension
85
+ ["input*/*.chi" ],
86
+ ["input_dir/good_data.chi" ],
87
+ ),
76
88
]
77
89
78
90
@@ -84,6 +96,7 @@ def test_set_input_lists(inputs, expected, user_filesystem):
84
96
85
97
cli_inputs = ["2.5" ] + inputs
86
98
actual_args = get_args (cli_inputs )
99
+ actual_args = expand_wildcard_file (actual_args )
87
100
actual_args = expand_list_file (actual_args )
88
101
actual_args = set_input_lists (actual_args )
89
102
assert sorted (actual_args .input_paths ) == sorted (expected_paths )
@@ -108,6 +121,16 @@ def test_set_input_lists(inputs, expected, user_filesystem):
108
121
["input_dir/file_list.txt" ],
109
122
"Cannot find missing_file.txt. Please specify valid input file(s) or directories." ,
110
123
),
124
+ ( # valid wildcard pattern, but does not match any files or directories
125
+ ["non_existing_dir*" ],
126
+ "Invalid wildcard input non_existing_dir*. "
127
+ "Please ensure the wildcard pattern matches at least one file or directory." ,
128
+ ),
129
+ ( # invalid wildcard pattern
130
+ ["invalid_dir**" ],
131
+ "Invalid wildcard input invalid_dir**. "
132
+ "Please ensure the wildcard pattern matches at least one file or directory." ,
133
+ ),
111
134
]
112
135
113
136
@@ -117,8 +140,9 @@ def test_set_input_files_bad(inputs, msg, user_filesystem):
117
140
os .chdir (base_dir )
118
141
cli_inputs = ["2.5" ] + inputs
119
142
actual_args = get_args (cli_inputs )
120
- actual_args = expand_list_file (actual_args )
121
143
with pytest .raises (FileNotFoundError , match = msg [0 ]):
144
+ actual_args = expand_wildcard_file (actual_args )
145
+ actual_args = expand_list_file (actual_args )
122
146
actual_args = set_input_lists (actual_args )
123
147
124
148
0 commit comments