-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make IsolateLogger more explicit (#152)
* refactor: make IsolateLogger more explicit * Update src/isolate/logger.py Co-authored-by: Ruslan Kuprieiev <[email protected]> * typing * tests --------- Co-authored-by: Ruslan Kuprieiev <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
22 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 |
---|---|---|
@@ -1,22 +1,45 @@ | ||
import json | ||
|
||
import pytest | ||
from isolate.logger import IsolateLogger | ||
|
||
|
||
def test_logger(monkeypatch): | ||
labels = { | ||
@pytest.fixture | ||
def log_labels(): | ||
return { | ||
"foo": "$MYENVVAR1", | ||
"bar": "$MYENVVAR2", | ||
"baz": "baz", | ||
"qux": "qux", | ||
"qux": "$NOTTHERE", | ||
} | ||
|
||
|
||
def test_logger_with_env_expanded(log_labels, monkeypatch): | ||
monkeypatch.setenv("MYENVVAR1", "myenvvar1") | ||
monkeypatch.setenv("MYENVVAR2", "myenvvar2") | ||
monkeypatch.setenv("ISOLATE_LOG_LABELS", json.dumps(labels)) | ||
logger = IsolateLogger() | ||
logger = IsolateLogger.with_env_expanded(log_labels) | ||
assert logger.log_labels == { | ||
"foo": "myenvvar1", | ||
"bar": "myenvvar2", | ||
"baz": "baz", | ||
"qux": "qux", | ||
"qux": "$NOTTHERE", | ||
} | ||
|
||
|
||
def test_logger_from_env(log_labels, monkeypatch): | ||
monkeypatch.setenv("MYENVVAR1", "myenvvar1") | ||
monkeypatch.setenv("MYENVVAR2", "myenvvar2") | ||
monkeypatch.setenv("ISOLATE_LOG_LABELS", json.dumps(log_labels)) | ||
logger = IsolateLogger.from_env() | ||
assert logger.log_labels == { | ||
"foo": "myenvvar1", | ||
"bar": "myenvvar2", | ||
"baz": "baz", | ||
"qux": "$NOTTHERE", | ||
} | ||
|
||
|
||
def test_logger_direct(log_labels): | ||
logger = IsolateLogger(log_labels=log_labels) | ||
# should not do env expansion | ||
assert logger.log_labels == log_labels |