Skip to content

Commit 46c5021

Browse files
authored
Fix temp directory creation on container (#1053)
* fix temp directory creation on container * add unit test
1 parent 3a1dfbd commit 46c5021

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

openml/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _setup(config=None):
204204
# read config file, create directory for config file
205205
if not os.path.exists(config_dir):
206206
try:
207-
os.mkdir(config_dir)
207+
os.makedirs(config_dir, exist_ok=True)
208208
cache_exists = True
209209
except PermissionError:
210210
cache_exists = False
@@ -235,7 +235,7 @@ def _get(config, key):
235235
# create the cache subdirectory
236236
if not os.path.exists(cache_directory):
237237
try:
238-
os.mkdir(cache_directory)
238+
os.makedirs(cache_directory, exist_ok=True)
239239
except PermissionError:
240240
openml_logger.warning(
241241
"No permission to create openml cache directory at %s! This can result in "

tests/test_openml/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def test_non_writable_home(self, log_handler_mock, warnings_mock, expanduser_moc
2626
self.assertEqual(log_handler_mock.call_count, 1)
2727
self.assertFalse(log_handler_mock.call_args_list[0][1]["create_file_handler"])
2828

29+
@unittest.mock.patch("os.path.expanduser")
30+
def test_XDG_directories_do_not_exist(self, expanduser_mock):
31+
with tempfile.TemporaryDirectory(dir=self.workdir) as td:
32+
33+
def side_effect(path_):
34+
return os.path.join(td, str(path_).replace("~/", ""))
35+
36+
expanduser_mock.side_effect = side_effect
37+
openml.config._setup()
38+
2939
def test_get_config_as_dict(self):
3040
""" Checks if the current configuration is returned accurately as a dict. """
3141
config = openml.config.get_config_as_dict()

0 commit comments

Comments
 (0)