File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 15
15
def test_set_output_directory (inputs , expected ):
16
16
expected_output_directory = expected [0 ]
17
17
actual_args = argparse .Namespace (output_directory = inputs [0 ])
18
- actual_output_directory = set_output_directory (actual_args )
19
- assert actual_output_directory == expected_output_directory
18
+ actual_args .output_directory = set_output_directory (actual_args )
19
+ assert actual_args .output_directory == expected_output_directory
20
+ assert Path (actual_args .output_directory ).exists ()
21
+ assert Path (actual_args .output_directory ).is_dir ()
22
+
23
+ with pytest .raises (FileExistsError ):
24
+ actual_args = argparse .Namespace (output_directory = "test_tools.py" )
25
+ actual_args .output_directory = set_output_directory (actual_args )
Original file line number Diff line number Diff line change 2
2
3
3
4
4
def set_output_directory (args ):
5
+ """
6
+ set the output directory based on the given input arguments
7
+
8
+ Parameters
9
+ ----------
10
+ args argparse.Namespace
11
+ input arguments provided by the user
12
+
13
+ Returns
14
+ -------
15
+ pathlib.PosixPath that contains the full path of the output directory
16
+
17
+ it is determined as follows:
18
+ If user provides an output directory, use it.
19
+ Otherwise, we set it to the current directory if nothing is provided.
20
+ We then create the directory if it does not exist.
21
+ If the provided directory is an existed file then we raise the FileExistsError.
22
+
23
+ """
5
24
output_dir = Path (args .output_directory ).resolve () if args .output_directory else Path .cwd ()
6
25
output_dir .mkdir (parents = True , exist_ok = True )
7
26
return output_dir
You can’t perform that action at this time.
0 commit comments