Skip to content

Commit 26e19e9

Browse files
committed
Add tests for CADET paths and CADET Runner attributes
1 parent e153f3b commit 26e19e9

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

tests/test_dll.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import copy
2-
import os
31
from pathlib import Path
4-
import platform
52
import subprocess
6-
import sys
7-
8-
from addict import Dict
93
import pytest
104

115
from cadet import Cadet
@@ -14,7 +8,8 @@
148
# %% Utility methods
159

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

1914
def setup_model(
2015
cadet_root,

tests/test_install_path_settings.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import warnings
1+
import os
22
from pathlib import Path
33

44
import pytest
5+
import re
56

67
from cadet import Cadet
78

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

1112
install_path_conda = Cadet.autodetect_cadet()
1213

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

2122

2223
def test_install_path():
2324
sim = Cadet(install_path=full_path_dll, use_dll=True)
2425
assert sim.cadet_dll_path == full_path_dll
25-
assert sim.cadet_runner.cadet_path.suffix == ".dll"
26+
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]
2627

2728
sim = Cadet()
2829
sim.install_path = full_path_dll.parent.parent
2930
sim.use_dll = True
3031
assert sim.cadet_dll_path == full_path_dll
31-
assert sim.cadet_runner.cadet_path.suffix == ".dll"
32+
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]
3233

3334
sim = Cadet()
3435
with pytest.deprecated_call():
3536
sim.cadet_path = full_path_dll.parent.parent
3637

3738
sim.use_dll = True
3839
assert sim.cadet_dll_path == full_path_dll
39-
assert sim.cadet_runner.cadet_path.suffix == ".dll"
40+
assert sim.cadet_runner.cadet_path.suffix in [".dll", ".so"]
4041

4142

42-
def test_meta_class():
43-
Cadet.cadet_path = full_path_dll
44-
assert Cadet.use_dll
43+
def test_dll_runner_attrs():
44+
cadet = Cadet(full_path_dll.parent.parent)
45+
cadet_runner = cadet._cadet_dll_runner
46+
assert re.match("\d\.\d\.\d", cadet_runner.cadet_version)
47+
assert isinstance(cadet_runner.cadet_branch, str)
48+
assert isinstance(cadet_runner.cadet_build_type, str | None)
49+
assert isinstance(cadet_runner.cadet_commit_hash, str)
50+
assert isinstance(cadet_runner.cadet_path, str | os.PathLike)
4551

46-
# With a path set in the meta class, the sim instance should not autodetect and use the meta class cadet path
47-
sim = Cadet()
48-
assert sim.use_dll
49-
assert sim.install_path == install_path_dll
50-
assert sim.cadet_dll_path.parent.parent == install_path_dll
51-
assert sim.cadet_cli_path.parent.parent == install_path_dll
5252

53-
# With an install path given, the sim instance should use the given install path
54-
sim = Cadet(install_path=install_path_conda)
55-
assert sim.install_path == install_path_conda
56-
assert sim.cadet_dll_path.parent.parent == install_path_conda
57-
assert sim.cadet_cli_path.parent.parent == install_path_conda
53+
def test_cli_runner_attrs():
54+
cadet = Cadet(full_path_dll.parent.parent)
55+
cadet_runner = cadet._cadet_cli_runner
56+
assert re.match("\d\.\d\.\d", cadet_runner.cadet_version)
57+
assert isinstance(cadet_runner.cadet_branch, str)
58+
assert isinstance(cadet_runner.cadet_build_type, str | None)
59+
assert isinstance(cadet_runner.cadet_commit_hash, str)
60+
assert isinstance(cadet_runner.cadet_path, str | os.PathLike)
61+
62+
63+
if __name__ == '__main__':
64+
pytest.main(["test_install_path_settings.py"])

tests/test_meta_class_install_path.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
3+
from cadet import Cadet
4+
5+
6+
# Full path to cadet.dll or cadet.so, that is different from the system/conda cadet
7+
full_path_dll = Path(r"C:\Users\ronal\Documents\CADET\out\install\aRELEASE\bin\cadet.dll")
8+
9+
install_path_conda = Cadet.autodetect_cadet()
10+
11+
12+
def test_meta_class():
13+
Cadet.cadet_path = full_path_dll
14+
assert Cadet.use_dll
15+
16+
# With a path set in the meta class, the sim instance should not autodetect and use the meta class cadet path
17+
sim = Cadet()
18+
assert sim.use_dll
19+
assert sim.install_path == full_path_dll.parent.parent
20+
assert sim.cadet_dll_path == full_path_dll
21+
assert sim.cadet_cli_path.parent == full_path_dll.parent
22+
23+
# With an install path given, the sim instance should use the given install path
24+
sim = Cadet(install_path=install_path_conda)
25+
assert sim.install_path == install_path_conda
26+
assert sim.cadet_dll_path.parent.parent == install_path_conda
27+
assert sim.cadet_cli_path.parent.parent == install_path_conda

0 commit comments

Comments
 (0)