-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: Add time_logger() context manager
- Loading branch information
Showing
4 changed files
with
35 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,15 @@ | ||
from __future__ import unicode_literals | ||
|
||
import contextlib | ||
import logging | ||
import time | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@contextlib.contextmanager | ||
def time_logger(name): | ||
start = time.time() | ||
yield | ||
logger.debug('%s took %dms', name, (time.time() - start) * 1000) |
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,12 @@ | ||
from __future__ import unicode_literals | ||
|
||
import re | ||
|
||
from mopidy_spotify import utils | ||
|
||
|
||
def test_time_logger(caplog): | ||
with utils.time_logger('task'): | ||
pass | ||
|
||
assert re.match('.*task took \d+ms.*', caplog.text()) |