Skip to content

Commit e93a9a0

Browse files
add a test
1 parent 472dc06 commit e93a9a0

2 files changed

Lines changed: 83 additions & 1 deletion

File tree

mirgecom/logging_quantities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def logmgr_verify_steptime(logmgr: LogManager, tolerance: float = 1.1) -> None:
176176
177177
Call this function after :meth:`logpyle.LogManager.tick_after`.
178178
179-
:arg tolerance: tolerance factor for the step time.
179+
:arg tolerance: tolerance factor for the step time. Should be >=1.
180180
"""
181181
t_step = logmgr.last_values.get("t_step", 0.0)
182182
t_2step = logmgr.last_values.get("t_2step", 0.0)

test/test_logging.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""Test built-in logging functionality."""
2+
3+
__copyright__ = """
4+
Copyright (C) 2025 University of Illinois Board of Trustees
5+
"""
6+
7+
__license__ = """
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.
25+
"""
26+
27+
import pytest
28+
29+
from logpyle import (
30+
EventCounter,
31+
IntervalTimer,
32+
LogManager,
33+
LogQuantity,
34+
PushLogQuantity,
35+
add_general_quantities,
36+
add_run_info,
37+
add_simulation_quantities,
38+
set_dt,
39+
time_and_count_function,
40+
)
41+
42+
43+
@pytest.fixture
44+
def basic_logmgr():
45+
import os
46+
47+
# setup
48+
filename = "THIS_LOG_SHOULD_BE_DELETED.sqlite"
49+
logmgr = LogManager(filename, "wo")
50+
51+
# give obj to test
52+
yield logmgr
53+
54+
# clean up object
55+
logmgr.close()
56+
os.remove(filename)
57+
58+
59+
def test_logmgr_verify_steptime(basic_logmgr) -> None:
60+
from mirgecom.logging_quantities import logmgr_verify_steptime
61+
from time import sleep
62+
63+
add_general_quantities(basic_logmgr)
64+
65+
basic_logmgr.tick_before()
66+
sleep(0.1)
67+
basic_logmgr.tick_after()
68+
69+
sleep(0.1) # Do "work" in between ticks
70+
71+
basic_logmgr.tick_before()
72+
sleep(0.1)
73+
basic_logmgr.tick_after()
74+
75+
with pytest.warns(UserWarning):
76+
logmgr_verify_steptime(basic_logmgr)
77+
78+
import warnings
79+
with warnings.catch_warnings():
80+
# make sure this does not raise a warning
81+
warnings.simplefilter("error")
82+
logmgr_verify_steptime(basic_logmgr, 3.0)

0 commit comments

Comments
 (0)