# Path: notifications_utils/statsd_decorators.py
# def statsd(namespace):
#     def time_function(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
#             start_time = time.monotonic()
#             try:
#                 res = func(*args, **kwargs)
#                 elapsed_time = time.monotonic() - start_time
#                 current_app.statsd_client.incr('{namespace}.{func}'.format(
#                     namespace=namespace, func=func.__name__)
#                 )
#                 current_app.statsd_client.timing('{namespace}.{func}'.format(
#                     namespace=namespace, func=func.__name__), elapsed_time
#                 )
# 
#             except Exception as e:
#                 raise e
#             else:
#                 current_app.logger.debug(
#                     "{namespace} call {func} took {time}".format(
#                         namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
#                     )
#                 )
#                 return res
#         wrapper.__wrapped__.__name__ = func.__name__
#         return wrapper
# 
#     return time_function


from unittest.mock import ANY, Mock
from notifications_utils.statsd_decorators import statsd



class AnyStringWith(str):
    def __eq__(self, other):
        return self in other


def test_should_call_statsd(app, mocker):
    app.config['NOTIFY_ENVIRONMENT'] = "test"
    app.config['NOTIFY_APP_NAME'] = "api"
    app.config['STATSD_HOST'] = "localhost"
    app.config['STATSD_PORT'] = "8000"
    app.config['STATSD_PREFIX'] = "prefix"
    app.statsd_client = Mock()

    mock_logger = mocker.patch.object(app.logger, 'debug')


# Path: notifications_utils/statsd_decorators.py
# def statsd(namespace):
#     def time_function(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
#             start_time = time.monotonic()
#             try:
#                 res = func(*args, **kwargs)
#                 elapsed_time = time.monotonic() - start_time
#                 current_app.statsd_client.incr('{namespace}.{func}'.format(
#                     namespace=namespace, func=func.__name__)
#                 )
#                 current_app.statsd_client.timing('{namespace}.{func}'.format(
#                     namespace=namespace, func=func.__name__), elapsed_time
#                 )
# 
#             except Exception as e:
#                 raise e
#             else:
#                 current_app.logger.debug(
#                     "{namespace} call {func} took {time}".format(
#                         namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
#                     )
#                 )
#                 return res
#         wrapper.__wrapped__.__name__ = func.__name__
#         return wrapper
# 
#     return time_function


# Path: tests/test_statsd_decorators.py
from unittest.mock import ANY, Mock
from notifications_utils.statsd_decorators import statsd




class AnyStringWith(str):
    def __eq__(self, other):
        return self in other


def test_should_call_statsd(app, mocker):
    app.config['NOTIFY_ENVIRONMENT'] = "test"
    app.config['NOTIFY_APP_NAME'] = "api"
    app.config['STATSD_HOST'] = "localhost"
    app.config['STATSD_PORT'] = "8000"
    app.config['STATSD_PREFIX'] = "prefix"
    app.statsd_client = Mock()

    mock_logger = mocker.patch.object(app.logger, 'debug')


    @statsd(namespace="test")