File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import os
1515import tempfile
1616import unittest
17+ from unittest .mock import patch
1718import h5py
1819import numpy .random
1920import scipy .linalg
@@ -367,3 +368,14 @@ def test_load_no_general_calculations(self):
367368 # Load the molecule and check that general_calculations is empty.
368369 new_molecule = MolecularData (filename = filename )
369370 self .assertEqual (new_molecule .general_calculations , {})
371+
372+ def test_get_from_file_exceptions (self ):
373+ with patch ('h5py.File' ) as mock_file :
374+ mock_file .return_value .__enter__ .return_value .__getitem__ .side_effect = KeyError
375+ data = self .molecule .get_from_file ("nonexistent_property" )
376+ self .assertIsNone (data )
377+
378+ with patch ('h5py.File' ) as mock_file :
379+ mock_file .side_effect = IOError
380+ data = self .molecule .get_from_file ("any_property" )
381+ self .assertIsNone (data )
You can’t perform that action at this time.
0 commit comments