def test_parseStockAndTransactions(self): EAN1 = '0746817152012' EAN2 = '8014215020045' transDict = finsIn.parseTransactionCsv(TEST_TRANSACTION_FILE) res = {EAN1:structs.StockInfo(ean=EAN1,batchsize=24,brand='V05',quantity='150ml',margin=269,sellthroughPr=699, name='hair gel - extra strong',nSold=transDict[EAN1],profit=269*transDict[EAN1],wholesalePr=430), EAN2:structs.StockInfo(ean=EAN2,batchsize=20,brand='Alisea',quantity='50cl',margin=70,sellthroughPr=210, name='Naturale Italian mineral water',nSold=transDict[EAN2],profit=70*transDict[EAN2], wholesalePr=140) } self.assertDictEqual(res,finsIn.parseWestBun(TEST_STOCK_FILE,transDict)) return
def summarizeTransactions(stockfile,transfile): ''' Print the summary of transactions in the specified files. For file format specification see appropriate classes in finsburyInput @param[in] stockfile filename to be parsed by parseWestBun @param[in] transfile filename to be parsed by parseTransactionsCsv ''' transDict = finsIn.parseTransactionCsv(transfile) summary = finsIn.parseWestBun(stockfile,transactionDict=transDict) summaryList = structs.StockInfoList(summary.values()) print('Total profit:') print(formatCash(summaryList.getTotalProfit())) print('\nTop 3 products by profit:') top = summaryList.getTopNProfits(3) for i,s in enumerate(top): print('{}. {:<40} {:>12}'.format(i,s.name,formatCash(s.profit))) print('\nBottom 3 products by profit:') bot = summaryList.getBottomNProfits(3) for i,s in enumerate(bot): print('{}. {:<40} {:>12}'.format(i,s.name,formatCash(s.profit))) print('\nTop 3 products by quantity:') top = summaryList.getTopNQuantities(3) for i,s in enumerate(top): print('{}. {:<40} {:>12,d}'.format(i,s.name,s.nSold)) print('\nBottom 3 products by quantity:') bot = summaryList.getBottomNQuantities(3) for i,s in enumerate(bot): print('{}. {:<40} {:>12,d}'.format(i,s.name,s.nSold)) #Display the top 3 brands by quantity sold. print('\nTop 3 brands by quantity sold:') topB = summaryList.getTopAggregatedBrands(3) for i,s in enumerate(topB): print('{}. {:<40} {:>12,d}'.format(i,s[0],s[1])) print('\nBottom 3 brands by quantity sold:') bottomB = summaryList.getBottomAggregatedBrands(3) for i,s in enumerate(bottomB): print('{}. {:<40} {:>12,d}'.format(i,s[0],s[1])) return
def summarizeTransactions(stockfile, transfile): ''' Print the summary of transactions in the specified files. For file format specification see appropriate classes in finsburyInput @param[in] stockfile filename to be parsed by parseWestBun @param[in] transfile filename to be parsed by parseTransactionsCsv ''' transDict = finsIn.parseTransactionCsv(transfile) summary = finsIn.parseWestBun(stockfile, transactionDict=transDict) summaryList = structs.StockInfoList(summary.values()) print('Total profit:') print(formatCash(summaryList.getTotalProfit())) print('\nTop 3 products by profit:') top = summaryList.getTopNProfits(3) for i, s in enumerate(top): print('{}. {:<40} {:>12}'.format(i, s.name, formatCash(s.profit))) print('\nBottom 3 products by profit:') bot = summaryList.getBottomNProfits(3) for i, s in enumerate(bot): print('{}. {:<40} {:>12}'.format(i, s.name, formatCash(s.profit))) print('\nTop 3 products by quantity:') top = summaryList.getTopNQuantities(3) for i, s in enumerate(top): print('{}. {:<40} {:>12,d}'.format(i, s.name, s.nSold)) print('\nBottom 3 products by quantity:') bot = summaryList.getBottomNQuantities(3) for i, s in enumerate(bot): print('{}. {:<40} {:>12,d}'.format(i, s.name, s.nSold)) #Display the top 3 brands by quantity sold. print('\nTop 3 brands by quantity sold:') topB = summaryList.getTopAggregatedBrands(3) for i, s in enumerate(topB): print('{}. {:<40} {:>12,d}'.format(i, s[0], s[1])) print('\nBottom 3 brands by quantity sold:') bottomB = summaryList.getBottomAggregatedBrands(3) for i, s in enumerate(bottomB): print('{}. {:<40} {:>12,d}'.format(i, s[0], s[1])) return
def test_fromToDate(self): #now endDate fromD = datetime(day=25,month=10,year=2011,hour=13,minute=42) toD = datetime(day=25,month=10,year=2011,hour=13,minute=43) self.assertDictEqual(finsIn.parseTransactionCsv(TEST_TRANSACTION_FILE,fromDate=fromD,toDate=toD),{EAN1:-3})
def test_fromDate(self): #now check date constraints work: first just startDate fromD = datetime(day=25,month=10,year=2011,hour=13,minute=43) self.assertDictEqual(finsIn.parseTransactionCsv(TEST_TRANSACTION_FILE,fromDate=fromD),{EAN2:8})
def test_parseCsv(self): self.assertRaises(IOError,finsIn.parseTransactionCsv,'/pathToNon-Existent.file') transDict = finsIn.parseTransactionCsv(TEST_TRANSACTION_FILE) self.assertDictEqual(transDict,{EAN1: 1, EAN2: 8})