diff --git a/micromagneticmodel/driver.py b/micromagneticmodel/driver.py index 79a7147..151cc04 100644 --- a/micromagneticmodel/driver.py +++ b/micromagneticmodel/driver.py @@ -294,6 +294,9 @@ def _write_info_json(self, system, **kwargs): info["date"] = datetime.datetime.now().strftime("%Y-%m-%d") info["time"] = datetime.datetime.now().strftime("%H:%M:%S") info["driver"] = self.__class__.__name__ + # "adapter" is the ubermag package (e.g. oommfc) that communicates with the + # calculator (e.g. OOMMF) + info["adapter"] = self.__module__.split(".")[0] for k, v in kwargs.items(): info[k] = v with open("info.json", "wt", encoding="utf-8") as jsonfile: diff --git a/micromagneticmodel/tests/test_driver.py b/micromagneticmodel/tests/test_driver.py index 593b5d5..a1abf33 100644 --- a/micromagneticmodel/tests/test_driver.py +++ b/micromagneticmodel/tests/test_driver.py @@ -1,3 +1,6 @@ +import datetime +import json + import discretisedfield as df import pytest @@ -66,6 +69,18 @@ def test_external_driver(tmp_path): assert system.m.allclose(-mm.examples.macrospin().m) assert (tmp_path / system.name / "drive-0" / "info.json").exists() + with open(tmp_path / system.name / "drive-0" / "info.json") as f: + info = json.load(f) + + assert info["adapter"] == "micromagneticmodel" + assert info["driver"] == "MyExternalDriver" + assert info["drive_number"] == 0 + + info_time = datetime.datetime.fromisoformat(f"{info['date']}T{info['time']}") + now = datetime.datetime.now() + # assumption: this test runs in under one minute + assert (now - info_time).total_seconds() < 60 + with pytest.raises(FileExistsError): driver.drive(system, dirname=str(tmp_path), append=False)