-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add data source tests to CI for MSN and Yahoo (closes #59) #84
Merged
mrhappyasthma
merged 6 commits into
mrhappyasthma:master
from
kocielnik:59-test-data-sources
Jul 28, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
db6eb1c
Use a dataclass to represent company info.
kocielnik 32c0dee
Rename test modules for PyTest to see them.
kocielnik 1f9d413
Test data obtained from MSN Money.
kocielnik 289b164
Add a test for Yahoo! Finance.
kocielnik 19ab28e
Update CI recipe to only run `pytest`.
kocielnik 56fddf4
Prune logic not required to run the tests with PyTest.
kocielnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class CompanyInfo: | ||
ticker_symbol: str | ||
name: str | ||
description: str | ||
industry: str | ||
current_price: float | ||
average_volume: float | ||
market_cap: float | ||
shares_outstanding: int | ||
pe_high: float | ||
pe_low: float | ||
roic: float | ||
roic_averages: [float] | ||
equity: float | ||
equity_growth_rates: [float] | ||
free_cash_flow: float | ||
free_cash_flow_growth_rates: [float] | ||
revenue: float | ||
revenue_growth_rates: [float] | ||
eps: float | ||
eps_growth_rates: [float] | ||
debt_equity_ratio: float | ||
last_year_net_income: float | ||
total_debt: float |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from isthisstockgood.CompanyInfo import CompanyInfo | ||
from isthisstockgood.DataFetcher import DataFetcher | ||
|
||
|
||
def test_msn_money(): | ||
test_ticker = 'MSFT' | ||
test_name = 'Microsoft Corp' | ||
|
||
data = get_msn_money_data(test_ticker) | ||
|
||
assert data.ticker_symbol == test_ticker | ||
assert data.name == test_name | ||
assert data.description != '' | ||
assert data.industry != '' | ||
assert data.current_price > 0.0 | ||
assert data.average_volume > 0 | ||
assert data.market_cap > 0.0 | ||
assert data.shares_outstanding > 0 | ||
assert data.pe_high > 0.0 | ||
assert data.pe_low > 0.0 | ||
assert data.roic != [] | ||
assert data.roic_averages != [] | ||
assert data.equity != [] | ||
assert data.equity_growth_rates != [] | ||
assert data.free_cash_flow != [] | ||
assert data.free_cash_flow_growth_rates != [] | ||
assert data.revenue != [] | ||
assert data.revenue_growth_rates != [] | ||
assert data.eps != [] | ||
assert data.eps_growth_rates != [] | ||
assert data.debt_equity_ratio > 0.0 | ||
assert data.last_year_net_income > 0.0 | ||
assert data.total_debt >= 0.0 | ||
|
||
def test_yahoo(): | ||
test_ticker = 'MSFT' | ||
test_name = 'Microsoft Corp' | ||
|
||
data = get_yahoo_data(test_ticker) | ||
|
||
assert data.ticker_symbol == test_ticker | ||
assert float(data.five_year_growth_rate) > 0.0 | ||
|
||
def get_msn_money_data(ticker): | ||
data_fetcher = DataFetcher() | ||
data_fetcher.ticker_symbol = ticker | ||
|
||
# Make all network request asynchronously to build their portion of | ||
# the json results. | ||
data_fetcher.fetch_msn_money_data() | ||
|
||
# Wait for each RPC result before proceeding. | ||
for rpc in data_fetcher.rpcs: | ||
rpc.result() | ||
|
||
return CompanyInfo(**vars(data_fetcher.msn_money)) | ||
|
||
def get_yahoo_data(ticker): | ||
data_fetcher = DataFetcher() | ||
data_fetcher.ticker_symbol = ticker | ||
|
||
# Make all network request asynchronously to build their portion of | ||
# the json results. | ||
data_fetcher.fetch_yahoo_finance_analysis() | ||
|
||
# Wait for each RPC result before proceeding. | ||
for rpc in data_fetcher.rpcs: | ||
rpc.result() | ||
|
||
return data_fetcher.yahoo_finance_analysis |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this run all the tests still? Does the rename of the tests fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
run_all_tests.py
I see 18 tests being run:With PyTest after renaming, I see 22 tests run:
The tests I added for the API and the data sources are not UnitTest-formatted. That's probably the reason they don't get picked up by UnitTest. I see there's 4 of them:
In summary – yes, renaming was enough at this point.
For this to work, all code called by the tests had to be organized into a "package" (in this case – under the name
isthisstockgood
, installable withpip
andpoetry
). That reorganization was included in #78.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, with Python and PyTest testing becomes straightforward only after we make the code a package.
With that, in tests we call our logic just like we would use any other third-party package:
from isthisstockgood import foo
.Anything simpler than that (including
from .src import foo
) ends up getting treated differently by different Python versions and requires adding thesrc
directory to import paths, as you did intest_MSNMoney.py
:I kept using the above trick for a long time, until PIP started to support installing project dependencies from
pyproject.toml
and Poetry got more reliable. It seems finally we can skip that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied:
All 22 tests still run fine: