Skip to content

Commit

Permalink
Rudimentary test for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
frostedoyster committed Feb 6, 2024
1 parent 8b39820 commit 9069a29
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/cli/test_train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,31 @@ def test_no_architecture_name(monkeypatch, tmp_path):
)
except subprocess.CalledProcessError as captured:
assert "Architecture name is not defined!" in str(captured.output)


def test_train_logging(monkeypatch, tmp_path):
"""Test that training via the training cli runs without an error raise."""
monkeypatch.chdir(tmp_path)
shutil.copy(RESOURCES_PATH / "qm9_reduced_100.xyz", "qm9_reduced_100.xyz")
shutil.copy(RESOURCES_PATH / "options.yaml", "options.yaml")

command = ["metatensor-models", "train", "options.yaml"]

subprocess.check_call(command)

# Test if fully expanded options.yaml file is written
assert len(glob.glob("outputs/*/*/options.yaml")) == 1

# Test if logfile is written
assert len(glob.glob("outputs/*/*/train.log")) == 1

# Open the log file and check if the logging is correct
with open(glob.glob("outputs/*/*/train.log")[0]) as f:
log = f.read()

assert "[INFO]" in log
assert "Epoch" in log
assert "loss" in log
assert "validation" in log
assert "train" in log
assert "energy" in log

0 comments on commit 9069a29

Please sign in to comment.