Skip to content

Commit 93cf5b4

Browse files
used sorted for tests and edited input function to include file list only if user specifies it
1 parent 99d73aa commit 93cf5b4

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
( # glob input directory
2828
["./input_dir"],
2929
[
30-
"./good_data.chi",
31-
"./good_data.xy",
32-
"./good_data.txt",
3330
"input_dir/good_data.chi",
3431
"input_dir/good_data.xy",
3532
"input_dir/good_data.txt",
@@ -72,7 +69,7 @@ def test_set_input_lists(inputs, expected, user_filesystem):
7269
cli_inputs = ["2.5"] + inputs
7370
actual_args = get_args(cli_inputs)
7471
actual_args = set_input_lists(actual_args)
75-
assert set(actual_args.input_paths) == set(expected_paths)
72+
assert sorted(actual_args.input_paths) == sorted(expected_paths)
7673

7774

7875
# This test covers non-existing single input file or directory, in this case we raise an error with message

src/diffpy/labpdfproc/tools.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ def _parse_file_list_file(input_path):
3535
return input_files
3636

3737

38-
def _parse_input_paths(input_path):
39-
# Takes a path to return either a list of files paths if it is a file list,
40-
# a list of single file path if it is a data file, or nothing
41-
if "file_list" in input_path.name:
42-
return _parse_file_list_file(input_path)
43-
elif input_path.is_file():
44-
return [input_path]
45-
else:
46-
return []
47-
48-
4938
def set_input_lists(args):
5039
"""
5140
Set input directory and files.
@@ -69,11 +58,16 @@ def set_input_lists(args):
6958
input_path = Path(input).resolve()
7059
if input_path.exists():
7160
if input_path.is_file():
72-
input_paths.extend(_parse_input_paths(input_path))
61+
if "file_list" in input_path.name:
62+
input_paths.extend(_parse_file_list_file(input_path))
63+
else:
64+
input_paths.append(input_path)
7365
elif input_path.is_dir():
7466
input_files = input_path.glob("*")
75-
for file in input_files:
76-
input_paths.extend(_parse_input_paths(file))
67+
input_files = [
68+
file.resolve() for file in input_files if file.is_file() and "file_list" not in file.name
69+
]
70+
input_paths.extend(input_files)
7771
else:
7872
raise FileNotFoundError(f"Cannot find {input}. Please specify valid input file(s) or directories.")
7973
else:

0 commit comments

Comments
 (0)