Skip to content

Commit

Permalink
test: Added more raw test data, statistics tests, and summary tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgnsrekt committed Oct 10, 2020
1 parent e08e8cc commit 196d15b
Show file tree
Hide file tree
Showing 36 changed files with 1,350 additions and 9 deletions.
57 changes: 55 additions & 2 deletions tests/common_fixtures.py
@@ -1,3 +1,4 @@
from itertools import permutations
from pathlib import Path

import pytest
Expand All @@ -14,13 +15,65 @@ def get_data(path: Path) -> HTML:
return HTML(html=file.read())


@pytest.fixture(params=["aapl"])
@pytest.fixture(
params=[
"aapl",
"amd",
"amzn",
"dia",
"exfo",
"fcel",
"gpro",
"lite",
"msft",
"pavm",
"tsla",
"twtr",
]
)
def summary_page_data_fixture(request):
symbol = request.param
test_response_path = TEST_DIRECTORY / "data" / f"{symbol}_summary_page_raw.html"
test_response_path = TEST_DIRECTORY / "data" / "summary" / f"{symbol}_summary_page_raw.html"
return symbol, get_data(test_response_path)


symbols = [
"aapl",
"amd",
"amzn",
"dia",
"exfo",
"fcel",
"twtr",
]
input = list(permutations(symbols, r=2))
output = [sorted(c) for c in input]


@pytest.fixture(params=list(zip(input, output)))
def multiple_summary_page_data_fixture(request):
from pprint import pprint

input, output = request.param
symbol_one, symbol_two = input

test_response_path_one = (
TEST_DIRECTORY / "data" / "summary" / f"{symbol_one}_summary_page_raw.html"
)
test_response_path_two = (
TEST_DIRECTORY / "data" / "summary" / f"{symbol_two}_summary_page_raw.html"
)
output = [symbol.upper() for symbol in output]
return (
symbol_one,
symbol_two,
get_data(test_response_path_one),
get_data(test_response_path_two),
output,
)


#
@pytest.fixture
def option_expiration_data_fixture():
test_response_path = TEST_DIRECTORY / "data" / "spy_option_expiration_raw.html"
Expand Down
File renamed without changes.
105 changes: 105 additions & 0 deletions tests/data/summary/amd_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/amzn_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/dia_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/exfo_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/fcel_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/gpro_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/lite_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/msft_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/pavm_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/tsla_summary_page_raw.html

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions tests/data/summary/twtr_summary_page_raw.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_amd_.yml
@@ -0,0 +1,2 @@
'{"name": "Advanced Micro Devices, Inc.", "close": 83.1, "change": -3.41, "percent_change":
-3.94}'
2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_amzn_.yml
@@ -0,0 +1,2 @@
'{"name": "Amazon.com, Inc.", "close": 3286.65, "change": 96.1, "percent_change":
3.01}'
2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_dia_.yml
@@ -0,0 +1,2 @@
'{"name": "SPDR Dow Jones Industrial Average ETF Trust", "close": 285.83, "change":
1.54, "percent_change": 0.54}'
1 change: 1 addition & 0 deletions tests/test_quote/test_parse_quote_header_info_exfo_.yml
@@ -0,0 +1 @@
'{"name": "EXFO Inc.", "close": 3.07, "change": 0.08, "percent_change": 2.68}'
2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_fcel_.yml
@@ -0,0 +1,2 @@
'{"name": "FuelCell Energy, Inc.", "close": 2.62, "change": 0.24, "percent_change":
10.08}'
1 change: 1 addition & 0 deletions tests/test_quote/test_parse_quote_header_info_gpro_.yml
@@ -0,0 +1 @@
'{"name": "GoPro, Inc.", "close": 6.18, "change": -0.03, "percent_change": -0.48}'
2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_lite_.yml
@@ -0,0 +1,2 @@
'{"name": "Lumentum Holdings Inc.", "close": 82.74, "change": 0.69, "percent_change":
0.84}'
2 changes: 2 additions & 0 deletions tests/test_quote/test_parse_quote_header_info_msft_.yml
@@ -0,0 +1,2 @@
'{"name": "Microsoft Corporation", "close": 215.81, "change": 5.23, "percent_change":
2.48}'
1 change: 1 addition & 0 deletions tests/test_quote/test_parse_quote_header_info_pavm_.yml
@@ -0,0 +1 @@
'{"name": "PAVmed Inc.", "close": 2.04, "change": 0.12, "percent_change": 6.25}'
1 change: 1 addition & 0 deletions tests/test_quote/test_parse_quote_header_info_tsla_.yml
@@ -0,0 +1 @@
'{"name": "Tesla, Inc.", "close": 433.95, "change": 8.03, "percent_change": 1.89}'
1 change: 1 addition & 0 deletions tests/test_quote/test_parse_quote_header_info_twtr_.yml
@@ -0,0 +1 @@
'{"name": "Twitter, Inc.", "close": 45.9, "change": -0.11, "percent_change": -0.24}'
33 changes: 26 additions & 7 deletions tests/test_summary.py
Expand Up @@ -3,23 +3,42 @@

