55import os
66import sys
77import argparse
8+ from pathlib import Path
89import importlib .util
910from importlib .machinery import SourceFileLoader
1011
@@ -49,12 +50,12 @@ def test_list_arguments_accepted(self, list_flag):
4950 assert args .file is None
5051
5152 @pytest .mark .parametrize ("inputdata_flag" , ["-inputdata" , "-i" , "--inputdata" , "--inputdata-root" , "-inputdata-root" ])
52- def test_inputdata_arguments_accepted (self , inputdata_flag ):
53+ def test_inputdata_arguments_accepted (self , temp_dirs , inputdata_flag ):
5354 """Test that all inputdata argument flags are accepted."""
55+ inputdata_root , _ = temp_dirs
5456 parser = rimport .build_parser ()
55- inputdata_dir = "/some/dir"
56- args = parser .parse_args ([inputdata_flag , inputdata_dir , "-f" , "dummy_file.nc" ])
57- assert args .inputdata_root == inputdata_dir
57+ args = parser .parse_args ([inputdata_flag , inputdata_root , "-f" , "dummy_file.nc" ])
58+ assert args .inputdata_root == inputdata_root
5859
5960 def test_file_and_list_mutually_exclusive (self , capsys ):
6061 """Test that -file and -list cannot be used together."""
@@ -82,7 +83,7 @@ def test_inputdata_default(self):
8283 """Test that -inputdata has correct default value."""
8384 parser = rimport .build_parser ()
8485 args = parser .parse_args (["-file" , "test.txt" ])
85- assert args .inputdata_root == rimport .DEFAULT_INPUTDATA_ROOT
86+ assert args .inputdata_root == str ( rimport .DEFAULT_INPUTDATA_ROOT )
8687
8788 def test_check_default (self ):
8889 """Test that --check has the correct default value."""
@@ -97,10 +98,12 @@ def test_check_arguments_accepted(self, check_flag):
9798 args = parser .parse_args (["-file" , "test.txt" , check_flag ])
9899 assert args .check is True
99100
100- def test_inputdata_custom (self ):
101+ def test_inputdata_custom (self , temp_dirs ):
101102 """Test that -inputdata can be customized."""
102103 parser = rimport .build_parser ()
103- custom_path = "/custom/path"
104+ inputdata_root , _ = temp_dirs
105+ custom_path = os .path .join (inputdata_root , "custom" , "path" )
106+ os .makedirs (custom_path )
104107 args = parser .parse_args (["-file" , "test.txt" , "-inputdata" , custom_path ])
105108 assert args .inputdata_root == custom_path
106109
@@ -113,19 +116,25 @@ def test_help_flags_show_help(self, help_flag):
113116 # Help should exit with code 0
114117 assert exc_info .value .code == 0
115118
116- def test_file_with_inputdata (self ):
119+ def test_file_with_inputdata (self , temp_dirs ):
117120 """Test combining -file with -inputdata."""
118121 parser = rimport .build_parser ()
119- args = parser .parse_args (["-file" , "data.nc" , "-inputdata" , "/my/data" ])
122+ inputdata_root , _ = temp_dirs
123+ custom_path = os .path .join (inputdata_root , "custom" , "path2" )
124+ os .makedirs (custom_path )
125+ args = parser .parse_args (["-file" , "data.nc" , "-inputdata" , custom_path ])
120126 assert args .file == "data.nc"
121- assert args .inputdata_root == "/my/data"
127+ assert args .inputdata_root == custom_path
122128
123- def test_list_with_inputdata (self ):
129+ def test_list_with_inputdata (self , temp_dirs ):
124130 """Test combining -list with -inputdata."""
125131 parser = rimport .build_parser ()
126- args = parser .parse_args (["-list" , "files.txt" , "-inputdata" , "/my/data" ])
132+ inputdata_root , _ = temp_dirs
133+ custom_path = os .path .join (inputdata_root , "custom" , "path3" )
134+ os .makedirs (custom_path )
135+ args = parser .parse_args (["-list" , "files.txt" , "-inputdata" , custom_path ])
127136 assert args .filelist == "files.txt"
128- assert args .inputdata_root == "/my/data"
137+ assert args .inputdata_root == custom_path
129138
130139 def test_quiet_default (self ):
131140 """Test that quiet defaults to False."""
0 commit comments