generated from dbt-labs/dbt-oss-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a print Event to replace the print usage in dbt-core (#130)
* first_iter * add tests * nits * comment * check using name
- Loading branch information
1 parent
4c96366
commit e37d9c9
Showing
7 changed files
with
143 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add a print event to support firing event to console in --quiet mode | ||
time: 2024-05-15T16:11:06.815526-07:00 | ||
custom: | ||
Author: ChenyuLInx | ||
Issue: "8756" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
import json | ||
from dbt_common.events.logger import LoggerConfig, _TextLogger, _JsonLogger | ||
from dbt_common.events.base_types import EventLevel, msg_from_base_event | ||
from dbt_common.events.types import PrintEvent | ||
|
||
|
||
def test_create_print_line(): | ||
# No format, still fired even when error is the level | ||
config = LoggerConfig(name="test_logger", level=EventLevel.ERROR) | ||
logger = _TextLogger(config) | ||
msg = msg_from_base_event(PrintEvent(msg="This is a print event")) | ||
expected_line = "This is a print event" | ||
actual_line = logger.create_line(msg) | ||
assert actual_line == expected_line | ||
|
||
|
||
def test_create_print_json(): | ||
# JSON format still have event level being info | ||
config = LoggerConfig(name="test_logger", level=EventLevel.ERROR) | ||
logger = _JsonLogger(config) | ||
msg = msg_from_base_event(PrintEvent(msg="This is a print event")) | ||
expected_json = { | ||
"data": {"msg": "This is a print event"}, | ||
"info": { | ||
"category": "", | ||
"code": "Z052", | ||
"extra": {}, | ||
"level": "info", | ||
"msg": "This is a print event", | ||
"name": "PrintEvent", | ||
"thread": "MainThread", | ||
}, | ||
} | ||
actual_line = logger.create_line(msg) | ||
actual_json = json.loads(actual_line) | ||
assert "info" in actual_json | ||
actual_json["info"].pop("invocation_id") | ||
actual_json["info"].pop("ts") | ||
actual_json["info"].pop("pid") | ||
assert actual_json == expected_json |
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