Repository: quantopian/zipline
File: tests/test_algorithm.py (Python)

Code before:
    ])
    def test_invalid_capital_base(self, cap_base, name):
        """
        Test that the appropriate error is being raised and orders aren't
        filled for algos with capital base <= 0
        """
        algo_text = """
def initialize(context):
    pass

def handle_data(context, data):
    order(sid(24), 1000)
        """
        sim_params = SimulationParameters(
            start_session=pd.Timestamp("2006-01-03", tz='UTC'),
            end_session=pd.Timestamp("2006-01-06", tz='UTC'),
            capital_base=cap_base,
            data_frequency="minute",
            trading_calendar=self.trading_calendar
        )

        with self.assertRaises(ZeroCapitalError) as exc:
            # make_algo will trace to TradingAlgorithm,
            # where the exception will be raised
            algo = self.make_algo(script=algo_text, sim_params=sim_params)
            algo.run()
        # Make sure the correct error was raised
        error = exc.exception
        self.assertEqual(str(error),
                         'initial capital base must be greater than zero')

    def test_get_environment(self):
        expected_env = {
            'arena': 'backtest',
            'data_frequency': 'minute',
            'start': pd.Timestamp('2006-01-03 14:31:00+0000', tz='utc'),
            'end': pd.Timestamp('2006-01-04 21:00:00+0000', tz='utc'),
            'capital_base': 100000.0,
            'platform': 'zipline'
        }

        def initialize(algo):
            self.assertEqual('zipline', algo.get_environment())
            self.assertEqual(expected_env, algo.get_environment('*'))

        def handle_data(algo, data):
            pass

        self.run_algorithm(initialize=initialize, handle_data=handle_data)

    def test_get_open_orders(self):

Review comment (suggestion):
So since we're going to hit your error in the line above, this line is never being run, and probably shouldn't be included in the test. If the idea is to make flake8 not yell at you about unused assignment, you can just not assign for the `make_algo` call above.

Code after:
    ])
    def test_invalid_capital_base(self, cap_base, name):
        """
        Test that the appropriate error is being raised and orders aren't
        filled for algos with capital base <= 0
        """
        algo_text = """
def initialize(context):
    pass

def handle_data(context, data):
    order(sid(24), 1000)
        """
        sim_params = SimulationParameters(
            start_session=pd.Timestamp("2006-01-03", tz='UTC'),
            end_session=pd.Timestamp("2006-01-06", tz='UTC'),
            capital_base=cap_base,
            data_frequency="minute",
            trading_calendar=self.trading_calendar
        )

        with self.assertRaises(ZeroCapitalError) as exc:
            # make_algo will trace to TradingAlgorithm,
            # where the exception will be raised
            self.make_algo(script=algo_text, sim_params=sim_params)
        # Make sure the correct error was raised
        error = exc.exception
        self.assertEqual(str(error),
                         'initial capital base must be greater than zero')

    def test_get_environment(self):
        expected_env = {
            'arena': 'backtest',
            'data_frequency': 'minute',
            'start': pd.Timestamp('2006-01-03 14:31:00+0000', tz='utc'),
            'end': pd.Timestamp('2006-01-04 21:00:00+0000', tz='utc'),
            'capital_base': 100000.0,
            'platform': 'zipline'
        }

        def initialize(algo):
            self.assertEqual('zipline', algo.get_environment())
            self.assertEqual(expected_env, algo.get_environment('*'))

        def handle_data(algo, data):
            pass

        self.run_algorithm(initialize=initialize, handle_data=handle_data)

    def test_get_open_orders(self):
        def initialize(algo):