Skip to content

Commit

Permalink
Fixing bug in Fido to allow download to path="./" (#4058)
Browse files Browse the repository at this point in the history
* fixing cwd save and adding test

* removing my print statements

* fixing test to move into tmpdir

* adding changelog

* Fix PEP8 newline

Co-authored-by: David Stansby <[email protected]>
  • Loading branch information
hayesla and dstansby authored Apr 29, 2020
1 parent bd77cc7 commit dacb05b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/4058.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a bug in fido_factory to allow path="./" in fido.fetch().
3 changes: 2 additions & 1 deletion sunpy/net/fido_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ def fetch(self, *query_results, path=None, max_conn=5, progress=True,
"""
if path is not None:
exists = list(filter(lambda p: p.exists(), Path(path).parents))
exists = list(filter(lambda p: p.exists(), Path(path).resolve().parents))

if not os.access(exists[0], os.W_OK):
raise PermissionError('You do not have permission to write'
f' to the directory {exists[0]}.')
Expand Down
10 changes: 10 additions & 0 deletions sunpy/net/tests/test_fido.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def test_save_path_pathlib(tmpdir):
assert f"eve{os.path.sep}0" in f


@pytest.mark.remote_data
def test_save_path_cwd(tmpdir):
qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))

# Test when path is ./ for current working directory
os.chdir(tmpdir) # move into temp directory
files = Fido.fetch(qr, path="./")
for f in files:
assert pathlib.Path.cwd().joinpath(f).exists()

"""
Factory Tests
"""
Expand Down

0 comments on commit dacb05b

Please sign in to comment.