Skip to content

Commit

Permalink
Move setup_event_logger tests from test_functions.py to `test_log…
Browse files Browse the repository at this point in the history
…ging.py`
  • Loading branch information
QMalcolm committed May 15, 2024
1 parent 38bcde5 commit e08c448
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 17 additions & 1 deletion tests/unit/events/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from argparse import Namespace
from copy import deepcopy

from pytest_mock import MockerFixture

from dbt.events.logging import setup_event_logger
from dbt.flags import get_flags
from dbt.flags import get_flags, set_from_args
from dbt_common.events.base_types import BaseEvent
from dbt_common.events.event_manager_client import get_event_manager
from dbt_common.events.logger import LoggerConfig
Expand All @@ -24,3 +27,16 @@ def test_clears_preexisting_event_manager_state(self, mock_global_event_manager)
setup_event_logger(flags=flags)
assert len(manager.loggers) == 0
assert len(manager.callbacks) == 0

def test_specify_max_bytes(
self,
mocker: MockerFixture,
mock_global_event_manager,
) -> None:
patched_file_handler = mocker.patch("dbt_common.events.logger.RotatingFileHandler")
args = Namespace(log_file_max_bytes=1234567)
set_from_args(args, {})
setup_event_logger(get_flags())
patched_file_handler.assert_called_once_with(
filename="logs/dbt.log", encoding="utf8", maxBytes=1234567, backupCount=5
)
14 changes: 0 additions & 14 deletions tests/unit/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from argparse import Namespace

import pytest
from pytest_mock import MockerFixture

import dbt.flags as flags
from dbt.adapters.events.types import AdapterDeprecationWarning
from dbt.events.logging import setup_event_logger
from dbt.events.types import NoNodesForSelectionCriteria
from dbt_common.events.functions import msg_to_dict, warn_or_error
from dbt_common.events.types import InfoLevel, RetryExternalCall
Expand Down Expand Up @@ -83,15 +81,3 @@ def __init__(self):
assert (
False
), f"We expect `msg_to_dict` to gracefully handle exceptions, but it raised {exc}"


def test_setup_event_logger_specify_max_bytes(
mocker: MockerFixture, mock_global_event_manager
) -> None:
patched_file_handler = mocker.patch("dbt_common.events.logger.RotatingFileHandler")
args = Namespace(log_file_max_bytes=1234567)
flags.set_from_args(args, {})
setup_event_logger(flags.get_flags())
patched_file_handler.assert_called_once_with(
filename="logs/dbt.log", encoding="utf8", maxBytes=1234567, backupCount=5
)

0 comments on commit e08c448

Please sign in to comment.