55
66This file covers the server, not the client
77'''
8+
89import unittest
9- from tests import get_test_session
10+ # from tests import get_test_session
1011import calcbench as cb
1112import json
1213
1314HOST = 'localhost:444'
1415class Normalized (unittest .TestCase ):
1516 def setUp (self ):
16- #self.prod_session = cb.api_client._calcbench_session()
17- self .calcbench_session = get_test_session ()
17+ self .calcbench_session = get_test_session ()
1818
1919 @staticmethod
2020 def normalized_point_sort_key (data_point , period_type = 'calendar' ):
21- return tuple (data_point [key ] for key in ('ticker' , 'metric' , '{0}_year' .format (period_type ), '{0}_period' .format (period_type )))
21+ return tuple (data_point [key ] for key in ('ticker' ,
22+ 'metric' ,
23+ '{0}_year' .format (period_type ),
24+ '{0}_period' .format (period_type )))
2225
2326 @staticmethod
2427 def normalized_point_sort_key_fiscal (data_point ):
@@ -37,7 +40,9 @@ def testNormalizedDateRangeAnnualTrace(self):
3740 """ )
3841
3942
40- self .assertListEqual (sorted (data , key = self .normalized_point_sort_key ), sorted (expected_data , key = self .normalized_point_sort_key ), "Date Range Annual Failed" )
43+ self .assertListEqual (sorted (data , key = self .normalized_point_sort_key ),
44+ sorted (expected_data , key = self .normalized_point_sort_key ),
45+ "Date Range Annual Failed" )
4146
4247 def testNormalizedDatePeriodBackQuarterlyTrace (self ):
4348 payload = {"period_type" : "quarterly" , "periods_back" : 4 , "company_identifiers" : ["msft" ], "metrics" : ["revenue" , "taxespayable" ], 'include_trace' : True }
@@ -54,7 +59,8 @@ def testRatiosDateRangeQuarterly(self):
5459 expected_data = json .loads ('''
5560 [{"metric":"assetturn","ticker":"MSFT","value":0.75026900,"calendar_year":2008,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.72560400,"calendar_year":2009,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.64342600,"calendar_year":2010,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.60791900,"calendar_year":2011,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.54657300,"calendar_year":2012,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.50371800,"calendar_year":2013,"calendar_period":0},{"metric":"assetturn","ticker":"MSFT","value":0.53103100,"calendar_year":2014,"calendar_period":0}]
5661 ''' )
57- self .assertListEqual (sorted (expected_data , key = self .normalized_point_sort_key ), sorted (data , key = self .normalized_point_sort_key ))
62+ self .assertListEqual (sorted (expected_data , key = self .normalized_point_sort_key ),
63+ sorted (data , key = self .normalized_point_sort_key ))
5864
5965 def testClientCase (self ):
6066 payload = {"point_in_time" : False , "filing_accession_number" : "0000950103-15-008508" , "metrics" : [ "DiscountedFutureNetCashFlowsRelatingToProvedOilAndGasReservesFutureCashInflows" , "SalesReturnsAllowancesAndDiscounts" , "TreasuryStockShares" , "PrepaidRent" , "period_end" ,"ProvedReservesOil" ,"Revenue" ]}
@@ -77,6 +83,7 @@ def testSICCodes(self):
7783 'MarketCapAtEndOfPeriod' ,
7884 'Liabilities' ,
7985 'Revenue' ]
86+
8087 cb .normalized_dataframe (company_identifiers = peer_group_tickers ,
8188 metrics = z_score_metrics ,
8289 start_year = 2009 , start_period = 1 ,
@@ -90,6 +97,7 @@ def testXBRLTags(self):
9097 ''' )
9198 self .assertListEqual (sorted (data , key = Normalized .normalized_point_sort_key ),
9299 sorted (expected_data , key = Normalized .normalized_point_sort_key ), "XBRL Tags case failed" )
100+
93101if __name__ == "__main__" :
94102 #import sys;sys.argv = ['', 'Test.testName']
95103 unittest .main ()
0 commit comments