# Path: zipline/finance/slippage.py
# class FixedSlippage(SlippageModel):
# 
#     def __init__(self, spread=0.0):
#         """
#         Use the fixed slippage model, which will just add/subtract
#         a specified spread spread/2 will be added on buys and subtracted
#         on sells per share
#         """
#         self.spread = spread
# 
#     def process_order(self, event, order):
#         return create_transaction(
#             event,
#             order,
#             event.price + (self.spread / 2.0 * order.direction),
#             order.amount,
#         )


from unittest import TestCase
from zipline.test_algorithms import (
    ExceptionAlgorithm,
    DivByZeroAlgorithm,
    SetPortfolioAlgorithm,
)
from zipline.finance.slippage import FixedSlippage
from zipline.transforms.utils import StatefulTransform
from zipline.utils.test_utils import (
    drain_zipline,
    setup_logger,
    teardown_logger,
    ExceptionSource,
    ExceptionTransform
)
import zipline.utils.simfactory as simfactory
import zipline.utils.factory as factory
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.






DEFAULT_TIMEOUT = 15  # seconds
EXTENDED_TIMEOUT = 90


class ExceptionTestCase(TestCase):

    def setUp(self):
        self.zipline_test_config = {
            'sid': 133,
            'slippage': FixedSlippage()
        }
        setup_logger(self)

    def tearDown(self):
        teardown_logger(self)

    def test_datasource_exception(self):
        self.zipline_test_config['trade_source'] = ExceptionSource()

# Path: zipline/finance/slippage.py
# class FixedSlippage(SlippageModel):
# 
#     def __init__(self, spread=0.0):
#         """
#         Use the fixed slippage model, which will just add/subtract
#         a specified spread spread/2 will be added on buys and subtracted
#         on sells per share
#         """
#         self.spread = spread
# 
#     def process_order(self, event, order):
#         return create_transaction(
#             event,
#             order,
#             event.price + (self.spread / 2.0 * order.direction),
#             order.amount,
#         )


# Path: tests/test_exception_handling.py
from unittest import TestCase
from zipline.test_algorithms import (
    ExceptionAlgorithm,
    DivByZeroAlgorithm,
    SetPortfolioAlgorithm,
)
from zipline.finance.slippage import FixedSlippage
from zipline.transforms.utils import StatefulTransform
from zipline.utils.test_utils import (
    drain_zipline,
    setup_logger,
    teardown_logger,
    ExceptionSource,
    ExceptionTransform
)
import zipline.utils.simfactory as simfactory
import zipline.utils.factory as factory

#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.






DEFAULT_TIMEOUT = 15  # seconds
EXTENDED_TIMEOUT = 90


class ExceptionTestCase(TestCase):

    def setUp(self):
        self.zipline_test_config = {
            'sid': 133,
            'slippage': FixedSlippage()
        }
        setup_logger(self)

    def tearDown(self):
        teardown_logger(self)

    def test_datasource_exception(self):
        self.zipline_test_config['trade_source'] = ExceptionSource()

        zipline = simfactory.create_test_zipline(