# Path: botoflow/core/async_event_loop.py
# class AsyncEventLoop(object):
#     """
#     TODO Document
#     """
# 
#     def __init__(self):
#         self.tasks = deque()
#         self.root_context = AsyncRootTaskContext(weakref.proxy(self))
# 
#     def __enter__(self):
#         set_async_context(self.root_context)
#         return self.root_context
# 
#     # noinspection PyUnusedLocal
#     def __exit__(self, exc_type, err, tb):
#         set_async_context(None)
# 
#     def execute(self, task):
#         if DEBUG:
#             log.debug("Adding task: %s", task)
#         self.tasks.append(task)
# 
#     def execute_now(self, task):
#         if DEBUG:
#             log.debug("Prepending task: %s", task)
#         self.tasks.appendleft(task)
# 
#     def execute_all_tasks(self):
#         while self.execute_queued_task():
#             pass
# 
#     def execute_queued_task(self):
#         if DEBUG:
#             log.debug("Task queue: %s", self.tasks)
#         try:
#             task = self.tasks.popleft()
#             if not task.done:
#                 if DEBUG:
#                     log.debug("Running task: %s", task)
#                 task.run()
#         except IndexError:  # no more tasks
#             return False
#         return True
# 
# Path: botoflow/core/decorators.py
# DEBUG = False
# def _task(daemon=False):
#     def __task(func):
#         def inner_task(*args, **kwargs):
#         def _do_except_wrapper(except_func):
#         def _do_finally_wrapper(finally_func):
#     def __init__(self, func, daemon):
#     def _progress_function(self, future, *args, **kwargs):
#     def _progress_except(self, future, except_func, err):
#     def __get__(self, instance, cls):
#     def __call__(self, *args, **kwargs):
# def _coroutine(daemon=False):
#     def __coroutine(func=None):
#         def ___coroutine(func):
# class CoroutineDecorator(object):
# 
# Path: botoflow/core/async_traceback.py
# def format_exc(limit=None, exception=None, tb_list=None):
#     """
#     This is like print_exc(limit) but returns a string instead of printing to a
#     file.
#     """
#     result = ["Traceback (most recent call last):\n"]
#     if exception is None:
#         exception = get_context_with_traceback(get_async_context()).exception
# 
#     if tb_list is None:
#         tb_list = extract_tb(limit)
# 
#     if tb_list:
#         result.extend(traceback.format_list(tb_list))
#         result.extend(traceback.format_exception_only(exception.__class__,
#                                                       exception))
#         return result
#     else:
#         return None
# 
# def print_exc(limit=None, file=None):
#     """
#     Print exception information and up to limit stack trace entries to file
#     """
#     if file is None:
#         file = sys.stderr
# 
#     formatted_exc = format_exc(limit)
#     if formatted_exc is not None:
#         for line in formatted_exc:
#             file.write(line)
# 
# Path: botoflow/logging_filters.py
# class BotoflowFilter(logging.Filter):
#     """You can use this filter with Python's :py:mod:`logging` module to filter out
#     botoflow logs that are being replayed by the decider.
# 
#     For example::
# 
#         import logging
#         from botoflow.logging_filters import BotoflowFilter
# 
#         logging.basicConfig(level=logging.DEBUG,
#             format='%(filename)s:%(lineno)d (%(funcName)s) - %(message)s')
# 
#         logging.getLogger('botoflow').addFilter(BotoflowFilter())
# 
#     """
# 
#     def __init__(self, name='', filter_replaying=True):
#         super(BotoflowFilter, self).__init__(name)
#         self._filter_replaying = filter_replaying
# 
#     def filter(self, record):
#         try:
#             if self._filter_replaying and botoflow.get_context().replaying:
#                 return 0
#         except AttributeError:
#             pass
#         return 1


import pytest
import unittest
import logging
import pytest
import sys
import six
from botoflow.core.async_event_loop import AsyncEventLoop
from botoflow.core.decorators import coroutine, task
from botoflow.core.async_traceback import format_exc, print_exc
from botoflow.logging_filters import BotoflowFilter



logging.basicConfig(level=logging.DEBUG,
                    format='%(filename)s:%(lineno)d (%(funcName)s) - %(message)s')
logging.getLogger('botoflow').addFilter(BotoflowFilter())

pytestmark = pytest.mark.usefixtures('core_debug')


class TestTraceback(unittest.TestCase):

    def setUp(self):
        self.tb_str = None

    @pytest.mark.xfail(sys.version_info >= (3,5,0),
                       reason="Some kind of brokennes on 3.5.0 specifically")
    def test_format(self):

