# Path: jasper/steps.py
# class Step(object):
#     """
#     The Step class is used as a wrapper around functions for testing behaviours.
#     """
#     def __init__(self, function, **kwargs):
#         """
#         Initialize a new Step object.
# 
#         :param function: The function this step will call when this step is run.
#         :param kwargs: Kwargs to call the given function with.
#         """
#         self.function = function
#         self.kwargs = kwargs
#         self.ran = False
#         self.passed = False
# 
#     async def run(self, context):
#         """
#         Run this step and record the results.
# 
#         :param context: A context object too pass into this steps function.
#         """
#         try:
#             if asyncio.iscoroutinefunction(self.function):
#                 await self.function(context, **self.kwargs)
#             else:
#                 self.function(context, **self.kwargs)
#         except Exception:
#             raise
#         else:
#             self.passed = True
#         finally:
#             self.ran = True
# 
# def step(func):
#     """
#     A decorator for wrapping a function into a Step object.
# 
#     :param func: The function to create a step out of.
#     :return: A function which when called will return a new instance of a Step object.
#     """
#     @wraps(func)
#     def wrapper(**kwargs):
#         return Step(func, **kwargs)
# 
#     return wrapper


from unittest import TestCase, mock
from jasper.steps import Step, step
import time
import asyncio
        mock_context = mock.MagicMock()
        some_step = Step(self.async_slow_function, sleep_time=0.1, fail=False)

        try:
            self.loop.run_until_complete(some_step.run(mock_context))
        except Exception:
            raise AssertionError
        else:
            self.assertTrue(some_step.ran)
            self.assertTrue(some_step.passed)
            self.assertTrue(self.async_slow_function_called)
            self.assertEqual(
                self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': False}
            )

    def test_failure_async_run(self):
        mock_context = mock.MagicMock()
        some_step = Step(self.async_slow_function, sleep_time=0.1, fail=True)

        with self.assertRaises(Exception):
            self.loop.run_until_complete(some_step.run(mock_context))

            self.assertTrue(some_step.ran)
            self.assertFalse(some_step.passed)
            self.assertTrue(self.async_slow_function_called)
            self.assertEqual(
                self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': True}
            )

    def test_step_decorator(self):

# Path: jasper/steps.py
# class Step(object):
#     """
#     The Step class is used as a wrapper around functions for testing behaviours.
#     """
#     def __init__(self, function, **kwargs):
#         """
#         Initialize a new Step object.
# 
#         :param function: The function this step will call when this step is run.
#         :param kwargs: Kwargs to call the given function with.
#         """
#         self.function = function
#         self.kwargs = kwargs
#         self.ran = False
#         self.passed = False
# 
#     async def run(self, context):
#         """
#         Run this step and record the results.
# 
#         :param context: A context object too pass into this steps function.
#         """
#         try:
#             if asyncio.iscoroutinefunction(self.function):
#                 await self.function(context, **self.kwargs)
#             else:
#                 self.function(context, **self.kwargs)
#         except Exception:
#             raise
#         else:
#             self.passed = True
#         finally:
#             self.ran = True
# 
# def step(func):
#     """
#     A decorator for wrapping a function into a Step object.
# 
#     :param func: The function to create a step out of.
#     :return: A function which when called will return a new instance of a Step object.
#     """
#     @wraps(func)
#     def wrapper(**kwargs):
#         return Step(func, **kwargs)
# 
#     return wrapper


# Path: tests/test_unit/test_step.py
from unittest import TestCase, mock
from jasper.steps import Step, step
import time
import asyncio

        mock_context = mock.MagicMock()
        some_step = Step(self.async_slow_function, sleep_time=0.1, fail=False)

        try:
            self.loop.run_until_complete(some_step.run(mock_context))
        except Exception:
            raise AssertionError
        else:
            self.assertTrue(some_step.ran)
            self.assertTrue(some_step.passed)
            self.assertTrue(self.async_slow_function_called)
            self.assertEqual(
                self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': False}
            )

    def test_failure_async_run(self):
        mock_context = mock.MagicMock()
        some_step = Step(self.async_slow_function, sleep_time=0.1, fail=True)

        with self.assertRaises(Exception):
            self.loop.run_until_complete(some_step.run(mock_context))

            self.assertTrue(some_step.ran)
            self.assertFalse(some_step.passed)
            self.assertTrue(self.async_slow_function_called)
            self.assertEqual(
                self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': True}
            )

    def test_step_decorator(self):

        some_step = step(self.slow_function)(sleep_time=0.1, fail=False)