Reformat code to pythonic standards

This commit is contained in:
chris committed 2026-05-27 08:19:34 -04:00
1 parent e2b8f5497c
commit ea62bdfc0b
6 files changed
+249 -100

No files matched your search

+29 -14
View File
@@ -1,24 +1,29 @@
from datetime import datetime
import pytest
from sqlalchemy.exc import IntegrityError
from httpx import ConnectError
from conftest import MegaMillionsDraw
from httpx import ConnectError
from sqlalchemy.exc import IntegrityError
from util.drawing import get_mega_millions_object
from util.scrape import scrape_game_history
def test_create_mega_millions_draw(db_session) -> None:
"""add a record"""
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,
main_ball5=49, mega_ball=9, megaplier=4)
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,
main_ball5=49, mega_ball=9, megaplier=4,
)
db_session.add(new_record)
db_session.commit()
# 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 == 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:
"""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
def test_mega_millions_draw_integrity(db_session) -> None:
"""ensure that duplicate records cannot be inserted"""
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,
main_ball5=49, mega_ball=9, megaplier=4)
new_record = MegaMillionsDraw(
draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26,
main_ball4=27,
main_ball5=49, mega_ball=9, megaplier=4,
)
try:
# 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:
"""test the __eq__, __repr__ and __str__ methods of MegaMillionsDraw"""
date = datetime(2010, 2, 2).date()
new_record = MegaMillionsDraw(draw_date=date, main_ball1=6, main_ball2=7, main_ball3=26, main_ball4=27,
main_ball5=49, mega_ball=9, megaplier=4)
new_record = MegaMillionsDraw(
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
db_session.add(new_record)
db_session.commit()
# 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__
assert str(record) == str(new_record)