Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/openfermion/chem/molecular_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import tempfile
import unittest
from unittest.mock import patch
import h5py
import numpy.random
import scipy.linalg
Expand Down Expand Up @@ -367,3 +368,14 @@ def test_load_no_general_calculations(self):
# Load the molecule and check that general_calculations is empty.
new_molecule = MolecularData(filename=filename)
self.assertEqual(new_molecule.general_calculations, {})

def test_get_from_file_exceptions(self):
with patch('h5py.File') as mock_file:
mock_file.return_value.__enter__.return_value.__getitem__.side_effect = KeyError
data = self.molecule.get_from_file("nonexistent_property")
self.assertIsNone(data)

with patch('h5py.File') as mock_file:
mock_file.side_effect = IOError
data = self.molecule.get_from_file("any_property")
self.assertIsNone(data)
Loading