mirror of
https://github.com/biopython/biopython.git
synced 2025-10-20 21:53:47 +08:00
improve coverage of tests
This commit is contained in:
@ -290,7 +290,9 @@ class PDBList:
|
||||
file_type = (
|
||||
"pdb"
|
||||
if file_format == "pdb"
|
||||
else "mmCIF" if file_format == "mmCif" else "XML"
|
||||
else "mmCIF"
|
||||
if file_format == "mmCif"
|
||||
else "XML"
|
||||
)
|
||||
url = (
|
||||
self.pdb_server
|
||||
@ -338,7 +340,7 @@ class PDBList:
|
||||
urlretrieve(url, filename)
|
||||
except OSError as e:
|
||||
print(
|
||||
f"Desired structure not found or doesn't exist:"
|
||||
f"Desired structure not found or download failed."
|
||||
f" '{pdb_code}': {str(e)}"
|
||||
)
|
||||
return None
|
||||
|
@ -160,18 +160,34 @@ class TestPDBListGetStructure(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_retrieve_pdb_file_not_existing(self):
|
||||
"""Tests retrieving a non-existent molecule returns None."""
|
||||
"""Tests retrieving a non-existent molecule - returns None and prints error message."""
|
||||
with self.make_temp_directory(os.getcwd()) as tmp:
|
||||
pdblist = PDBList(pdb=tmp)
|
||||
result = pdblist.retrieve_pdb_file("zzzz", file_format="pdb")
|
||||
self.assertIsNone(result)
|
||||
with unittest.patch("sys.stderr") as mock_stderr:
|
||||
result = pdblist.retrieve_pdb_file("zzzz", file_format="pdb")
|
||||
self.assertIsNone(result)
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Desired structure not found or download failed." in str(call)
|
||||
for call in mock_stderr.write.call_args_list
|
||||
),
|
||||
"Error message not printed for non-existent molecule",
|
||||
)
|
||||
|
||||
def test_retrieve_pdb_file_bad_url(self):
|
||||
"""Tests retrieving with bad server URL returns None."""
|
||||
"""Tests retrieving with bad server URL - returns None and prints error message."""
|
||||
with self.make_temp_directory(os.getcwd()) as tmp:
|
||||
pdblist = PDBList(server=" http://something.wrong ", pdb=tmp)
|
||||
result = pdblist.retrieve_pdb_file("127d", file_format="pdb")
|
||||
self.assertIsNone(result)
|
||||
with unittest.patch("sys.stderr") as mock_stderr:
|
||||
result = pdblist.retrieve_pdb_file("127d", file_format="pdb")
|
||||
self.assertIsNone(result)
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Desired structure not found or download failed." in str(call)
|
||||
for call in mock_stderr.write.call_args_list
|
||||
),
|
||||
"Error message not printed for bad server URL",
|
||||
)
|
||||
|
||||
|
||||
class TestPDBListGetAssembly(unittest.TestCase):
|
||||
|
Reference in New Issue
Block a user