Skip to content

Commit

Permalink
Tidy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar authored and alinelena committed Apr 5, 2024
1 parent 0d601d2 commit 91dd53f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
12 changes: 7 additions & 5 deletions tests/test_geomopt_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml

from janus_core.cli import app
from tests.utils import check_log_contents, read_atoms
from tests.utils import assert_log_contains, read_atoms

DATA_PATH = Path(__file__).parent / "data"

Expand Down Expand Up @@ -75,7 +75,7 @@ def test_log(tmp_path):
)
assert result.exit_code == 0

check_log_contents(
assert_log_contains(
log_path, includes="Starting geometry optimization", excludes="Using filter"
)

Expand Down Expand Up @@ -131,7 +131,9 @@ def test_fully_opt(tmp_path):
)
assert result.exit_code == 0

check_log_contents(log_path, includes=["Using filter", "hydrostatic_strain: False"])
assert_log_contains(
log_path, includes=["Using filter", "hydrostatic_strain: False"]
)

atoms = read(results_path)
expected = [5.68834069, 5.68893345, 5.68932555, 89.75938298, 90.0, 90.0]
Expand Down Expand Up @@ -162,7 +164,7 @@ def test_fully_opt_and_vectors(tmp_path):
)
assert result.exit_code == 0

check_log_contents(log_path, includes=["Using filter", "hydrostatic_strain: True"])
assert_log_contains(log_path, includes=["Using filter", "hydrostatic_strain: True"])

atoms = read(results_path)
expected = [5.69139709, 5.69139709, 5.69139709, 89.0, 90.0, 90.0]
Expand Down Expand Up @@ -192,7 +194,7 @@ def test_vectors_not_fully_opt(tmp_path):
)
assert result.exit_code == 0

check_log_contents(log_path, includes=["Using filter", "hydrostatic_strain: True"])
assert_log_contains(log_path, includes=["Using filter", "hydrostatic_strain: True"])


def test_duplicate_traj(tmp_path):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import yaml

from janus_core.log import config_logger
from tests.utils import check_log_contents
from tests.utils import assert_log_contains


def test_multiline_log(tmp_path):
Expand All @@ -27,4 +27,4 @@ def test_multiline_log(tmp_path):
assert log_dicts[0]["level"] == "INFO"
assert len(log_dicts[0]["message"]) == 3

check_log_contents(log_path, includes=["Line 1", "Line 4"])
assert_log_contains(log_path, includes=["Line 1", "Line 4"])
4 changes: 2 additions & 2 deletions tests/test_md_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import yaml

from janus_core.cli import app
from tests.utils import check_log_contents
from tests.utils import assert_log_contains

DATA_PATH = Path(__file__).parent / "data"

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_log(tmp_path):
)
assert result.exit_code == 0

check_log_contents(log_path, includes=["Starting molecular dynamics simulation"])
assert_log_contains(log_path, includes=["Starting molecular dynamics simulation"])

with open(tmp_path / "nvt-T300-stats.dat", encoding="utf8") as stats_file:
lines = stats_file.readlines()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_singlepoint_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml

from janus_core.cli import app
from tests.utils import check_log_contents, read_atoms
from tests.utils import assert_log_contains, read_atoms

DATA_PATH = Path(__file__).parent / "data"

Expand Down Expand Up @@ -192,7 +192,7 @@ def test_log(tmp_path):
)
assert result.exit_code == 0

check_log_contents(log_path, includes=["Starting single point calculation"])
assert_log_contains(log_path, includes=["Starting single point calculation"])


def test_summary(tmp_path):
Expand Down
7 changes: 4 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utility functions for tests."""

from pathlib import Path
from typing import Optional, Union
from typing import Union

from ase import Atoms
from ase.io import read
Expand Down Expand Up @@ -35,8 +35,9 @@ def read_atoms(path: Path) -> Union[Atoms, None]:
return atoms if atoms else None


def check_log_contents(
log_path: PathLike, *,
def assert_log_contains(
log_path: PathLike,
*,
includes: MaybeSequence[str] = (),
excludes: MaybeSequence[str] = (),
) -> None:
Expand Down

0 comments on commit 91dd53f

Please sign in to comment.