Skip to content

Commit 336804c

Browse files
0.14.67
test
1 parent 780e5c0 commit 336804c

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.14.66"
10+
version = "0.14.67"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pickle
2+
import pytest
3+
from unittest.mock import patch, MagicMock
4+
5+
from spotPython.utils.file import load_and_run_spot_python_experiment
6+
7+
8+
@pytest.fixture
9+
def mock_experiment_data():
10+
return (
11+
MagicMock(), # mock spot_tuner
12+
{"TENSORBOARD_CLEAN": True, "tensorboard_start": False}, # mock fun_control
13+
MagicMock(), # mock design_control
14+
MagicMock(), # mock surrogate_control
15+
MagicMock() # mock optimizer_control
16+
)
17+
18+
19+
@patch("spotPython.utils.file.load_experiment")
20+
@patch("spotPython.utils.file.pprint.pprint")
21+
@patch("spotPython.utils.file.gen_design_table")
22+
@patch("spotPython.utils.file.setup_paths")
23+
@patch("spotPython.utils.file.start_tensorboard")
24+
@patch("spotPython.utils.file.stop_tensorboard")
25+
def test_load_and_run_spot_python_experiment(
26+
mock_stop_tensorboard,
27+
mock_start_tensorboard,
28+
mock_setup_paths,
29+
mock_gen_design_table,
30+
mock_pprint,
31+
mock_load_experiment,
32+
mock_experiment_data
33+
):
34+
# Set up the mocks
35+
mock_load_experiment.return_value = mock_experiment_data
36+
mock_start_tensorboard.return_value = None
37+
38+
# Call the function under test
39+
result = load_and_run_spot_python_experiment("spot_test_experiment.pkl")
40+
41+
# Verify behaviors for load_experiment and return values
42+
mock_load_experiment.assert_called_once_with("spot_test_experiment.pkl")
43+
mock_gen_design_table.assert_called_once_with(mock_experiment_data[1])
44+
mock_setup_paths.assert_called_once_with(mock_experiment_data[1]["TENSORBOARD_CLEAN"])
45+
mock_experiment_data[0].init_spot_writer.assert_called_once()
46+
mock_experiment_data[0].run.assert_called_once()
47+
mock_experiment_data[0].save_experiment.assert_called_once()
48+
mock_stop_tensorboard.assert_called_once_with(None)
49+
50+
# Assert the returned tuple
51+
assert result == (*mock_experiment_data, None)

0 commit comments

Comments
 (0)