Skip to content

Commit

Permalink
fix RuntimeErrror (#27)
Browse files Browse the repository at this point in the history
* fix RuntimeErrror

* lint
  • Loading branch information
PythonFZ authored Mar 15, 2023
1 parent 6565dda commit 101b6dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "znh5md"
version = "0.1.0"
version = "0.1.1"
description = "High Performance Interface for H5MD Trajectories"
authors = ["zincwarecode <[email protected]>"]
license = "Apache-2.0"
Expand Down
32 changes: 31 additions & 1 deletion tests/test_ASEH5MD.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

import ase
import pytest
from ase.calculators.calculator import PropertyNotImplementedError

import znh5md

Expand All @@ -19,8 +21,12 @@ def test_get_atoms_list(example_h5):
assert isinstance(atoms[0], ase.Atoms)


def test_get_slice(tmp_path, atoms_list):
@pytest.mark.parametrize("remove_calc", [True, False])
def test_get_slice(tmp_path, atoms_list, remove_calc):
os.chdir(tmp_path)
if remove_calc:
for atoms in atoms_list:
atoms.calc = None

db = znh5md.io.DataWriter(filename="db.h5")
db.initialize_database_groups()
Expand All @@ -39,3 +45,27 @@ def test_get_slice(tmp_path, atoms_list):
traj[1:2] == atoms_list[1:2]

assert len(traj.position) == 21


@pytest.mark.parametrize("remove_calc", [True, False])
def test_request_missing_properties(tmp_path, atoms_list, remove_calc):
os.chdir(tmp_path)
if remove_calc:
for atoms in atoms_list:
atoms.calc = None

db = znh5md.io.DataWriter(filename="db.h5")
db.initialize_database_groups()

if remove_calc:
with pytest.raises(RuntimeError):
for chunk in znh5md.io.AtomsReader(atoms_list).yield_chunks(
group_names=["stress"]
):
db.add_chunk_data(**chunk)
else:
with pytest.raises(PropertyNotImplementedError):
for chunk in znh5md.io.AtomsReader(atoms_list).yield_chunks(
group_names=["stress"]
):
db.add_chunk_data(**chunk)
2 changes: 1 addition & 1 deletion tests/test_znh5md.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_version():
assert znh5md.__version__ == "0.1.0"
assert znh5md.__version__ == "0.1.1"


def test_shape(example_h5):
Expand Down
8 changes: 4 additions & 4 deletions znh5md/io/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _get_box(self, atoms: list[ase.Atoms]) -> np.ndarray:
return np.array([x.get_cell() for x in atoms])

def yield_chunks(
self, group_name: list = None
self, group_names: list = None
) -> typing.Iterator[typing.Dict[str, ExplicitStepTimeChunk]]:
start_index = 0
stop_index = 0
Expand All @@ -55,7 +55,7 @@ def yield_chunks(
"box": self._get_box,
}

for name in group_name or functions:
for name in group_names or functions:
if name not in functions:
raise ValueError(f"Value {name} not supported")

Expand All @@ -66,8 +66,8 @@ def yield_chunks(
step=np.arange(start_index, start_index + len(value)),
time=np.arange(start_index, start_index + len(value)),
)
except PropertyNotImplementedError as err:
if group_name is not None:
except (PropertyNotImplementedError, RuntimeError) as err:
if group_names is not None:
# if the property was specifcally selected, raise the error
raise err
else:
Expand Down

0 comments on commit 101b6dc

Please sign in to comment.