-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CM-8548_fix_error_message_for_invalid_timestamp
- Loading branch information
Showing
17 changed files
with
193 additions
and
99 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
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,56 @@ | ||
# -*- coding: utf-8 -*- | ||
# ******************************************************* | ||
# ____ _ _ | ||
# / ___|___ _ __ ___ ___| |_ _ __ ___ | | | ||
# | | / _ \| '_ ` _ \ / _ \ __| | '_ ` _ \| | | ||
# | |__| (_) | | | | | | __/ |_ _| | | | | | | | ||
# \____\___/|_| |_| |_|\___|\__(_)_| |_| |_|_| | ||
# | ||
# Sign up for free at https://www.comet.com | ||
# Copyright (C) 2015-2023 Comet ML INC | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this package. | ||
# ******************************************************* | ||
|
||
import functools | ||
import logging | ||
from typing import TYPE_CHECKING, Any, Callable | ||
|
||
from comet_llm import logging as comet_logging | ||
|
||
if TYPE_CHECKING: | ||
from comet_llm import summary | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def filter(allow_raising: bool, summary: "summary.Summary") -> Callable: | ||
def decorator(function: Callable) -> Callable: | ||
@functools.wraps(function) | ||
def wrapper(*args, **kwargs) -> Any: # type: ignore | ||
try: | ||
return function(*args, **kwargs) | ||
except Exception as exception: | ||
summary.increment_failed() | ||
|
||
if allow_raising: | ||
raise | ||
|
||
if getattr(exception, "log_message_once", False): | ||
comet_logging.log_once_at_level( | ||
LOGGER, | ||
logging.ERROR, | ||
str(exception), | ||
exc_info=True, | ||
extra={"show_traceback": True}, | ||
) | ||
else: | ||
LOGGER.error( | ||
str(exception), | ||
exc_info=True, | ||
extra={"show_traceback": True}, | ||
) | ||
|
||
return wrapper | ||
|
||
return decorator |
File renamed without changes.
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
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,63 @@ | ||
import logging | ||
|
||
import pytest | ||
from testix import * | ||
|
||
from comet_llm.exceptions import exceptions, filter_decorator | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_imports(patch_module): | ||
patch_module(filter_decorator, "LOGGER") | ||
patch_module(filter_decorator, "comet_logging") | ||
|
||
|
||
def test_filter__no_exceptions_raised__nothing_done(): | ||
NOT_USED = None | ||
@filter_decorator.filter(allow_raising=True, summary=NOT_USED) | ||
def f(): | ||
return 42 | ||
|
||
assert f() == 42 | ||
|
||
|
||
def test_filter__upraising_allowed__function_raised_exception__exception_raised_to_user(): | ||
@filter_decorator.filter(allow_raising=True, summary=Fake("summary")) | ||
def f(): | ||
raise Exception("some-message") | ||
|
||
with Scenario() as s: | ||
s.summary.increment_failed() | ||
with pytest.raises(Exception): | ||
f() | ||
|
||
|
||
def test_filter__upraising_not_allowed__function_raised_exception__exception_info_logged(): | ||
@filter_decorator.filter(allow_raising=False, summary=Fake("summary")) | ||
def f(): | ||
raise Exception("some-message") | ||
|
||
with Scenario() as s: | ||
s.summary.increment_failed() | ||
s.LOGGER.error( | ||
"some-message", | ||
exc_info=True, | ||
extra={"show_traceback": True} | ||
) | ||
assert f() is None | ||
|
||
|
||
def test_filter__upraising_not_allowed__function_raised_exception__exception_has_log_message_once_attribute_True__exception_info_logged_once(): | ||
@filter_decorator.filter(allow_raising=False, summary=Fake("summary")) | ||
def f(): | ||
raise exceptions.CometLLMException("some-message", log_message_once=True) | ||
with Scenario() as s: | ||
s.summary.increment_failed() | ||
s.comet_logging.log_once_at_level( | ||
filter_decorator.LOGGER, | ||
logging.ERROR, | ||
"some-message", | ||
exc_info=True, | ||
extra={"show_traceback": True} | ||
) | ||
assert f() is None |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.