Skip to content

Commit 98880c2

Browse files
committed
Initial tests
1 parent c1eb622 commit 98880c2

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

package/MDAnalysis/web/downloaders.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ def download(self, cache_path=None, timeout=None):
9494
r.raise_for_status()
9595
self._file.write(r.text)
9696
except requests.HTTPError:
97-
print(self._file)
98-
print(self._file.name)
99-
# Clean Up files in case of download failure
100-
#Path(str(self._file)).unlink()
97+
# This also deletes the undownloaded file
10198
raise FileDownloadPDBError
10299
finally:
103100
# Closes File safely if saving to cache
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import MDAnalysis as mda
2+
import pytest
3+
import requests
4+
5+
6+
7+
working_PDB_ID = '1DPX' # egg white lysozyme
8+
file_format="pdb"
9+
10+
11+
12+
def test_fetch_pdb_base_functionality():
13+
"""Check default parameter of mda.fetch_pdb"""
14+
assert isinstance(mda.fetch_pdb(PDB_ID=working_PDB_ID), mda.Universe)
15+
16+
17+
def test_fetch_pdb_timeout():
18+
"""Checks requests timeout Exception for fetch_pdb and PdbDownloader"""
19+
with pytest.raises(requests.exceptions.ConnectTimeout):
20+
mda.fetch_pdb(PDB_ID=working_PDB_ID, timeout=0.000001)
21+
22+
def test_fetch_pdb_keywords():
23+
"""Check if keywords could be passed to Universe consturctors"""
24+
assert isinstance(mda.fetch_pdb(working_PDB_ID, download_path=None, timeout=None, in_memory=True),
25+
mda.Universe)
26+
27+
28+
def test_file_namecache(tmp_path):
29+
"""Test that cache is saved as ID.file_format"""
30+
test_directory = tmp_path
31+
32+
downloader = mda.web.PdbDownloader(PDB_ID=working_PDB_ID,
33+
file_format=file_format)
34+
35+
downloader.download(cache_path=test_directory)
36+
37+
assert test_directory / f"{working_PDB_ID}.{file_format}"
38+
39+
40+
def test_invalid_id():
41+
"""Test invalid id for PdbDownloader and fetch_pdb"""
42+
43+
with pytest.raises(mda.web.downloaders.FileDownloadPDBError):
44+
mda.web.PdbDownloader(PDB_ID='BananaBoat').download()
45+
46+
47+
48+
49+
50+
51+
52+

0 commit comments

Comments
 (0)