Skip to content

Commit

Permalink
Raise Value Error for empty list. (#664)
Browse files Browse the repository at this point in the history
* Raise Value Error for empty list

* Add check for empty line at begining of xyz

* Add test for empty line in xyz input

---------

Co-authored-by: Adam Grofe <[email protected]>
  • Loading branch information
adam-grofe and Adam Grofe authored Feb 25, 2025
1 parent 5b78c88 commit 6c99137
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def submit(self,

if isinstance(input_data, list):

if len(input_data) < 1:
raise ValueError("Input data list has no elements.")

if all(isinstance(task,str) for task in input_data):
qcschema_data = self.assemble_qcschema_from_files(input_data, input_params)

Expand Down Expand Up @@ -257,7 +260,7 @@ def _xyz_to_qcschema_mol(self, file_data: str ) -> Dict[str, Any]:
"""

lines = file_data.split("\n")
if len(lines) < 3:
if len(lines) < 3 or not lines[0]:
raise ValueError("Invalid xyz format.")
n_atoms = int(lines.pop(0))
comment = lines.pop(0)
Expand Down
10 changes: 9 additions & 1 deletion azure-quantum/tests/unit/test_microsoft_elements_dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,22 @@ def test_xyz_parsing_correct_xyz_files(data_regression, xyz_str):
H 1.00 0.00 0.00
H -1.00 1.00 1.00
H -1.00 1.00 1.00 -0.6
""",
"""
3
water
O 0.00 0.00 0.00
H 1.00 0.00 0.00
H -1.00 1.00 1.00
""",
],
ids=[
'atom_missing',
'atom_on_previous_line',
'empty_line_in_middle',
'duplicated_line',
'mm_atom_without_dash'
'mm_atom_without_dash',
'empty_line_at_beginning'
]
)
def test_xyz_raises_for_bad_input(xyz_str):
Expand Down

0 comments on commit 6c99137

Please sign in to comment.