from collections import ChainMap

from yfs.summary import parse_summary_table, SummaryPage
from yfs.summary import parse_summary_table, SummaryPage, SummaryPageGroup
from yfs.quote import parse_quote_header_info

from .common_fixtures import summary_page_data_fixture
from .common_fixtures import summary_page_data_fixture, multiple_summary_page_data_fixture


def test_parse_summary_table(data_regression, summary_page_data_fixture):

symbol, data = summary_page_data_fixture

def create_summary_page_object(symbol, data):
summary = parse_summary_table(data)
quote = parse_quote_header_info(data)

data = ChainMap(quote.dict(), summary)
data["symbol"] = symbol
data["quote"] = quote

result = SummaryPage(**data)
return SummaryPage(**data)


def test_parse_summary_table(data_regression, summary_page_data_fixture):

symbol, data = summary_page_data_fixture

result = create_summary_page_object(symbol, data)

assert result.high > result.low

data_regression.check(result.json())


def test_sorting_summary_pages(multiple_summary_page_data_fixture):
symbol_one, symbol_two, data_one, data_two, target = multiple_summary_page_data_fixture
page_one = create_summary_page_object(symbol_one, data_one)
page_two = create_summary_page_object(symbol_two, data_two)

summary_page_group = SummaryPageGroup()

