class TestCanReturnDict(unittest.TestCase): def setUp(self): self.yfget = YahooFinanceGet() self.yfget.load_summary_from_html('GOOG-Key-Statistics.html') def test_name_dict(self): d = self.yfget.to_dict() self.assertEqual(d['company'], 'Google Inc.') self.assertEqual(d['symbol'], 'GOOG') self.assertEqual(d['last_updated'], 'May 17, 4:00PM EDT') def test_valuation_measures(self): d = self.yfget.to_dict() self.assertEqual(d['valuation_measures']['market_cap'], 301640000000) self.assertEqual(d['valuation_measures']['enterprise_value'], 261140000000) self.assertEqual(d['valuation_measures']['trailing_pe'], 27.20) self.assertEqual(d['valuation_measures']['forward_pe'], 17.10) self.assertEqual(d['valuation_measures']['peg_ratio'], 1.32) self.assertEqual(d['valuation_measures']["price-to-sales_ttm"], 5.61) self.assertEqual(d['valuation_measures']["price-to-book_mrq"], 3.96) self.assertEqual(d['valuation_measures']["enterprise_value-to-revenue_ttm"], 4.88) self.assertEqual(d['valuation_measures']["enterprise_value-to-ebitda_ttm"], 15.53) def test_financial_highlights(self): d = self.yfget.to_dict() d = d['financial_highlights']
def setUp(self): import ast # Read our file with the dict stored as a text file with open("AAPL-dict.txt", "r") as f: dict_txt = f.read() # Convert our text to a python dict self.text_dict = ast.literal_eval(dict_txt) yfg = YahooFinanceGet() yfg.load_summary_from_html("AAPL-Key-Statistics.html") self.yfg_dict = yfg.to_dict(fmt="text") self.maxDiff = None
def test_compare_GOOG_numeric(self): import ast # Read our file with the dict stored as a text file with open("GOOG-dict-numeric.txt", "r") as f: dict_txt = f.read() # Convert our text to a python dict self.text_dict = ast.literal_eval(dict_txt) yfg = YahooFinanceGet() yfg.load_summary_from_html("GOOG-Key-Statistics.html") self.yfg_dict = yfg.to_dict() self.maxDiff = None self.assertDictEqual(self.text_dict, self.yfg_dict)
def setUp(self): self.yfget = YahooFinanceGet() self.yfget.load_summary_from_html('GOOG-Key-Statistics.html')
def test_loads_url_and_reads_name(self): yfget = YahooFinanceGet() yfget.load_summary_from_url(symbol='GOOG') self.assertEqual(yfget.get_company_name(), "Google Inc.")