# Path: botoflow/core/async_event_loop.py
# class AsyncEventLoop(object):
#     """
#     TODO Document
#     """
# 
#     def __init__(self):
#         self.tasks = deque()
#         self.root_context = AsyncRootTaskContext(weakref.proxy(self))
# 
#     def __enter__(self):
#         set_async_context(self.root_context)
#         return self.root_context
# 
#     # noinspection PyUnusedLocal
#     def __exit__(self, exc_type, err, tb):
#         set_async_context(None)
# 
#     def execute(self, task):
#         if DEBUG:
#             log.debug("Adding task: %s", task)
#         self.tasks.append(task)
# 
#     def execute_now(self, task):
#         if DEBUG:
#             log.debug("Prepending task: %s", task)
#         self.tasks.appendleft(task)
# 
#     def execute_all_tasks(self):
#         while self.execute_queued_task():
#             pass
# 
#     def execute_queued_task(self):
#         if DEBUG:
#             log.debug("Task queue: %s", self.tasks)
#         try:
#             task = self.tasks.popleft()
#             if not task.done:
#                 if DEBUG:
#                     log.debug("Running task: %s", task)
#                 task.run()
#         except IndexError:  # no more tasks
#             return False
#         return True
# 
# Path: botoflow/core/decorators.py
# DEBUG = False
# def _task(daemon=False):
#     def __task(func):
#         def inner_task(*args, **kwargs):
#         def _do_except_wrapper(except_func):
#         def _do_finally_wrapper(finally_func):
#     def __init__(self, func, daemon):
#     def _progress_function(self, future, *args, **kwargs):
#     def _progress_except(self, future, except_func, err):
#     def __get__(self, instance, cls):
#     def __call__(self, *args, **kwargs):
# def _coroutine(daemon=False):
#     def __coroutine(func=None):
#         def ___coroutine(func):
# class CoroutineDecorator(object):
# 
# Path: botoflow/core/async_traceback.py
# def format_exc(limit=None, exception=None, tb_list=None):
#     """
#     This is like print_exc(limit) but returns a string instead of printing to a
#     file.
#     """
#     result = ["Traceback (most recent call last):\n"]
#     if exception is None:
#         exception = get_context_with_traceback(get_async_context()).exception
# 
#     if tb_list is None:
#         tb_list = extract_tb(limit)
# 
#     if tb_list:
#         result.extend(traceback.format_list(tb_list))
#         result.extend(traceback.format_exception_only(exception.__class__,
#                                                       exception))
#         return result
#     else:
#         return None
# 
# def print_exc(limit=None, file=None):
#     """
#     Print exception information and up to limit stack trace entries to file
#     """
#     if file is None:
#         file = sys.stderr
# 
#     formatted_exc = format_exc(limit)
#     if formatted_exc is not None:
#         for line in formatted_exc:
#             file.write(line)
# 
# Path: botoflow/logging_filters.py
# class BotoflowFilter(logging.Filter):
#     """You can use this filter with Python's :py:mod:`logging` module to filter out
#     botoflow logs that are being replayed by the decider.
# 
#     For example::
# 
#         import logging
#         from botoflow.logging_filters import BotoflowFilter
# 
#         logging.basicConfig(level=logging.DEBUG,
#             format='%(filename)s:%(lineno)d (%(funcName)s) - %(message)s')
# 
#         logging.getLogger('botoflow').addFilter(BotoflowFilter())
# 
#     """
# 
#     def __init__(self, name='', filter_replaying=True):
#         super(BotoflowFilter, self).__init__(name)
#         self._filter_replaying = filter_replaying
# 
#     def filter(self, record):
#         try:
#             if self._filter_replaying and botoflow.get_context().replaying:
#                 return 0
#         except AttributeError:
#             pass
#         return 1


# Path: test/unit/core/test_async_traceback.py
import pytest
import unittest
import logging
import pytest
import sys
import six
from botoflow.core.async_event_loop import AsyncEventLoop
from botoflow.core.decorators import coroutine, task
from botoflow.core.async_traceback import format_exc, print_exc
from botoflow.logging_filters import BotoflowFilter




logging.basicConfig(level=logging.DEBUG,
                    format='%(filename)s:%(lineno)d (%(funcName)s) - %(message)s')
logging.getLogger('botoflow').addFilter(BotoflowFilter())

pytestmark = pytest.mark.usefixtures('core_debug')


class TestTraceback(unittest.TestCase):

    def setUp(self):
        self.tb_str = None

    @pytest.mark.xfail(sys.version_info >= (3,5,0),
                       reason="Some kind of brokennes on 3.5.0 specifically")
    def test_format(self):

        @task