'Test that the new and old data APIs hit the same code paths.
We want to ensure that the old data API(data[sid(N)].field and
similar)  and the new data API(data.current(sid(N), field) and
similar) hit the same code paths on the DataPortal.'

def test_old_new_data_api_paths(self):

    test_start_minute = self.trading_calendar.minutes_for_session(self.sim_params.sessions[0])[1]
    test_end_minute = self.trading_calendar.minutes_for_session(self.sim_params.sessions[0])[(-1)]
    bar_data = self.create_bardata((lambda : test_end_minute))
    ohlcvp_fields = ['open', 'high', 'lowclose', 'volume', 'price']
    spot_value_meth = 'zipline.data.data_portal.DataPortal.get_spot_value'
    def assert_get_spot_value_called(fun, field):
        '\n                                                Assert    that    get_spot_value    was    called    during    the    execution    of    fun.\n\n                                                Takes    in    a    function    fun    and    a    string    field.\n                                                '
        with patch(spot_value_meth) as gsv:
            fun()
            gsv.assert_called_with(self.asset1, field, test_end_minute, 'minute')
    for field in ohlcvp_fields:
        assert_get_spot_value_called((lambda : getattr(bar_data[self.asset1], field)), field)
        assert_get_spot_value_called((lambda : bar_data.current(self.asset1, field)), field)
    history_meth = 'zipline.data.data_portal.DataPortal.get_history_window'
    def assert_get_history_window_called(fun, is_legacy):
        '\n                                                Assert    that    get_history_window    was    called    during    fun().\n\n                                                Takes    in    a    function    fun    and    a    boolean    is_legacy.\n                                                '
        with patch(history_meth) as ghw:
            fun()
            if is_legacy:
                ghw.assert_called_with([self.asset1, self.asset2, self.asset3], test_end_minute, 5, '1m', 'volume', 'minute', True)
            else:
                ghw.assert_called_with([self.asset1, self.asset2, self.asset3], test_end_minute, 5, '1m', 'volume', 'minute')
    test_sim_params = SimulationParameters(start_session=test_start_minute, end_session=test_end_minute, data_frequency='minute', trading_calendar=self.trading_calendar)
    history_algorithm = self.create_algo(history_algo, sim_params=test_sim_params)
    assert_get_history_window_called((lambda : history_algorithm.run(self.data_portal)), is_legacy=True)
    assert_get_history_window_called((lambda : bar_data.history([self.asset1, self.asset2, self.asset3], 'volume', 5, '1m')), is_legacy=False)
