-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: add test for logging with timing
- Loading branch information
1 parent
d9f4e5e
commit 30eb49d
Showing
3 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Test logging utils.""" | ||
|
||
import io | ||
import unittest | ||
from contextlib import redirect_stdout | ||
|
||
from molpipeline.utils.logging import print_elapsed_time | ||
|
||
|
||
class LoggingUtilsTest(unittest.TestCase): | ||
"""Unittest for conversion of sklearn models to json and back.""" | ||
|
||
def test__print_elapsed_time(self) -> None: | ||
"""Test message logging with timings work as expected.""" | ||
|
||
# when message is None nothing should be printed | ||
stream1 = io.StringIO() | ||
with redirect_stdout(stream1): | ||
with print_elapsed_time("source", message=None, use_logger=False): | ||
pass | ||
output1 = stream1.getvalue() | ||
self.assertEqual(output1, "") | ||
|
||
# message should be printed in the expected sklearn format | ||
stream2 = io.StringIO() | ||
with redirect_stdout(stream2): | ||
with print_elapsed_time("source", message="my message", use_logger=False): | ||
pass | ||
output2 = stream2.getvalue() | ||
self.assertTrue( | ||
output2.startswith( | ||
"[source] ................................... my message, total=" | ||
) | ||
) |