Skip to content

Commit fccaf14

Browse files
committed
Adding cleanup_saved_downloads function to help the testcleanup directive
1 parent d40d316 commit fccaf14

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

astroquery/utils/cleanup_downloads.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
"""
3+
Utility to cleanup files created during doctesting.
4+
"""
5+
import glob
6+
import os
7+
import shutil
8+
9+
10+
def cleanup_saved_downloads(names):
11+
""" Function to clean up save files.
12+
13+
Parameters
14+
----------
15+
names : str or list of str
16+
Files or directories to clean up. Wildcards are excepted.
17+
"""
18+
19+
if isinstance(names, str):
20+
names = [names]
21+
22+
for path in names:
23+
files = glob.glob(path)
24+
for saved_download in files:
25+
try:
26+
shutil.rmtree(saved_download)
27+
except NotADirectoryError:
28+
os.remove(saved_download)

0 commit comments

Comments
 (0)