From fb4a24da3d9b9345cbb2b7748c3fab0803a24888 Mon Sep 17 00:00:00 2001 From: frostedoyster Date: Mon, 11 Nov 2024 18:40:24 +0100 Subject: [PATCH] One more test --- tests/utils/data/test_readers_metatensor.py | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/utils/data/test_readers_metatensor.py b/tests/utils/data/test_readers_metatensor.py index b03470b4..5b990032 100644 --- a/tests/utils/data/test_readers_metatensor.py +++ b/tests/utils/data/test_readers_metatensor.py @@ -1,4 +1,5 @@ import metatensor.torch +import numpy as np import pytest import torch from metatensor.torch import Labels, TensorBlock, TensorMap @@ -231,3 +232,27 @@ def test_read_generic_cartesian(monkeypatch, tmpdir, cartesian_tensor_map): for tensor_map in tensor_maps: assert metatensor.torch.equal(tensor_map, cartesian_tensor_map) + + +def test_read_error(monkeypatch, tmpdir): + monkeypatch.chdir(tmpdir) + + numpy_array = np.zeros((2, 2)) + np.save("numpy_array.mts", numpy_array) + + conf = { + "quantity": "energy", + "read_from": "numpy_array.mts", + "reader": "metatensor", + "key": "true_energy", + "unit": "eV", + "type": "scalar", + "per_atom": False, + "num_properties": 1, + "forces": False, + "stress": False, + "virial": False, + } + + with pytest.raises(ValueError, match="Failed to read"): + read_energy(OmegaConf.create(conf))