Skip to content

Commit

Permalink
Added more tests for Ticker and missing dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-corneliusson committed Nov 6, 2022
1 parent 2be7187 commit 112fd5c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 4 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ multitasking>=0.0.7
lxml>=4.5.1
appdirs>=1.4.4
pytz>=2022.5
frozendict>=2.3.4
frozendict>=2.3.4
beautifulsoup4>=4.11.1
html5lib>=1.1
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
install_requires=['pandas>=1.1.0', 'numpy>=1.15',
'requests>=2.26', 'multitasking>=0.0.7',
'lxml>=4.5.1', 'appdirs>=1.4.4', 'pytz>=2022.5',
'frozendict>=2.3.4'],
'frozendict>=2.3.4',
'beautifulsoup4>=4.11.1', 'html5lib>=1.1'],
entry_points={
'console_scripts': [
'sample=sample:main',
Expand Down
106 changes: 104 additions & 2 deletions tests/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

if log_requests:
import logging

logging.basicConfig(level=logging.DEBUG)


class TestTicker(unittest.TestCase):
def setUp(self):
pass
Expand Down Expand Up @@ -70,6 +72,22 @@ def test_earnings_forecasts(self):
data_cached = self.ticker.earnings_forecasts
self.assertIs(data, data_cached, "data not cached")

def test_earnings_dates(self):
data = self.ticker.earnings_dates
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.earnings_dates
self.assertIs(data, data_cached, "data not cached")

def test_earnings_trend(self):
data = self.ticker.earnings_trend
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.earnings_trend
self.assertIs(data, data_cached, "data not cached")


class TestTickerHolders(unittest.TestCase):

Expand Down Expand Up @@ -104,7 +122,7 @@ def test_mutualfund_holders(self):
self.assertIs(data, data_cached, "data not cached")


class TestTickerBalanceSheet(unittest.TestCase):
class TestTickerMiscFinancials(unittest.TestCase):

def setUp(self):
self.ticker = yf.Ticker("GOOGL")
Expand All @@ -120,14 +138,98 @@ def test_balance_sheet(self):
data_cached = self.ticker.balance_sheet
self.assertIs(data, data_cached, "data not cached")

def test_quarterly_balance_sheet(self):
data = self.ticker.quarterly_balance_sheet
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.quarterly_balance_sheet
self.assertIs(data, data_cached, "data not cached")

def test_cashflow(self):
data = self.ticker.cashflow
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.cashflow
self.assertIs(data, data_cached, "data not cached")

def test_quarterly_cashflow(self):
data = self.ticker.quarterly_cashflow
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.quarterly_cashflow
self.assertIs(data, data_cached, "data not cached")

def test_sustainability(self):
data = self.ticker.sustainability
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.sustainability
self.assertIs(data, data_cached, "data not cached")

def test_recommendations(self):
data = self.ticker.recommendations
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.recommendations
self.assertIs(data, data_cached, "data not cached")

def test_recommendations_summary(self):
data = self.ticker.recommendations_summary
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.recommendations_summary
self.assertIs(data, data_cached, "data not cached")

def test_analyst_price_target(self):
data = self.ticker.analyst_price_target
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.analyst_price_target
self.assertIs(data, data_cached, "data not cached")

def test_revenue_forecasts(self):
data = self.ticker.revenue_forecasts
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.revenue_forecasts
self.assertIs(data, data_cached, "data not cached")

def test_calendar(self):
data = self.ticker.calendar
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

data_cached = self.ticker.calendar
self.assertIs(data, data_cached, "data not cached")

def test_isin(self):
data = self.ticker.isin
self.assertIsInstance(data, str, "data has wrong type")
self.assertEquals("ARDEUT116159", data, "data is empty")

data_cached = self.ticker.isin
self.assertIs(data, data_cached, "data not cached")

def test_options(self):
data = self.ticker.options
self.assertIsInstance(data, tuple, "data has wrong type")
self.assertTrue(len(data) > 1, "data is empty")


def suite():
suite = unittest.TestSuite()
suite.addTest(TestTicker('Test ticker'))
suite.addTest(TestTickerEarnings('Test earnings'))
suite.addTest(TestTickerHolders('Test holders'))
suite.addTest(TestTickerBalanceSheet('Test balance sheet'))
suite.addTest(TestTickerMiscFinancials('Test balance sheet'))
return suite


Expand Down

0 comments on commit 112fd5c

Please sign in to comment.