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
3The Evaluate route runs the engine with ``debug=True``, which writes
4``output/logs/evaluate.log`` under the working directory -- the repo, for a
5stack 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``
7quiets the console; unset, both are exactly as before.
8"""
9
10from __future__ import annotations
11
12import logging
13from pathlib import Path
14
15ROOT = Path(__file__).resolve().parents[1]
16PSI = 6894.757293168361
17
18
19def _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
28def _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
36def 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")
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
47 monkeypatch.chdir(tmp_path)
48 monkeypatch.delenv("ENGINE_DESIGN_LOG_DIR", raising=False)
49 monkeypatch.delenv("ENGINE_DESIGN_CONSOLE_LOG_LEVEL", raising=False)
51 assert (tmp_path / "output" / "logs" / "evaluate.log").stat().st_size > 0
52 assert _console_levels() == [logging.INFO]
53
54
56 monkeypatch.chdir(tmp_path)
57 monkeypatch.setenv("ENGINE_DESIGN_LOG_DIR", str(tmp_path))
58 monkeypatch.setenv("ENGINE_DESIGN_CONSOLE_LOG_LEVEL", "chatty")
60 assert _console_levels() == [logging.INFO]
test_debug_log_goes_where_it_is_told(tmp_path, monkeypatch)
test_unset_it_is_output_logs_under_the_working_directory(tmp_path, monkeypatch)
test_a_level_it_does_not_know_keeps_the_console_at_info(tmp_path, monkeypatch)