generated from dbt-labs/dbt-oss-template
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to silence
events via WarnErrorOptions
#112
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
428823f
Add `silence` option to `WarnErrorOptions`
QMalcolm 6b88244
Add `silenced` def to `IncludeExclude` and use in `includes`
QMalcolm 45fd2cc
Begin using `silenced` of `WarnErrorOptions` in `warn_or_error`
QMalcolm 71286b2
Refactor `get_all_subclasses` in `test_events` to ignore events class…
QMalcolm 688556f
Changie doc for new `silence` of `WarnErrorOptions`
QMalcolm 61f7ff9
Refactor `silence` logic from `IncludeExclude` to `WarnErrorOptions`
QMalcolm be987dc
Create `event_name` in `warn_or_error` to reduce regeneration of name
QMalcolm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ability to silence warnings via `WarnErrorOptions` | ||
time: 2024-04-19T23:20:30.014054-07:00 | ||
custom: | ||
Author: QMalcolm | ||
Issue: "111" |
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
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,79 @@ | ||
import pytest | ||
|
||
from dataclasses import dataclass, field | ||
from dbt_common.events import functions | ||
from dbt_common.events.base_types import EventLevel, EventMsg, WarnLevel | ||
from dbt_common.events.event_manager import EventManager | ||
from dbt_common.events.event_manager_client import ctx_set_event_manager | ||
from dbt_common.exceptions import EventCompilationError | ||
from dbt_common.helper_types import WarnErrorOptions | ||
from typing import List, Set | ||
|
||
|
||
# Re-implementing `Note` event as a warn event for | ||
# our testing purposes | ||
class Note(WarnLevel): | ||
def code(self) -> str: | ||
return "Z050" | ||
|
||
def message(self) -> str: | ||
return self.msg | ||
|
||
|
||
@dataclass | ||
class EventCatcher: | ||
caught_events: List[EventMsg] = field(default_factory=list) | ||
|
||
def catch(self, event: EventMsg) -> None: | ||
self.caught_events.append(event) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def event_catcher() -> EventCatcher: | ||
return EventCatcher() | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def set_event_manager_with_catcher(event_catcher: EventCatcher) -> None: | ||
event_manager = EventManager() | ||
event_manager.callbacks.append(event_catcher.catch) | ||
ctx_set_event_manager(event_manager) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def valid_error_names() -> Set[str]: | ||
return {Note.__name__} | ||
|
||
|
||
class TestWarnOrError: | ||
def test_fires_error(self, valid_error_names: Set[str]): | ||
functions.WARN_ERROR_OPTIONS = WarnErrorOptions( | ||
include="*", valid_error_names=valid_error_names | ||
) | ||
with pytest.raises(EventCompilationError): | ||
functions.warn_or_error(Note(msg="hi")) | ||
|
||
def test_fires_warning( | ||
self, | ||
valid_error_names: Set[str], | ||
event_catcher: EventCatcher, | ||
set_event_manager_with_catcher, | ||
): | ||
functions.WARN_ERROR_OPTIONS = WarnErrorOptions( | ||
include="*", exclude=list(valid_error_names), valid_error_names=valid_error_names | ||
) | ||
functions.warn_or_error(Note(msg="hi")) | ||
assert len(event_catcher.caught_events) == 1 | ||
assert event_catcher.caught_events[0].info.level == EventLevel.WARN.value | ||
|
||
def test_silenced( | ||
self, | ||
valid_error_names: Set[str], | ||
event_catcher: EventCatcher, | ||
set_event_manager_with_catcher, | ||
): | ||
functions.WARN_ERROR_OPTIONS = WarnErrorOptions( | ||
include="*", silence=list(valid_error_names), valid_error_names=valid_error_names | ||
) | ||
functions.warn_or_error(Note(msg="hi")) | ||
assert len(event_catcher.caught_events) == 0 |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