def test_get_date_from_file(self): cash_file = get_current_path() + '\\samples\\Cash _ 15112016.xls' holdings_file = get_current_path( ) + '\\samples\\Holding _ 12072016.xls' port_values = {} read_cash_bochk(cash_file, port_values) read_holdings_bochk(holdings_file, port_values) self.assertEqual(datetime(2016, 11, 15), port_values['cash_date']) self.assertEqual(datetime(2016, 7, 12), port_values['holding_date'])
def test_output_error(self): filename = get_current_path( ) + '\\samples\\sample_holdings_error11 _ 16112016.xls' port_values = {} read_holdings_bochk(filename, port_values) directory = get_current_path() + '\\samples' with self.assertRaises(InvestmentIdNotFound): write_holding_csv(port_values, directory, \ get_prefix_from_dir(get_input_directory()))
def test_cash_error4(self): holdings_file = get_current_path( ) + '\\samples\\sample_holdings2 _ 16112016.xls' cash_file = get_current_path( ) + '\\samples\\cash_error4 _ 16112016.xls' port_values = {} directory = get_current_path() + '\\samples' read_cash_bochk(cash_file, port_values) read_holdings_bochk(holdings_file, port_values) with self.assertRaises(InvalidCashAccountName): write_csv(port_values, directory)
def test_read_cash_bochk2(self): filename = get_current_path() + '\\samples\\sample_cash2 _ 16112016.xls' port_values = {} read_cash_bochk(filename, port_values) cash_entries = port_values['cash'] cash_transactions = port_values['cash_transactions'] self.verify_cash2(cash_entries, cash_transactions)
def test_read_holdings_bochk3(self): filename = get_current_path( ) + '\\samples\\short_position _ 03032017.xlsx' port_values = {} read_holdings_bochk(filename, port_values) self.assertEqual(port_values['holdings'][0]['sub_total'], -200000) self.assertEqual(port_values['holdings'][1]['sub_total'], -1600000)
def test_read_cash_bochk4(self): # the in house fund, it has cash consoliation (two HKD accounts, savings # and current account) filename = get_current_path() + '\\samples\\Cash Stt _30042018.xlsx' port_values = {} read_cash_bochk(filename, port_values) consolidate_cash(port_values) self.verify_cash4(port_values['cash'], port_values['cash_transactions'])
def test_read_holdings_bochk4(self): # the in house fund holdings filename = get_current_path() + '\\samples\\Holding _ 31082017.xls' port_values = {} read_holdings_bochk(filename, port_values) self.assertEqual(port_values['holdings'][0]['sub_total'], 1000000) # the last position self.assertEqual(port_values['holdings'][10]['security_id'], 'XS1450332256') self.assertEqual(port_values['holdings'][10]['sub_total'], 5000000)
def test_err9(self): filename = get_current_path( ) + '\\samples\\sample_holdings_error9 _ 16112016.xls' port_values = {} with self.assertRaises(InconsistentPositionFieldsTotal): read_holdings_bochk(filename, port_values)
def test_err6(self): filename = get_current_path( ) + '\\samples\\sample_holdings_error6 _ 16112016.xls' port_values = {} with self.assertRaises(TypeError): read_holdings_bochk(filename, port_values)
def test_err(self): filename = get_current_path( ) + '\\samples\\sample_holdings_error _ 16112016.xls' port_values = {} with self.assertRaises(InvalidFieldName): read_holdings_bochk(filename, port_values)
def get_worksheet(self, filename): filename = get_current_path() + filename wb = open_workbook(filename=filename) ws = wb.sheet_by_index(0) return ws
def test_cash_error3(self): filename = get_current_path() + '\\samples\\cash_error3 _ 16112016.xls' port_values = {} with self.assertRaises(InvalidCashTransaction): read_cash_bochk(filename, port_values)
def test_read_holdings_bochk2(self): filename = get_current_path( ) + '\\samples\\sample_holdings4 _ 06072016.xls' port_values = {} read_holdings_bochk(filename, port_values) self.verify_holdings2(port_values['holdings'])