STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_runner_log_dir.py
Go to the documentation of this file.
1
"""Where an evaluate's debug log goes.
2
3
The Evaluate route runs the engine with ``debug=True``, which writes
4
``output/logs/evaluate.log`` under the working directory -- the repo, for a
5
stack run from a working tree -- and echoes every block to the console.
6
``ENGINE_DESIGN_LOG_DIR`` moves the file and ``ENGINE_DESIGN_CONSOLE_LOG_LEVEL``
7
quiets the console; unset, both are exactly as before.
8
"""
9
10
from
__future__
import
annotations
11
12
import
logging
13
from
pathlib
import
Path
14
15
ROOT = Path(__file__).resolve().parents[1]
16
PSI = 6894.757293168361
17
18
19
def
_evaluate_debug
() -> None:
20
from
engine.pipeline.io
import
load_config
21
from
engine.core.runner
import
PintleEngineRunner
22
23
cfg = load_config(str(ROOT /
"configs/ethalox_6500N.yaml"
))
24
P = 584.2669657943025 * PSI
25
PintleEngineRunner(cfg).evaluate(P_tank_O=P, P_tank_F=P, debug=
True
)
26
27
28
def
_console_levels
() -> list[int]:
29
return
[
30
h.level
31
for
h
in
logging.getLogger(
"evaluate"
).handlers
32
if
type(h)
is
logging.StreamHandler
33
]
34
35
36
def
test_debug_log_goes_where_it_is_told
(tmp_path, monkeypatch):
37
monkeypatch.chdir(tmp_path)
38
monkeypatch.setenv(
"ENGINE_DESIGN_LOG_DIR"
, str(tmp_path /
"elsewhere"
))
39
monkeypatch.setenv(
"ENGINE_DESIGN_CONSOLE_LOG_LEVEL"
,
"warning"
)
40
_evaluate_debug
()
41
assert
(tmp_path /
"elsewhere"
/
"evaluate.log"
).stat().st_size > 0
42
assert
not
(tmp_path /
"output"
).exists()
43
assert
_console_levels
() == [logging.WARNING]
44
45
46
def
test_unset_it_is_output_logs_under_the_working_directory
(tmp_path, monkeypatch):
47
monkeypatch.chdir(tmp_path)
48
monkeypatch.delenv(
"ENGINE_DESIGN_LOG_DIR"
, raising=
False
)
49
monkeypatch.delenv(
"ENGINE_DESIGN_CONSOLE_LOG_LEVEL"
, raising=
False
)
50
_evaluate_debug
()
51
assert
(tmp_path /
"output"
/
"logs"
/
"evaluate.log"
).stat().st_size > 0
52
assert
_console_levels
() == [logging.INFO]
53
54
55
def
test_a_level_it_does_not_know_keeps_the_console_at_info
(tmp_path, monkeypatch):
56
monkeypatch.chdir(tmp_path)
57
monkeypatch.setenv(
"ENGINE_DESIGN_LOG_DIR"
, str(tmp_path))
58
monkeypatch.setenv(
"ENGINE_DESIGN_CONSOLE_LOG_LEVEL"
,
"chatty"
)
59
_evaluate_debug
()
60
assert
_console_levels
() == [logging.INFO]
engine.core.runner
Definition
runner.py:1
engine.pipeline.io
Definition
io.py:1
test_runner_log_dir.test_debug_log_goes_where_it_is_told
test_debug_log_goes_where_it_is_told(tmp_path, monkeypatch)
Definition
test_runner_log_dir.py:36
test_runner_log_dir._evaluate_debug
None _evaluate_debug()
Definition
test_runner_log_dir.py:19
test_runner_log_dir.test_unset_it_is_output_logs_under_the_working_directory
test_unset_it_is_output_logs_under_the_working_directory(tmp_path, monkeypatch)
Definition
test_runner_log_dir.py:46
test_runner_log_dir.test_a_level_it_does_not_know_keeps_the_console_at_info
test_a_level_it_does_not_know_keeps_the_console_at_info(tmp_path, monkeypatch)
Definition
test_runner_log_dir.py:55
test_runner_log_dir._console_levels
list[int] _console_levels()
Definition
test_runner_log_dir.py:28
EngineDesign
tests
test_runner_log_dir.py
Generated by
1.15.0