summary_page_group.append(page_one)
summary_page_group.append(page_two)
summary_page_group.sort()
assert summary_page_group.symbols == target
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_amd_.yml
@@ -0,0 +1,9 @@
'{"symbol": "AMD", "name": "Advanced Micro Devices, Inc.", "quote": {"name": "Advanced
Micro Devices, Inc.", "close": 83.1, "change": -3.41, "percent_change": -3.94},
"open": 84.74, "high": 85.75, "low": 82.35, "close": 83.1, "change": -3.41, "percent_change":
-3.94, "previous_close": 86.51, "bid_price": 83.05, "bid_size": 1100, "ask_price":
83.09, "ask_size": 1000, "fifty_two_week_low": 28.81, "fifty_two_week_high": 94.28,
"volume": 79384511, "average_volume": 62905489, "market_cap": 97564000000, "beta_five_year_monthly":
2.29, "pe_ratio_ttm": 161.67, "eps_ttm": 0.51, "earnings_date": "2020-10-27", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": "1995-04-27",
"one_year_target_est": 79.08}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_amzn_.yml
@@ -0,0 +1,9 @@
'{"symbol": "AMZN", "name": "Amazon.com, Inc.", "quote": {"name": "Amazon.com, Inc.",
"close": 3286.65, "change": 96.1, "percent_change": 3.01}, "open": 3210.0, "high":
3288.7, "low": 3197.88, "close": 3286.65, "change": 96.1, "percent_change": 3.01,
"previous_close": 3190.55, "bid_price": 3296.26, "bid_size": 900, "ask_price": 3297.5,
"ask_size": 1200, "fifty_two_week_low": 1626.03, "fifty_two_week_high": 3552.25,
"volume": 4721528, "average_volume": 4981015, "market_cap": 1646000000000, "beta_five_year_monthly":
1.35, "pe_ratio_ttm": 126.23, "eps_ttm": 26.04, "earnings_date": "2020-10-29", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
3726.61}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_dia_.yml
@@ -0,0 +1,9 @@
'{"symbol": "DIA", "name": "SPDR Dow Jones Industrial Average ETF Trust", "quote":
{"name": "SPDR Dow Jones Industrial Average ETF Trust", "close": 285.83, "change":
1.54, "percent_change": 0.54}, "open": 285.61, "high": 286.8, "low": 284.43, "close":
285.83, "change": 1.54, "percent_change": 0.54, "previous_close": 284.29, "bid_price":
286.14, "bid_size": 900, "ask_price": 286.48, "ask_size": 900, "fifty_two_week_low":
182.1, "fifty_two_week_high": 295.87, "volume": 2549141, "average_volume": 3226983,
"market_cap": null, "beta_five_year_monthly": 0.97, "pe_ratio_ttm": null, "eps_ttm":
null, "earnings_date": null, "forward_dividend_yield": null, "forward_dividend_yield_percentage":
null, "exdividend_date": null, "one_year_target_est": null}'
8 changes: 8 additions & 0 deletions tests/test_summary/test_parse_summary_table_exfo_.yml
@@ -0,0 +1,8 @@
'{"symbol": "EXFO", "name": "EXFO Inc.", "quote": {"name": "EXFO Inc.", "close": 3.07,
"change": 0.08, "percent_change": 2.68}, "open": 2.95, "high": 3.07, "low": 2.8456,
"close": 3.07, "change": 0.08, "percent_change": 2.68, "previous_close": 2.99, "bid_price":
2.48, "bid_size": 1200, "ask_price": 3.09, "ask_size": 800, "fifty_two_week_low":
2.0, "fifty_two_week_high": 4.95, "volume": 138319, "average_volume": 36450, "market_cap":
168861000, "beta_five_year_monthly": 1.43, "pe_ratio_ttm": null, "eps_ttm": -0.172,
"earnings_date": null, "forward_dividend_yield": null, "forward_dividend_yield_percentage":
null, "exdividend_date": null, "one_year_target_est": 3.79}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_fcel_.yml
@@ -0,0 +1,9 @@
'{"symbol": "FCEL", "name": "FuelCell Energy, Inc.", "quote": {"name": "FuelCell Energy,
Inc.", "close": 2.62, "change": 0.24, "percent_change": 10.08}, "open": 2.54, "high":
2.66, "low": 2.43, "close": 2.62, "change": 0.24, "percent_change": 10.08, "previous_close":
2.38, "bid_price": 2.6, "bid_size": 21500, "ask_price": 2.61, "ask_size": 34100,
"fifty_two_week_low": 0.23, "fifty_two_week_high": 3.5, "volume": 59871100, "average_volume":
16999709, "market_cap": 758225000, "beta_five_year_monthly": 2.2, "pe_ratio_ttm":
null, "eps_ttm": -0.558, "earnings_date": "2020-09-10", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
2.5}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_gpro_.yml
@@ -0,0 +1,9 @@
'{"symbol": "GPRO", "name": "GoPro, Inc.", "quote": {"name": "GoPro, Inc.", "close":
6.18, "change": -0.03, "percent_change": -0.48}, "open": 6.3, "high": 6.65, "low":
6.07, "close": 6.18, "change": -0.03, "percent_change": -0.48, "previous_close":
6.21, "bid_price": 6.16, "bid_size": 4000, "ask_price": 6.26, "ask_size": 2900,
"fifty_two_week_low": 2.0, "fifty_two_week_high": 6.65, "volume": 6883265, "average_volume":
2880492, "market_cap": 975377000, "beta_five_year_monthly": 1.16, "pe_ratio_ttm":
null, "eps_ttm": -0.64, "earnings_date": "2020-11-05", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
4.83}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_lite_.yml
@@ -0,0 +1,9 @@
'{"symbol": "LITE", "name": "Lumentum Holdings Inc.", "quote": {"name": "Lumentum
Holdings Inc.", "close": 82.74, "change": 0.69, "percent_change": 0.84}, "open":
83.2, "high": 83.77, "low": 82.51, "close": 82.74, "change": 0.69, "percent_change":
0.84, "previous_close": 82.05, "bid_price": 82.78, "bid_size": 900, "ask_price":
82.75, "ask_size": 1100, "fifty_two_week_low": 52.73, "fifty_two_week_high": 96.74,
"volume": 859243, "average_volume": 1311086, "market_cap": 6244000000, "beta_five_year_monthly":
0.92, "pe_ratio_ttm": 47.28, "eps_ttm": 1.75, "earnings_date": "2020-10-29", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
103.44}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_msft_.yml
@@ -0,0 +1,9 @@
'{"symbol": "MSFT", "name": "Microsoft Corporation", "quote": {"name": "Microsoft
Corporation", "close": 215.81, "change": 5.23, "percent_change": 2.48}, "open":
211.23, "high": 215.86, "low": 211.25, "close": 215.81, "change": 5.23, "percent_change":
2.48, "previous_close": 210.58, "bid_price": 215.58, "bid_size": 1100, "ask_price":
215.45, "ask_size": 1200, "fifty_two_week_low": 132.52, "fifty_two_week_high": 232.86,
"volume": 26458047, "average_volume": 34253627, "market_cap": 1633000000000, "beta_five_year_monthly":
0.92, "pe_ratio_ttm": 37.47, "eps_ttm": 5.76, "earnings_date": "2020-10-21", "forward_dividend_yield":
2.24, "forward_dividend_yield_percentage": 1.06, "exdividend_date": "2020-11-18",
"one_year_target_est": 229.83}'
8 changes: 8 additions & 0 deletions tests/test_summary/test_parse_summary_table_pavm_.yml
@@ -0,0 +1,8 @@
'{"symbol": "PAVM", "name": "PAVmed Inc.", "quote": {"name": "PAVmed Inc.", "close":
2.04, "change": 0.12, "percent_change": 6.25}, "open": 1.93, "high": 2.08, "low":
1.89, "close": 2.04, "change": 0.12, "percent_change": 6.25, "previous_close": 1.92,
"bid_price": 2.02, "bid_size": 900, "ask_price": 2.06, "ask_size": 800, "fifty_two_week_low":
0.81, "fifty_two_week_high": 3.45, "volume": 1216658, "average_volume": 587260,
"market_cap": 102208000, "beta_five_year_monthly": 0.03, "pe_ratio_ttm": null, "eps_ttm":
-0.768, "earnings_date": "2020-08-18", "forward_dividend_yield": null, "forward_dividend_yield_percentage":
null, "exdividend_date": null, "one_year_target_est": null}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_tsla_.yml
@@ -0,0 +1,9 @@
'{"symbol": "TSLA", "name": "Tesla, Inc.", "quote": {"name": "Tesla, Inc.", "close":
433.95, "change": 8.03, "percent_change": 1.89}, "open": 430.13, "high": 434.59,
"low": 426.47, "close": 433.95, "change": 8.03, "percent_change": 1.89, "previous_close":
425.92, "bid_price": 434.41, "bid_size": 1400, "ask_price": 434.5, "ask_size": 800,
"fifty_two_week_low": 49.36, "fifty_two_week_high": 502.49, "volume": 28327188,
"average_volume": 77580184, "market_cap": 404359000000, "beta_five_year_monthly":
1.69, "pe_ratio_ttm": 1124.22, "eps_ttm": 0.39, "earnings_date": "2020-10-21", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
309.55}'
9 changes: 9 additions & 0 deletions tests/test_summary/test_parse_summary_table_twtr_.yml
@@ -0,0 +1,9 @@
'{"symbol": "TWTR", "name": "Twitter, Inc.", "quote": {"name": "Twitter, Inc.", "close":
45.9, "change": -0.11, "percent_change": -0.24}, "open": 46.4, "high": 46.41, "low":
45.66, "close": 45.9, "change": -0.11, "percent_change": -0.24, "previous_close":
46.01, "bid_price": 45.88, "bid_size": 900, "ask_price": 46.09, "ask_size": 1400,
"fifty_two_week_low": 20.0, "fifty_two_week_high": 47.87, "volume": 7182326, "average_volume":
17407526, "market_cap": 36305000000, "beta_five_year_monthly": 0.81, "pe_ratio_ttm":
null, "eps_ttm": -1.58, "earnings_date": "2020-10-29", "forward_dividend_yield":
null, "forward_dividend_yield_percentage": null, "exdividend_date": null, "one_year_target_est":
37.92}'

0 comments on commit 196d15b

Please sign in to comment.