def test_read_position_available_balance(self): ws = self.get_worksheet('\\samples\\sample_holdings3 _ 16112016.xls') fields = read_holdings_fields(ws, 2) position = {} read_position_available_balance(ws, 11, fields, position) self.assertEqual(position['available_balance'], 3000000)
def test_grand_total_error(self): ws = self.get_worksheet( '\\samples\\sample_holdings_error12 _ 10072016.xls') fields = read_holdings_fields(ws, 2) self.assertTrue(is_grand_total(ws, 93)) with self.assertRaises(GrandTotalNotFound): x = read_grand_total(ws, 93)
def test_read_holdings2(self): ws = self.get_worksheet('\\samples\\sample_holdings4 _ 06072016.xls') fields = read_holdings_fields(ws, 2) port_values = {} try: x = read_holdings(ws, 3, port_values, fields) self.assertAlmostEqual(x, 85015806879.97) self.verify_holdings2(port_values['holdings']) except: self.fail('read_holdings() failed')
def test_grand_total2(self): ws = self.get_worksheet('\\samples\\sample_holdings6 _ 30032017.xlsx') fields = read_holdings_fields(ws, 2) self.assertTrue(is_grand_total(ws, 279)) try: x = read_grand_total(ws, 279) self.assertAlmostEqual(x, 459087628.2) except: self.fail('read grand total failed')
def test_grand_total(self): ws = self.get_worksheet('\\samples\\sample_holdings1 _ 10072016.xls') fields = read_holdings_fields(ws, 2) self.assertTrue(is_grand_total(ws, 93)) try: x = read_grand_total(ws, 93) self.assertEqual(x, 48415234) except: self.fail('read grand total failed')
def test_read_position(self): ws = self.get_worksheet('\\samples\\sample_holdings3 _ 16112016.xls') fields = read_holdings_fields(ws, 2) position = {} row = read_position(ws, 3, fields, position) self.assertEqual(row, 6) position = {} row = read_position(ws, 19, fields, position) self.assertEqual(row, 25) self.validate_position_fields(position)
def test_read_position_sub_total2(self): ws = self.get_worksheet('\\samples\\sample_holdings4 _ 06072016.xls') fields = read_holdings_fields(ws, 2) # read an All section position position = {} initialize_position(position) read_position_holding_detail(ws, 600, fields, position) read_position_sub_total(ws, 601, fields, position) self.assertEqual(len(position), 18) self.assertEqual(position['sub_total'], 2000000) self.assertEqual(position['market_price_currency'], 'USD') self.assertAlmostEqual(position['market_price'], 97.4179) self.assertAlmostEqual(position['market_value'], 1948358)
def test_read_position_sub_total(self): ws = self.get_worksheet('\\samples\\sample_holdings2 _ 16112016.xls') fields = read_holdings_fields(ws, 2) # read a normal position position = {} initialize_position(position) read_position_holding_detail(ws, 3, fields, position) read_position_sub_total(ws, 4, fields, position) self.assertEqual(len(position), 22) self.assertEqual(position['sub_total'], 7200000) self.assertEqual(position['market_price_currency'], 'USD') self.assertAlmostEqual(position['market_price'], 96.966) self.assertAlmostEqual(position['market_value'], 6981552)
def test_read_holdings_fields(self): """ Read the date """ ws = self.get_worksheet('\\samples\\sample_holdings2 _ 16112016.xls') row = 0 while not holdings_field_begins(ws, row): row = row + 1 fields = read_holdings_fields(ws, row) self.assertEqual(len(fields), 20) self.assertEqual(fields[0], 'generation_date') self.assertEqual(fields[10], 'holding_quantity') self.assertEqual(fields[19], 'equivalent_market_value')
def test_read_position2(self): # test the bond call ws = self.get_worksheet('\\samples\\sample_holdings5_call.xls') fields = read_holdings_fields(ws, 2) # read the call position position = {} row = read_position(ws, 12, fields, position) self.assertEqual(row, 15) self.assertEqual(position['settled_units'], 250000) self.assertEqual(position['pending_call'], 250000) self.assertEqual(position['sub_total'], 250000) self.assertEqual(position['pending_delivery'], 0) self.assertEqual(position['pending_receipt'], 0) self.assertEqual(position['available_balance'], 0)
def test_read_holdings(self): ws = self.get_worksheet('\\samples\\sample_holdings2 _ 16112016.xls') fields = read_holdings_fields(ws, 2) port_values = {} try: x = read_holdings(ws, 3, port_values, fields) self.assertTrue(x is None) # self.verify_holdings(port_values['holdings']) holdings = port_values['holdings'] self.assertEqual(len(holdings), 27) self.validate_position1(holdings[0]) self.validate_position2(holdings[17]) self.validate_position3(holdings[26]) except: self.fail('read_holdings() failed')
def test_read_position_holding_detail2(self): ws = self.get_worksheet('\\samples\\sample_holdings3 _ 16112016.xls') fields = read_holdings_fields(ws, 2) position = {} initialize_position(position) read_position_holding_detail(ws, 20, fields, position) read_position_holding_detail(ws, 21, fields, position) self.assertEqual(len(position), 14) self.assertEqual(position['generation_date'], datetime(2016, 7, 12)) self.assertEqual(position['statement_date'], datetime(2016, 7, 11)) self.assertEqual(position['security_id_type'], 'ISIN') self.assertEqual(position['security_id'], 'CNE1000021L3') self.assertEqual(position['settled_units'], 0) self.assertEqual(position['pending_delivery'], 222000)
def test_validate_position(self): ws = self.get_worksheet('\\samples\\sample_holdings3 _ 16112016.xls') fields = read_holdings_fields(ws, 2) position = {} row = read_position(ws, 3, fields, position) try: validate_position(position) except: self.fail('position validation failed') position = {} row = read_position(ws, 19, fields, position) try: validate_position(position) except: self.fail('position 2 validation failed')
def test_read_position_holding_detail(self): ws = self.get_worksheet('\\samples\\sample_holdings2 _ 16112016.xls') fields = read_holdings_fields(ws, 2) position = {} initialize_position(position) read_position_holding_detail(ws, 3, fields, position) # for fld in position: # print('{0}: {1}'.format(fld, position[fld])) # import sys # sys.exit(1) self.assertEqual(len(position), 14) self.assertEqual(position['generation_date'], datetime(2016, 11, 16)) self.assertEqual(position['statement_date'], datetime(2016, 11, 16)) self.assertEqual(position['security_id_type'], 'ISIN') self.assertEqual(position['security_id'], 'US09681MAC29') self.assertEqual(position['settled_units'], 7200000)