Reformat code to pythonic standards
This commit is contained in:
1 parent
e2b8f5497c
commit
ea62bdfc0b
6 files changed
+249
-100
No files matched your search
@@ -1,24 +1,29 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
|
||||||
from httpx import ConnectError
|
|
||||||
|
|
||||||
from conftest import MegaMillionsDraw
|
from conftest import MegaMillionsDraw
|
||||||
|
from httpx import ConnectError
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from util.drawing import get_mega_millions_object
|
from util.drawing import get_mega_millions_object
|
||||||
from util.scrape import scrape_game_history
|
from util.scrape import scrape_game_history
|
||||||
|
|
||||||
|
|
||||||
def test_create_mega_millions_draw(db_session) -> None:
|
def test_create_mega_millions_draw(db_session) -> None:
|
||||||
"""add a record"""
|
"""add a record"""
|
||||||
date = datetime(2010, 2, 2).date() # 6 7 26 27 49 9 4x
|
date = datetime(2010, 2, 2).date() # 6 7 26 27 49 9 4x
|
||||||
new_record = MegaMillionsDraw(draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26, main_ball4=27,
|
new_record = MegaMillionsDraw(
|
||||||
main_ball5=49, mega_ball=9, megaplier=4)
|
draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26,
|
||||||
|
main_ball4=27,
|
||||||
|
main_ball5=49, mega_ball=9, megaplier=4,
|
||||||
|
)
|
||||||
db_session.add(new_record)
|
db_session.add(new_record)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
# verify the record exists
|
# verify the record exists
|
||||||
record = db_session.query(MegaMillionsDraw).filter_by(draw_date=date).first()
|
record = db_session.query(MegaMillionsDraw).filter_by(
|
||||||
|
draw_date=date,
|
||||||
|
).first()
|
||||||
assert record is not None
|
assert record is not None
|
||||||
assert record == new_record
|
assert record == new_record
|
||||||
|
|
||||||
@@ -31,15 +36,20 @@ def test_mega_millions_draw_isolation(db_session) -> None:
|
|||||||
|
|
||||||
def test_mega_millions_draw_by_date_blank(db_session) -> None:
|
def test_mega_millions_draw_by_date_blank(db_session) -> None:
|
||||||
"""query for all mega millions records with a blank date"""
|
"""query for all mega millions records with a blank date"""
|
||||||
blank_results = db_session.query(MegaMillionsDraw).filter_by(draw_date='').all()
|
blank_results = db_session.query(MegaMillionsDraw).filter_by(
|
||||||
|
draw_date='',
|
||||||
|
).all()
|
||||||
assert len(blank_results) == 0
|
assert len(blank_results) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_mega_millions_draw_integrity(db_session) -> None:
|
def test_mega_millions_draw_integrity(db_session) -> None:
|
||||||
"""ensure that duplicate records cannot be inserted"""
|
"""ensure that duplicate records cannot be inserted"""
|
||||||
date = datetime(2010, 2, 2).date() # 6 7 26 27 49 9 4x
|
date = datetime(2010, 2, 2).date() # 6 7 26 27 49 9 4x
|
||||||
new_record = MegaMillionsDraw(draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26, main_ball4=27,
|
new_record = MegaMillionsDraw(
|
||||||
main_ball5=49, mega_ball=9, megaplier=4)
|
draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26,
|
||||||
|
main_ball4=27,
|
||||||
|
main_ball5=49, mega_ball=9, megaplier=4,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# insert a new record
|
# insert a new record
|
||||||
@@ -56,15 +66,20 @@ def test_mega_millions_draw_integrity(db_session) -> None:
|
|||||||
def test_mega_millions_draw_eq_repr_and_str(db_session) -> None:
|
def test_mega_millions_draw_eq_repr_and_str(db_session) -> None:
|
||||||
"""test the __eq__, __repr__ and __str__ methods of MegaMillionsDraw"""
|
"""test the __eq__, __repr__ and __str__ methods of MegaMillionsDraw"""
|
||||||
date = datetime(2010, 2, 2).date()
|
date = datetime(2010, 2, 2).date()
|
||||||
new_record = MegaMillionsDraw(draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26, main_ball4=27,
|
new_record = MegaMillionsDraw(
|
||||||
main_ball5=49, mega_ball=9, megaplier=4)
|
draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26,
|
||||||
|
main_ball4=27,
|
||||||
|
main_ball5=49, mega_ball=9, megaplier=4,
|
||||||
|
)
|
||||||
|
|
||||||
# insert a new record
|
# insert a new record
|
||||||
db_session.add(new_record)
|
db_session.add(new_record)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
# query the record
|
# query the record
|
||||||
record = db_session.query(MegaMillionsDraw).filter_by(draw_date=date).first()
|
record = db_session.query(MegaMillionsDraw).filter_by(
|
||||||
|
draw_date=date,
|
||||||
|
).first()
|
||||||
|
|
||||||
# compare the str and repr values of each using __eq__
|
# compare the str and repr values of each using __eq__
|
||||||
assert str(record) == str(new_record)
|
assert str(record) == str(new_record)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
|
||||||
from httpx import ConnectError
|
|
||||||
|
|
||||||
from conftest import PowerballDraw
|
from conftest import PowerballDraw
|
||||||
|
from httpx import ConnectError
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from util.drawing import get_powerball_object
|
from util.drawing import get_powerball_object
|
||||||
from util.scrape import scrape_game_history
|
from util.scrape import scrape_game_history
|
||||||
|
|
||||||
@@ -12,8 +12,11 @@ from util.scrape import scrape_game_history
|
|||||||
def test_create_powerball_draw(db_session) -> None:
|
def test_create_powerball_draw(db_session) -> None:
|
||||||
"""add a record"""
|
"""add a record"""
|
||||||
date = datetime(2010, 2, 3).date()
|
date = datetime(2010, 2, 3).date()
|
||||||
new_record = PowerballDraw(draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36, main_ball4=37,
|
new_record = PowerballDraw(
|
||||||
main_ball5=52, powerball=24, power_play=2)
|
draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36,
|
||||||
|
main_ball4=37,
|
||||||
|
main_ball5=52, powerball=24, power_play=2,
|
||||||
|
)
|
||||||
db_session.add(new_record)
|
db_session.add(new_record)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
@@ -31,15 +34,20 @@ def test_powerball_draw_isolation(db_session) -> None:
|
|||||||
|
|
||||||
def test_powerball_draw_by_date_blank(db_session) -> None:
|
def test_powerball_draw_by_date_blank(db_session) -> None:
|
||||||
"""query for all powerball records with a blank date"""
|
"""query for all powerball records with a blank date"""
|
||||||
blank_results = db_session.query(PowerballDraw).filter_by(draw_date='').all()
|
blank_results = db_session.query(PowerballDraw).filter_by(
|
||||||
|
draw_date='',
|
||||||
|
).all()
|
||||||
assert len(blank_results) == 0
|
assert len(blank_results) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_powerball_draw_integrity(db_session) -> None:
|
def test_powerball_draw_integrity(db_session) -> None:
|
||||||
"""ensure that duplicate records cannot be inserted"""
|
"""ensure that duplicate records cannot be inserted"""
|
||||||
date = datetime(2010, 2, 3).date()
|
date = datetime(2010, 2, 3).date()
|
||||||
new_record = PowerballDraw(draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36, main_ball4=37,
|
new_record = PowerballDraw(
|
||||||
main_ball5=52, powerball=24, power_play=2)
|
draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36,
|
||||||
|
main_ball4=37,
|
||||||
|
main_ball5=52, powerball=24, power_play=2,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# insert a new record
|
# insert a new record
|
||||||
@@ -56,8 +64,11 @@ def test_powerball_draw_integrity(db_session) -> None:
|
|||||||
def test_powerball_draw_eq_repr_and_str(db_session) -> None:
|
def test_powerball_draw_eq_repr_and_str(db_session) -> None:
|
||||||
"""test the __eq__, __repr__ and __str__ methods of PowerballDraw"""
|
"""test the __eq__, __repr__ and __str__ methods of PowerballDraw"""
|
||||||
date = datetime(2010, 2, 3).date()
|
date = datetime(2010, 2, 3).date()
|
||||||
new_record = PowerballDraw(draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36, main_ball4=37,
|
new_record = PowerballDraw(
|
||||||
main_ball5=52, powerball=24, power_play=2)
|
draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36,
|
||||||
|
main_ball4=37,
|
||||||
|
main_ball5=52, powerball=24, power_play=2,
|
||||||
|
)
|
||||||
|
|
||||||
# insert a new record
|
# insert a new record
|
||||||
db_session.add(new_record)
|
db_session.add(new_record)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pytest
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pytest
|
||||||
|
|
||||||
import lottery_predictor.analyze as analyze
|
import lottery_predictor.analyze as analyze
|
||||||
|
|
||||||
@@ -10,10 +10,16 @@ def test_load_dataframe_by_date() -> None:
|
|||||||
pb_start = datetime(2015, 10, 4)
|
pb_start = datetime(2015, 10, 4)
|
||||||
mm_start = datetime(2025, 4, 5)
|
mm_start = datetime(2025, 4, 5)
|
||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
assert int(analyze.load_dataframe_by_dates(
|
assert int(
|
||||||
game='Powerball', start_date=pb_start, end_date=date_end).count()['draw_date']) >= 1324
|
analyze.load_dataframe_by_dates(
|
||||||
assert int(analyze.load_dataframe_by_dates(
|
game='Powerball', start_date=pb_start, end_date=date_end,
|
||||||
game='MegaMillions', start_date=mm_start, end_date=date_end).count()['draw_date']) >= 96
|
).count()['draw_date'],
|
||||||
|
) >= 1324
|
||||||
|
assert int(
|
||||||
|
analyze.load_dataframe_by_dates(
|
||||||
|
game='MegaMillions', start_date=mm_start, end_date=date_end,
|
||||||
|
).count()['draw_date'],
|
||||||
|
) >= 96
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
analyze.load_dataframe_by_dates(game='SomeNonExistentGameName')
|
analyze.load_dataframe_by_dates(game='SomeNonExistentGameName')
|
||||||
|
|
||||||
@@ -21,8 +27,12 @@ def test_load_dataframe_by_date() -> None:
|
|||||||
def test_load_dataframe_most_recent() -> None:
|
def test_load_dataframe_most_recent() -> None:
|
||||||
assert len(analyze.load_dataframe_most_recent(game='Powerball')) == 10
|
assert len(analyze.load_dataframe_most_recent(game='Powerball')) == 10
|
||||||
assert len(analyze.load_dataframe_most_recent(game='MegaMillions')) == 10
|
assert len(analyze.load_dataframe_most_recent(game='MegaMillions')) == 10
|
||||||
assert len(analyze.load_dataframe_most_recent(game='Powerball', limit=105)) == 105
|
assert len(
|
||||||
assert len(analyze.load_dataframe_most_recent(game='MegaMillions', limit=45)) == 45
|
analyze.load_dataframe_most_recent(game='Powerball', limit=105),
|
||||||
|
) == 105
|
||||||
|
assert len(
|
||||||
|
analyze.load_dataframe_most_recent(game='MegaMillions', limit=45),
|
||||||
|
) == 45
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
analyze.load_dataframe_most_recent(game='Powerball', limit=-1)
|
analyze.load_dataframe_most_recent(game='Powerball', limit=-1)
|
||||||
analyze.load_dataframe_most_recent(game='DoesntExist')
|
analyze.load_dataframe_most_recent(game='DoesntExist')
|
||||||
@@ -31,9 +41,13 @@ def test_load_dataframe_most_recent() -> None:
|
|||||||
def test_prepare_split_data() -> None:
|
def test_prepare_split_data() -> None:
|
||||||
mm_start = datetime(2025, 4, 5)
|
mm_start = datetime(2025, 4, 5)
|
||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
mega = analyze.load_dataframe_by_dates(game='MegaMillions', start_date=mm_start, end_date=date_end)
|
mega = analyze.load_dataframe_by_dates(
|
||||||
|
game='MegaMillions', start_date=mm_start, end_date=date_end,
|
||||||
|
)
|
||||||
|
|
||||||
x, y1, y2 = analyze.prepare_split_data(data=mega.values, window_size=len(mega) - 1)
|
x, y1, y2 = analyze.prepare_split_data(
|
||||||
|
data=mega.values, window_size=len(mega) - 1,
|
||||||
|
)
|
||||||
assert isinstance(x, np.ndarray)
|
assert isinstance(x, np.ndarray)
|
||||||
assert isinstance(y1, np.ndarray)
|
assert isinstance(y1, np.ndarray)
|
||||||
assert isinstance(y2, np.ndarray)
|
assert isinstance(y2, np.ndarray)
|
||||||
@@ -42,7 +56,9 @@ def test_prepare_split_data() -> None:
|
|||||||
def test_make_prediction() -> None:
|
def test_make_prediction() -> None:
|
||||||
pb_start = datetime(2015, 10, 4)
|
pb_start = datetime(2015, 10, 4)
|
||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
power = analyze.load_dataframe_by_dates(game='Powerball', start_date=pb_start, end_date=date_end)
|
power = analyze.load_dataframe_by_dates(
|
||||||
|
game='Powerball', start_date=pb_start, end_date=date_end,
|
||||||
|
)
|
||||||
|
|
||||||
main, game = analyze.make_prediction(data_frame=power, window_size=10)
|
main, game = analyze.make_prediction(data_frame=power, window_size=10)
|
||||||
assert isinstance(main, np.ndarray)
|
assert isinstance(main, np.ndarray)
|
||||||
@@ -55,34 +71,55 @@ def test_least_and_most_common_number() -> None:
|
|||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
|
|
||||||
pb_df = analyze.load_dataframe_by_dates(
|
pb_df = analyze.load_dataframe_by_dates(
|
||||||
game='Powerball', start_date=pb_start, end_date=date_end)
|
game='Powerball', start_date=pb_start, end_date=date_end,
|
||||||
|
)
|
||||||
mm_df = analyze.load_dataframe_by_dates(
|
mm_df = analyze.load_dataframe_by_dates(
|
||||||
game='MegaMillions', start_date=mm_start, end_date=date_end)
|
game='MegaMillions', start_date=mm_start, end_date=date_end,
|
||||||
|
)
|
||||||
|
|
||||||
assert analyze.get_most_common_number(pb_df, top=5) == [61, 21, 23, 28, 33]
|
assert analyze.get_most_common_number(pb_df, top=5) == [61, 21, 23, 28, 33]
|
||||||
assert analyze.get_least_common_number(pb_df, bottom=5) == [13, 49, 26, 46, 34]
|
assert analyze.get_least_common_number(pb_df, bottom=5) == [
|
||||||
|
13, 49, 26, 46, 34,
|
||||||
|
]
|
||||||
assert analyze.get_most_common_number(mm_df, top=5) == [42, 18, 40, 49, 10]
|
assert analyze.get_most_common_number(mm_df, top=5) == [42, 18, 40, 49, 10]
|
||||||
assert analyze.get_least_common_number(mm_df, bottom=5) == [35, 51, 61, 1, 20]
|
assert analyze.get_least_common_number(mm_df, bottom=5) == [
|
||||||
|
35, 51, 61, 1, 20,
|
||||||
|
]
|
||||||
|
|
||||||
assert analyze.get_most_common_number(pb_df, columns=['powerball'], top=1) == [4]
|
assert analyze.get_most_common_number(
|
||||||
assert analyze.get_least_common_number(pb_df, columns=['powerball'], bottom=1) == [16]
|
pb_df, columns=['powerball'], top=1,
|
||||||
assert analyze.get_most_common_number(mm_df, columns=['mega_ball'], top=1) == [24]
|
) == [4]
|
||||||
assert analyze.get_least_common_number(mm_df, columns=['mega_ball'], bottom=1) == [20]
|
assert analyze.get_least_common_number(
|
||||||
|
pb_df, columns=['powerball'], bottom=1,
|
||||||
|
) == [16]
|
||||||
|
assert analyze.get_most_common_number(
|
||||||
|
mm_df, columns=['mega_ball'], top=1,
|
||||||
|
) == [24]
|
||||||
|
assert analyze.get_least_common_number(
|
||||||
|
mm_df, columns=['mega_ball'], bottom=1,
|
||||||
|
) == [20]
|
||||||
|
|
||||||
|
|
||||||
def test_calculate_probabilities() -> None:
|
def test_calculate_probabilities() -> None:
|
||||||
"""tests build_binary_matrix, build_next_targets and calculate_number_probability"""
|
"""tests build_binary_matrix, build_next_targets and
|
||||||
|
calculate_number_probability"""
|
||||||
pb_start = datetime(2015, 10, 4)
|
pb_start = datetime(2015, 10, 4)
|
||||||
mm_start = datetime(2025, 4, 5)
|
mm_start = datetime(2025, 4, 5)
|
||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
|
|
||||||
pb_df = analyze.load_dataframe_by_dates(
|
pb_df = analyze.load_dataframe_by_dates(
|
||||||
game='Powerball', start_date=pb_start, end_date=date_end)
|
game='Powerball', start_date=pb_start, end_date=date_end,
|
||||||
pb_probabilities = analyze.calculate_probabilities(data_frame=pb_df, max_number=69)
|
)
|
||||||
|
pb_probabilities = analyze.calculate_probabilities(
|
||||||
|
data_frame=pb_df, max_number=69,
|
||||||
|
)
|
||||||
|
|
||||||
mm_df = analyze.load_dataframe_by_dates(
|
mm_df = analyze.load_dataframe_by_dates(
|
||||||
game='MegaMillions', start_date=mm_start, end_date=date_end)
|
game='MegaMillions', start_date=mm_start, end_date=date_end,
|
||||||
mm_probabilities = analyze.calculate_probabilities(data_frame=mm_df, max_number=70)
|
)
|
||||||
|
mm_probabilities = analyze.calculate_probabilities(
|
||||||
|
data_frame=mm_df, max_number=70,
|
||||||
|
)
|
||||||
|
|
||||||
assert pb_probabilities[1] == 0.3142857142857143
|
assert pb_probabilities[1] == 0.3142857142857143
|
||||||
assert mm_probabilities[1] == 0.04225352112676056
|
assert mm_probabilities[1] == 0.04225352112676056
|
||||||
@@ -95,20 +132,34 @@ def test_hot_cold_numbers() -> None:
|
|||||||
date_end = datetime(2026, 3, 8)
|
date_end = datetime(2026, 3, 8)
|
||||||
|
|
||||||
pb_df = analyze.load_dataframe_by_dates(
|
pb_df = analyze.load_dataframe_by_dates(
|
||||||
game='Powerball', start_date=pb_start, end_date=date_end)
|
game='Powerball', start_date=pb_start, end_date=date_end,
|
||||||
|
)
|
||||||
pb_probs = analyze.calculate_probabilities(data_frame=pb_df, max_number=69)
|
pb_probs = analyze.calculate_probabilities(data_frame=pb_df, max_number=69)
|
||||||
mm_df = analyze.load_dataframe_by_dates(
|
mm_df = analyze.load_dataframe_by_dates(
|
||||||
game='MegaMillions', start_date=mm_start, end_date=date_end)
|
game='MegaMillions', start_date=mm_start, end_date=date_end,
|
||||||
|
)
|
||||||
mm_probs = analyze.calculate_probabilities(data_frame=mm_df, max_number=70)
|
mm_probs = analyze.calculate_probabilities(data_frame=mm_df, max_number=70)
|
||||||
|
|
||||||
assert (analyze.get_hot_numbers(probabilities=pb_probs) ==
|
assert (analyze.get_hot_numbers(probabilities=pb_probs) ==
|
||||||
[(13, 1.0), (61, 0.7), (21, 0.6714285714285715), (23, 0.6428571428571428), (28, 0.6428571428571428)])
|
[
|
||||||
|
(13, 1.0), (61, 0.7), (21, 0.6714285714285715),
|
||||||
|
(23, 0.6428571428571428), (28, 0.6428571428571428),
|
||||||
|
])
|
||||||
assert (analyze.get_cold_numbers(probabilities=pb_probs) ==
|
assert (analyze.get_cold_numbers(probabilities=pb_probs) ==
|
||||||
[(49, 0.10000000000000009), (26, 0.11428571428571432), (46, 0.11428571428571432),
|
[
|
||||||
(34, 0.17142857142857149), (65, 0.18571428571428572)])
|
(49, 0.10000000000000009), (26, 0.11428571428571432),
|
||||||
|
(46, 0.11428571428571432),
|
||||||
|
(34, 0.17142857142857149), (65, 0.18571428571428572),
|
||||||
|
])
|
||||||
assert (analyze.get_hot_numbers(probabilities=mm_probs) ==
|
assert (analyze.get_hot_numbers(probabilities=mm_probs) ==
|
||||||
[(42, 0.19718309859154928), (18, 0.18309859154929578), (40, 0.18309859154929578),
|
[
|
||||||
(10, 0.16901408450704225), (49, 0.16901408450704225)])
|
(42, 0.19718309859154928), (18, 0.18309859154929578),
|
||||||
|
(40, 0.18309859154929578),
|
||||||
|
(10, 0.16901408450704225), (49, 0.16901408450704225),
|
||||||
|
])
|
||||||
assert (analyze.get_cold_numbers(probabilities=mm_probs) ==
|
assert (analyze.get_cold_numbers(probabilities=mm_probs) ==
|
||||||
[(35, 0.028169014084507043), (51, 0.028169014084507043), (1, 0.04225352112676056),
|
[
|
||||||
(3, 0.04225352112676056), (20, 0.04225352112676056)])
|
(35, 0.028169014084507043), (51, 0.028169014084507043),
|
||||||
|
(1, 0.04225352112676056),
|
||||||
|
(3, 0.04225352112676056), (20, 0.04225352112676056),
|
||||||
|
])
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import lottery_predictor.collect as collect
|
import lottery_predictor.collect as collect
|
||||||
@@ -12,8 +13,12 @@ def test_get_record_count() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_get_recent_draw_date() -> None:
|
def test_get_recent_draw_date() -> None:
|
||||||
assert isinstance(collect.get_recent_draw_date(game='Powerball'), datetime.date)
|
assert isinstance(
|
||||||
assert isinstance(collect.get_recent_draw_date(game='MegaMillions'), datetime.date)
|
collect.get_recent_draw_date(game='Powerball'), datetime.date,
|
||||||
|
)
|
||||||
|
assert isinstance(
|
||||||
|
collect.get_recent_draw_date(game='MegaMillions'), datetime.date,
|
||||||
|
)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
collect.get_recent_draw_date(game='SomeNonExistentTable')
|
collect.get_recent_draw_date(game='SomeNonExistentTable')
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import lottery_predictor.draw as draw
|
|||||||
|
|
||||||
|
|
||||||
def test_generate_random_ticket() -> None:
|
def test_generate_random_ticket() -> None:
|
||||||
assert isinstance(draw.generate_random_ticket(max_main=69, max_game=26), tuple)
|
assert isinstance(
|
||||||
assert isinstance(draw.generate_random_ticket(max_main=70, max_game=24), tuple)
|
draw.generate_random_ticket(max_main=69, max_game=26), tuple,
|
||||||
|
)
|
||||||
|
assert isinstance(
|
||||||
|
draw.generate_random_ticket(max_main=70, max_game=24), tuple,
|
||||||
|
)
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
draw.generate_random_ticket()
|
draw.generate_random_ticket()
|
||||||
+102
-39
@@ -1,15 +1,15 @@
|
|||||||
"""Tests for the `util` module."""
|
"""Tests for the `util` module."""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
from httpx import ConnectError
|
from httpx import ConnectError
|
||||||
|
|
||||||
import pytest
|
|
||||||
import util.convert as uc
|
import util.convert as uc
|
||||||
import util.drawing as ud
|
import util.drawing as ud
|
||||||
import util.environment as ue
|
import util.environment as ue
|
||||||
import util.scrape as sc
|
|
||||||
import util.odds as uo
|
import util.odds as uo
|
||||||
from data.database import PowerballDraw, MegaMillionsDraw
|
import util.scrape as sc
|
||||||
|
from data.database import MegaMillionsDraw, PowerballDraw
|
||||||
|
|
||||||
|
|
||||||
def test_convert_string_to_integer() -> None:
|
def test_convert_string_to_integer() -> None:
|
||||||
@@ -31,7 +31,8 @@ def test_get_previous_draw_date_none() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_get_next_draw_date_minimum() -> None:
|
def test_get_next_draw_date_minimum() -> None:
|
||||||
"""Test the next draw date returned for each game and when an invalid name is presented (None)"""
|
"""Test the next draw date returned for each game and when an invalid
|
||||||
|
name is presented (None)"""
|
||||||
assert ud.get_next_draw_date(game="mega-millions")
|
assert ud.get_next_draw_date(game="mega-millions")
|
||||||
assert ud.get_next_draw_date(game="powerball")
|
assert ud.get_next_draw_date(game="powerball")
|
||||||
assert not ud.get_next_draw_date(game="something")
|
assert not ud.get_next_draw_date(game="something")
|
||||||
@@ -40,7 +41,8 @@ def test_get_next_draw_date_minimum() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_get_previous_draw_date_minimum() -> None:
|
def test_get_previous_draw_date_minimum() -> None:
|
||||||
"""Test the next draw date returned for each game and when an invalid name is presented (None)"""
|
"""Test the next draw date returned for each game and when an invalid
|
||||||
|
name is presented (None)"""
|
||||||
assert ud.get_previous_draw_date(game="mega-millions")
|
assert ud.get_previous_draw_date(game="mega-millions")
|
||||||
assert ud.get_previous_draw_date(game="powerball")
|
assert ud.get_previous_draw_date(game="powerball")
|
||||||
assert not ud.get_previous_draw_date(game="something")
|
assert not ud.get_previous_draw_date(game="something")
|
||||||
@@ -50,39 +52,84 @@ def test_get_previous_draw_date_minimum() -> None:
|
|||||||
|
|
||||||
def test_get_next_draw_date_specified_from_date() -> None:
|
def test_get_next_draw_date_specified_from_date() -> None:
|
||||||
"""Test drawing dates returned for each possible day of the week."""
|
"""Test drawing dates returned for each possible day of the week."""
|
||||||
assert ud.get_next_draw_date(game="mega-millions", from_date='02/15/2026') == '02/17/2026'
|
assert ud.get_next_draw_date(
|
||||||
assert ud.get_next_draw_date(game="mega-millions", from_date='02/16/2026') == '02/17/2026'
|
game="mega-millions", from_date='02/15/2026',
|
||||||
assert ud.get_next_draw_date(game="mega-millions", from_date='02/17/2026') == '02/17/2026'
|
) == '02/17/2026'
|
||||||
assert ud.get_next_draw_date(game="mega-millions", from_date='02/18/2026') == '02/20/2026'
|
assert ud.get_next_draw_date(
|
||||||
assert ud.get_next_draw_date(game="mega-millions", from_date='02/19/2026') == '02/20/2026'
|
game="mega-millions", from_date='02/16/2026',
|
||||||
|
) == '02/17/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game="mega-millions", from_date='02/17/2026',
|
||||||
|
) == '02/17/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game="mega-millions", from_date='02/18/2026',
|
||||||
|
) == '02/20/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game="mega-millions", from_date='02/19/2026',
|
||||||
|
) == '02/20/2026'
|
||||||
|
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/15/2026') == '02/16/2026'
|
assert ud.get_next_draw_date(
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/16/2026') == '02/16/2026'
|
game='powerball', from_date='02/15/2026',
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/17/2026') == '02/18/2026'
|
) == '02/16/2026'
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/18/2026') == '02/18/2026'
|
assert ud.get_next_draw_date(
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/19/2026') == '02/21/2026'
|
game='powerball', from_date='02/16/2026',
|
||||||
assert ud.get_next_draw_date(game='powerball', from_date='02/20/2026') == '02/21/2026'
|
) == '02/16/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game='powerball', from_date='02/17/2026',
|
||||||
|
) == '02/18/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game='powerball', from_date='02/18/2026',
|
||||||
|
) == '02/18/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game='powerball', from_date='02/19/2026',
|
||||||
|
) == '02/21/2026'
|
||||||
|
assert ud.get_next_draw_date(
|
||||||
|
game='powerball', from_date='02/20/2026',
|
||||||
|
) == '02/21/2026'
|
||||||
|
|
||||||
|
|
||||||
def test_get_previous_draw_date_specified_from_date() -> None:
|
def test_get_previous_draw_date_specified_from_date() -> None:
|
||||||
"""Test drawing dates returned for each possible day of the week."""
|
"""Test drawing dates returned for each possible day of the week."""
|
||||||
assert ud.get_previous_draw_date(game="mega-millions", from_date='02/15/2026') == '02/13/2026'
|
assert ud.get_previous_draw_date(
|
||||||
assert ud.get_previous_draw_date(game="mega-millions", from_date='02/16/2026') == '02/13/2026'
|
game="mega-millions", from_date='02/15/2026',
|
||||||
assert ud.get_previous_draw_date(game="mega-millions", from_date='02/17/2026') == '02/13/2026'
|
) == '02/13/2026'
|
||||||
assert ud.get_previous_draw_date(game="mega-millions", from_date='02/18/2026') == '02/17/2026'
|
assert ud.get_previous_draw_date(
|
||||||
assert ud.get_previous_draw_date(game="mega-millions", from_date='02/19/2026') == '02/17/2026'
|
game="mega-millions", from_date='02/16/2026',
|
||||||
|
) == '02/13/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game="mega-millions", from_date='02/17/2026',
|
||||||
|
) == '02/13/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game="mega-millions", from_date='02/18/2026',
|
||||||
|
) == '02/17/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game="mega-millions", from_date='02/19/2026',
|
||||||
|
) == '02/17/2026'
|
||||||
|
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/15/2026') == '02/14/2026'
|
assert ud.get_previous_draw_date(
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/16/2026') == '02/14/2026'
|
game='powerball', from_date='02/15/2026',
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/17/2026') == '02/16/2026'
|
) == '02/14/2026'
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/18/2026') == '02/16/2026'
|
assert ud.get_previous_draw_date(
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/19/2026') == '02/18/2026'
|
game='powerball', from_date='02/16/2026',
|
||||||
assert ud.get_previous_draw_date(game='powerball', from_date='02/20/2026') == '02/18/2026'
|
) == '02/14/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game='powerball', from_date='02/17/2026',
|
||||||
|
) == '02/16/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game='powerball', from_date='02/18/2026',
|
||||||
|
) == '02/16/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game='powerball', from_date='02/19/2026',
|
||||||
|
) == '02/18/2026'
|
||||||
|
assert ud.get_previous_draw_date(
|
||||||
|
game='powerball', from_date='02/20/2026',
|
||||||
|
) == '02/18/2026'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("game", ['powerball', 'mega-millions'])
|
@pytest.mark.parametrize("game", ['powerball', 'mega-millions'])
|
||||||
def test_scrape_game_history(game) -> None:
|
def test_scrape_game_history(game) -> None:
|
||||||
"""Test scraping the powerball result page for 1996, 2020, and current year."""
|
"""Test scraping the powerball result page for 1996, 2020, and current
|
||||||
|
year."""
|
||||||
try:
|
try:
|
||||||
scrape_data = sc.scrape_game_history(game, year=1996)
|
scrape_data = sc.scrape_game_history(game, year=1996)
|
||||||
assert len(scrape_data) in [17, 104]
|
assert len(scrape_data) in [17, 104]
|
||||||
@@ -106,31 +153,47 @@ def test_calculate_odds() -> None:
|
|||||||
|
|
||||||
def test_get_odds_of_winning() -> None:
|
def test_get_odds_of_winning() -> None:
|
||||||
assert uo.get_odds_of_winning(
|
assert uo.get_odds_of_winning(
|
||||||
main_ball_draw_pool=49, main_ball_draw_count=5, game_ball_draw_pool=18, game_ball_draw_count=1
|
main_ball_draw_pool=49, main_ball_draw_count=5, game_ball_draw_pool=18,
|
||||||
|
game_ball_draw_count=1,
|
||||||
) == 'The odds of winning are 1 in 34,323,912'
|
) == 'The odds of winning are 1 in 34,323,912'
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
uo.get_odds_of_winning()
|
uo.get_odds_of_winning()
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
uo.get_odds_of_winning(
|
uo.get_odds_of_winning(
|
||||||
main_ball_draw_pool=49, main_ball_draw_count= 50, game_ball_draw_pool=18, game_ball_draw_count=1)
|
main_ball_draw_pool=49, main_ball_draw_count=50,
|
||||||
|
game_ball_draw_pool=18, game_ball_draw_count=1,
|
||||||
|
)
|
||||||
assert uo.get_odds_of_winning(
|
assert uo.get_odds_of_winning(
|
||||||
main_ball_draw_pool=69, main_ball_draw_count=5, game_ball_draw_pool=26, game_ball_draw_count=1
|
main_ball_draw_pool=69, main_ball_draw_count=5, game_ball_draw_pool=26,
|
||||||
|
game_ball_draw_count=1,
|
||||||
) == 'The odds of winning are 1 in 292,201,338'
|
) == 'The odds of winning are 1 in 292,201,338'
|
||||||
|
|
||||||
|
|
||||||
def test_get_powerball_object() -> None:
|
def test_get_powerball_object() -> None:
|
||||||
data_value = ud.get_powerball_object(draw_date='2026-01-03', draw_result={'main_balls': [18, 21, 40, 53, 60],
|
data_value = ud.get_powerball_object(
|
||||||
'powerball': 23, 'multiplier': 3})
|
draw_date='2026-01-03', draw_result={
|
||||||
test_record = PowerballDraw(draw_date=datetime(2026, 1, 3).date(), main_ball1=18, main_ball2=21,
|
'main_balls': [18, 21, 40, 53, 60],
|
||||||
main_ball3=40, main_ball4=53, main_ball5=60, powerball=23, power_play=3)
|
'powerball': 23, 'multiplier': 3,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
test_record = PowerballDraw(
|
||||||
|
draw_date=datetime(2026, 1, 3).date(), main_ball1=18, main_ball2=21,
|
||||||
|
main_ball3=40, main_ball4=53, main_ball5=60, powerball=23, power_play=3,
|
||||||
|
)
|
||||||
assert data_value == test_record
|
assert data_value == test_record
|
||||||
|
|
||||||
|
|
||||||
def test_get_mega_millions_object() -> None:
|
def test_get_mega_millions_object() -> None:
|
||||||
data_value = ud.get_mega_millions_object(draw_date='2010-02-02', draw_result={'main_balls': [6, 7, 26, 27, 49],
|
data_value = ud.get_mega_millions_object(
|
||||||
'mega-ball': 9, 'multiplier': 4})
|
draw_date='2010-02-02', draw_result={
|
||||||
test_record = MegaMillionsDraw(draw_date=datetime(2010, 2, 2).date(), main_ball1=6, main_ball2=7,
|
'main_balls': [6, 7, 26, 27, 49],
|
||||||
main_ball3=26, main_ball4=27, main_ball5=49, mega_ball=9, megaplier=4)
|
'mega-ball': 9, 'multiplier': 4,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
test_record = MegaMillionsDraw(
|
||||||
|
draw_date=datetime(2010, 2, 2).date(), main_ball1=6, main_ball2=7,
|
||||||
|
main_ball3=26, main_ball4=27, main_ball5=49, mega_ball=9, megaplier=4,
|
||||||
|
)
|
||||||
assert data_value == test_record
|
assert data_value == test_record
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user