Exemplo n.º 1
0
 def test(self, get_contract, list_contracts):
     exchange = 'CME'
     fut_code = 'SP'
     contracts = ['SPZ2015','SPH2016']
     list_contracts.return_value = contracts 
     # Return the same dataset regardless of which contract is specified
     get_contract.return_value = self.dataset
     act = dataset_utils.get_futures_code_dataset(
             metadata=self.metadata,
             exchange=exchange,
             fut_code=fut_code)
     exp = pd.DataFrame()
     for contract in contracts:
         df = self.dataset.copy()
         df['Contract'] = contract
         exp = exp.append(df)
     pdt.assert_frame_equal(act, exp) 
     list_contracts.assert_called_with(self.metadata, fut_code)
     for contract in contracts:
         get_contract.assert_any_call(
           exchange=exchange,
           contract=contract,
           start=None,
           end=None,
           auth_token=None)
Exemplo n.º 2
0
 def test_start_date_filtering(self, get_contract, list_contracts):
     exchange = 'CME'
     fut_code = 'SP'
     start = '2016-01-05'
     old_contract = 'SPZ2015'
     new_contract = 'SPH2016'
     contracts = [old_contract, new_contract]
     list_contracts.return_value = contracts 
     # Return the same dataset regardless of which contract is specified
     get_contract.return_value = self.dataset
     _ = dataset_utils.get_futures_code_dataset(
           metadata=self.metadata,
           exchange=exchange,
           fut_code=fut_code,
           start=start)
     # Confirms we only asked for the "new" contract
     call = mock.call(
              exchange=exchange,
              contract=new_contract,
              start=start,
              end=None,
              auth_token=None)
     get_contract.assert_has_calls([call])