Skip to content

Commit

Permalink
Add tests for CADET paths and CADET Runner attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronald-jaepel committed Aug 20, 2024
1 parent e153f3b commit 26e19e9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
9 changes: 2 additions & 7 deletions tests/test_dll.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import copy
import os
from pathlib import Path
import platform
import subprocess
import sys

from addict import Dict
import pytest

from cadet import Cadet
Expand All @@ -14,7 +8,8 @@
# %% Utility methods

# TODO: Remove once #14 is merged
cadet_root = Path('/home/jo/code/CADET/install/capi/')
# cadet_root = Path('/home/jo/code/CADET/install/capi/')
cadet_root = Path(r'C:\Users\ronal\Documents\CADET\out\install\aRELEASE')

def setup_model(
cadet_root,
Expand Down
47 changes: 27 additions & 20 deletions tests/test_install_path_settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import warnings
import os
from pathlib import Path

import pytest
import re

from cadet import Cadet

# Full path to cadet.dll or cadet.so, that is different from the system/conda cadet
full_path_dll = Path(r"C:\Users\ronal\Documents\CADET\out\install\aRELEASE\bin\cadet.dll")
install_path_dll = full_path_dll.parent.parent

install_path_conda = Cadet.autodetect_cadet()

Expand All @@ -16,42 +17,48 @@ def test_autodetection():
assert sim.install_path == install_path_conda
assert sim.cadet_dll_path.parent.parent == install_path_conda
assert sim.cadet_cli_path.parent.parent == install_path_conda
assert sim.cadet_runner.cadet_path.suffix != "dll"
assert sim.cadet_runner.cadet_path.suffix not in [".dll", ".so"]


def test_install_path():
sim = Cadet(install_path=full_path_dll, use_dll=True)
assert sim.cadet_dll_path == full_path_dll
assert sim.cadet_runner.cadet_path.suffix == ".dll"
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]

sim = Cadet()
sim.install_path = full_path_dll.parent.parent
sim.use_dll = True
assert sim.cadet_dll_path == full_path_dll
assert sim.cadet_runner.cadet_path.suffix == ".dll"
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]

sim = Cadet()
with pytest.deprecated_call():
sim.cadet_path = full_path_dll.parent.parent

sim.use_dll = True
assert sim.cadet_dll_path == full_path_dll
assert sim.cadet_runner.cadet_path.suffix == ".dll"
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]


def test_meta_class():
Cadet.cadet_path = full_path_dll
assert Cadet.use_dll
def test_dll_runner_attrs():
cadet = Cadet(full_path_dll.parent.parent)
cadet_runner = cadet._cadet_dll_runner
assert re.match("\d\.\d\.\d", cadet_runner.cadet_version)
assert isinstance(cadet_runner.cadet_branch, str)
assert isinstance(cadet_runner.cadet_build_type, str | None)
assert isinstance(cadet_runner.cadet_commit_hash, str)
assert isinstance(cadet_runner.cadet_path, str | os.PathLike)

# With a path set in the meta class, the sim instance should not autodetect and use the meta class cadet path
sim = Cadet()
assert sim.use_dll
assert sim.install_path == install_path_dll
assert sim.cadet_dll_path.parent.parent == install_path_dll
assert sim.cadet_cli_path.parent.parent == install_path_dll

# With an install path given, the sim instance should use the given install path
sim = Cadet(install_path=install_path_conda)
assert sim.install_path == install_path_conda
assert sim.cadet_dll_path.parent.parent == install_path_conda
assert sim.cadet_cli_path.parent.parent == install_path_conda
def test_cli_runner_attrs():
cadet = Cadet(full_path_dll.parent.parent)
cadet_runner = cadet._cadet_cli_runner
assert re.match("\d\.\d\.\d", cadet_runner.cadet_version)
assert isinstance(cadet_runner.cadet_branch, str)
assert isinstance(cadet_runner.cadet_build_type, str | None)
assert isinstance(cadet_runner.cadet_commit_hash, str)
assert isinstance(cadet_runner.cadet_path, str | os.PathLike)


if __name__ == '__main__':
pytest.main(["test_install_path_settings.py"])
27 changes: 27 additions & 0 deletions tests/test_meta_class_install_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path

from cadet import Cadet


# Full path to cadet.dll or cadet.so, that is different from the system/conda cadet
full_path_dll = Path(r"C:\Users\ronal\Documents\CADET\out\install\aRELEASE\bin\cadet.dll")

install_path_conda = Cadet.autodetect_cadet()


def test_meta_class():
Cadet.cadet_path = full_path_dll
assert Cadet.use_dll

# With a path set in the meta class, the sim instance should not autodetect and use the meta class cadet path
sim = Cadet()
assert sim.use_dll
assert sim.install_path == full_path_dll.parent.parent
assert sim.cadet_dll_path == full_path_dll
assert sim.cadet_cli_path.parent == full_path_dll.parent

# With an install path given, the sim instance should use the given install path
sim = Cadet(install_path=install_path_conda)
assert sim.install_path == install_path_conda
assert sim.cadet_dll_path.parent.parent == install_path_conda
assert sim.cadet_cli_path.parent.parent == install_path_conda

0 comments on commit 26e19e9

Please sign in to comment.