From d947a6a9758d7349a9a22ac266383a8733deaf78 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Wed, 13 Jul 2022 19:12:42 +0000 Subject: [PATCH 1/3] extract number --- .devcontainer/devcontainer.json | 11 +++-------- npbc_core.py | 7 +++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4de47ef..b29193e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -21,8 +21,8 @@ // Set *default* container specific settings.json values on container create. "settings": { "python.defaultInterpreterPath": "/usr/local/bin/python", - "python.linting.enabled": true, - "python.linting.pylintEnabled": true, + "python.linting.enabled": false, + "python.linting.pylintEnabled": false, "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", "python.formatting.blackPath": "/usr/local/py-utils/bin/black", "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", @@ -37,10 +37,6 @@ "extensions": [ "ms-python.python", "ms-python.vscode-pylance", - "GitHub.codespaces", - "GitHub.remotehub", - "ms-vscode-remote.vscode-remote-extensionpack", - "ms-vscode.remote-repositories", "redhat.vscode-yaml", "mtxr.sqltools-driver-sqlite", "streetsidesoftware.code-spell-checker", @@ -62,8 +58,7 @@ "features": { "docker-in-docker": "latest", "git": "os-provided", - "github-cli": "latest", - "jupyterlab": "latest" + "github-cli": "latest" }, "remoteEnv": { "NPBC_DATABASE_DIR": "data" diff --git a/npbc_core.py b/npbc_core.py index 9f88b99..3a8810f 100644 --- a/npbc_core.py +++ b/npbc_core.py @@ -111,6 +111,9 @@ def extract_number(string: str, month: int, year: int) -> date | None: if 0 < day <= monthrange(year, month)[1]: return date(year, month, day) + # if we reach here, the check failed and it's not a valid date + raise npbc_exceptions.InvalidUndeliveredString(f'{string} is not a valid date for {datetime(year=year, month=month, day=1):%B %Y}.') + def extract_range(string: str, month: int, year: int) -> Generator[date, None, None]: """if the date is a range of numbers, it's a range of days. we identify all the dates in that range, bounds inclusive""" @@ -262,9 +265,9 @@ def calculate_cost_of_one_paper( for day in undelivered_dates: number_of_days_per_weekday_not_received[day.weekday()] += 1 - return numpy.sum( + return float(numpy.sum( delivery_data * cost_data * (number_of_each_weekday - number_of_days_per_weekday_not_received) - ) + )) def calculate_cost_of_all_papers(connection: Connection, undelivered_strings: dict[int, list[str]], month: int, year: int) -> tuple[ From d443e1130f13bcf370fe0d33d270cf516a5359a1 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Wed, 13 Jul 2022 20:43:16 +0000 Subject: [PATCH 2/3] test working --- npbc_core.py | 16 +++-- test_core.py | 165 ++++++++++++++++++++++++--------------------------- 2 files changed, 90 insertions(+), 91 deletions(-) diff --git a/npbc_core.py b/npbc_core.py index 3a8810f..76e755c 100644 --- a/npbc_core.py +++ b/npbc_core.py @@ -102,7 +102,7 @@ def validate_undelivered_string(*strings: str) -> None: # if we get here, all strings passed the regex check -def extract_number(string: str, month: int, year: int) -> date | None: +def extract_number(string: str, month: int, year: int) -> date: """if the date is simply a number, it's a single day. so we just identify that date""" day = int(string) @@ -125,6 +125,10 @@ def extract_range(string: str, month: int, year: int) -> Generator[date, None, N for day in range(start, end + 1): yield date(year, month, day) + else: + # if we reach here, the check failed and the month doesn't have that many days + raise npbc_exceptions.InvalidUndeliveredString(f'{datetime(year=year, month=month, day=1):%B %Y} does not have days between {start} and {end}.') + def extract_weekday(string: str, month: int, year: int) -> Generator[date, None, None]: """if the date is the plural of a weekday name, we identify all dates in that month which are the given weekday""" @@ -136,7 +140,7 @@ def extract_weekday(string: str, month: int, year: int) -> Generator[date, None, yield date(year, month, day) -def extract_nth_weekday(string: str, month: int, year: int) -> date | None: +def extract_nth_weekday(string: str, month: int, year: int) -> date: """if the date is a number and a weekday name (singular), we identify the date that is the nth occurrence of the given weekday in the month""" n, weekday_name = npbc_regex.HYPHEN_SPLIT_REGEX.split(string) @@ -159,6 +163,8 @@ def extract_nth_weekday(string: str, month: int, year: int) -> date | None: # return the date that is the nth occurrence of the given weekday in the month return valid_dates[n - 1] + # if we reach here, the check failed and the weekday does not occur n times in the month + raise npbc_exceptions.InvalidUndeliveredString(f'{datetime(year=year, month=month, day=1):%B %Y} does not have {n} {weekday_name}s.') def extract_all(month: int, year: int) -> Generator[date, None, None]: """if the text is "all", we identify all the dates in the month""" @@ -213,16 +219,18 @@ def parse_undelivered_strings(month: int, year: int, *strings: str) -> set[date] # check for each of the patterns for string in strings: + if string: try: dates.update(parse_undelivered_string(month, year, string)) - except npbc_exceptions.InvalidUndeliveredString: + except npbc_exceptions.InvalidUndeliveredString as e: print( f"""Congratulations! You broke the program! You managed to write a string that the program considers valid, but isn't actually. Please report it to the developer. \nThe string you wrote was: {string} - This data has not been counted.""" + This data has not been counted.\n + Exact error message: {e}""" ) return dates diff --git a/test_core.py b/test_core.py index 86cc5ae..845cb00 100644 --- a/test_core.py +++ b/test_core.py @@ -13,75 +13,70 @@ def test_get_number_of_each_weekday(): - test_function = npbc_core.get_number_of_each_weekday - - assert tuple(test_function(1, 2022)) == (5, 4, 4, 4, 4, 5, 5) - assert tuple(test_function(2, 2022)) == (4, 4, 4, 4, 4, 4, 4) - assert tuple(test_function(3, 2022)) == (4, 5, 5 ,5, 4, 4, 4) - assert tuple(test_function(2, 2020)) == (4, 4, 4, 4, 4, 5, 4) - assert tuple(test_function(12, 1954)) == (4, 4, 5, 5, 5, 4, 4) + assert tuple(npbc_core.get_number_of_each_weekday(1, 2022)) == (5, 4, 4, 4, 4, 5, 5) + assert tuple(npbc_core.get_number_of_each_weekday(2, 2022)) == (4, 4, 4, 4, 4, 4, 4) + assert tuple(npbc_core.get_number_of_each_weekday(3, 2022)) == (4, 5, 5 ,5, 4, 4, 4) + assert tuple(npbc_core.get_number_of_each_weekday(2, 2020)) == (4, 4, 4, 4, 4, 5, 4) + assert tuple(npbc_core.get_number_of_each_weekday(12, 1954)) == (4, 4, 5, 5, 5, 4, 4) def test_validate_undelivered_string(): - test_function = npbc_core.validate_undelivered_string - with raises(InvalidUndeliveredString): - test_function("a") - test_function("monday") - test_function("1-mondays") - test_function("1monday") - test_function("1 monday") - test_function("monday-1") - test_function("monday-1") - - test_function("") - test_function("1") - test_function("6") - test_function("31") - test_function("31","") - test_function("3","1") - test_function("3","1","") - test_function("3","1") - test_function("3","1") - test_function("3","1") - test_function("1","2","3-9") - test_function("1","2","3-9","11","12","13-19") - test_function("1","2","3-9","11","12","13-19","21","22","23-29") - test_function("1","2","3-9","11","12","13-19","21","22","23-29","31") - test_function("1","2","3","4","5","6","7","8","9") - test_function("mondays") - test_function("mondays,tuesdays") - test_function("mondays","tuesdays","wednesdays") - test_function("mondays","5-21") - test_function("mondays","5-21","tuesdays","5-21") - test_function("1-monday") - test_function("2-monday") - test_function("all") - test_function("All") - test_function("aLl") - test_function("alL") - test_function("aLL") - test_function("ALL") + npbc_core.validate_undelivered_string("a") + npbc_core.validate_undelivered_string("monday") + npbc_core.validate_undelivered_string("1-mondays") + npbc_core.validate_undelivered_string("1monday") + npbc_core.validate_undelivered_string("1 monday") + npbc_core.validate_undelivered_string("monday-1") + npbc_core.validate_undelivered_string("monday-1") + + npbc_core.validate_undelivered_string("") + npbc_core.validate_undelivered_string("1") + npbc_core.validate_undelivered_string("6") + npbc_core.validate_undelivered_string("31") + npbc_core.validate_undelivered_string("31","") + npbc_core.validate_undelivered_string("3","1") + npbc_core.validate_undelivered_string("3","1","") + npbc_core.validate_undelivered_string("3","1") + npbc_core.validate_undelivered_string("3","1") + npbc_core.validate_undelivered_string("3","1") + npbc_core.validate_undelivered_string("1","2","3-9") + npbc_core.validate_undelivered_string("1","2","3-9","11","12","13-19") + npbc_core.validate_undelivered_string("1","2","3-9","11","12","13-19","21","22","23-29") + npbc_core.validate_undelivered_string("1","2","3-9","11","12","13-19","21","22","23-29","31") + npbc_core.validate_undelivered_string("1","2","3","4","5","6","7","8","9") + npbc_core.validate_undelivered_string("mondays") + npbc_core.validate_undelivered_string("mondays,tuesdays") + npbc_core.validate_undelivered_string("mondays","tuesdays","wednesdays") + npbc_core.validate_undelivered_string("mondays","5-21") + npbc_core.validate_undelivered_string("mondays","5-21","tuesdays","5-21") + npbc_core.validate_undelivered_string("1-monday") + npbc_core.validate_undelivered_string("2-monday") + npbc_core.validate_undelivered_string("all") + npbc_core.validate_undelivered_string("All") + npbc_core.validate_undelivered_string("aLl") + npbc_core.validate_undelivered_string("alL") + npbc_core.validate_undelivered_string("aLL") + npbc_core.validate_undelivered_string("ALL") def test_undelivered_string_parsing(): MONTH = 5 YEAR = 2017 - test_function = npbc_core.parse_undelivered_strings - assert test_function(MONTH, YEAR, '') == set(()) + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '') == set(()) - assert test_function(MONTH, YEAR, '1') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '1') == set(( date(year=YEAR, month=MONTH, day=1), )) - assert test_function(MONTH, YEAR, '1-2') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '1-2') == set(( date(year=YEAR, month=MONTH, day=1), date(year=YEAR, month=MONTH, day=2) )) - assert test_function(MONTH, YEAR, '5-17') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '5-17') == set(( date(year=YEAR, month=MONTH, day=5), date(year=YEAR, month=MONTH, day=6), date(year=YEAR, month=MONTH, day=7), @@ -97,7 +92,7 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=17) )) - assert test_function(MONTH, YEAR, '5-17', '19') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '5-17', '19') == set(( date(year=YEAR, month=MONTH, day=5), date(year=YEAR, month=MONTH, day=6), date(year=YEAR, month=MONTH, day=7), @@ -114,7 +109,7 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=19) )) - assert test_function(MONTH, YEAR, '5-17', '19-21') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '5-17', '19-21') == set(( date(year=YEAR, month=MONTH, day=5), date(year=YEAR, month=MONTH, day=6), date(year=YEAR, month=MONTH, day=7), @@ -133,7 +128,7 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=21) )) - assert test_function(MONTH, YEAR, '5-17', '19-21', '23') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '5-17', '19-21', '23') == set(( date(year=YEAR, month=MONTH, day=5), date(year=YEAR, month=MONTH, day=6), date(year=YEAR, month=MONTH, day=7), @@ -153,7 +148,7 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=23) )) - assert test_function(MONTH, YEAR, 'mondays') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, 'mondays') == set(( date(year=YEAR, month=MONTH, day=1), date(year=YEAR, month=MONTH, day=8), date(year=YEAR, month=MONTH, day=15), @@ -161,7 +156,7 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=29) )) - assert test_function(MONTH, YEAR, 'mondays', 'wednesdays') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, 'mondays', 'wednesdays') == set(( date(year=YEAR, month=MONTH, day=1), date(year=YEAR, month=MONTH, day=8), date(year=YEAR, month=MONTH, day=15), @@ -174,11 +169,11 @@ def test_undelivered_string_parsing(): date(year=YEAR, month=MONTH, day=31) )) - assert test_function(MONTH, YEAR, '2-monday') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '2-monday') == set(( date(year=YEAR, month=MONTH, day=8), )) - assert test_function(MONTH, YEAR, '2-monday', '3-wednesday') == set(( + assert npbc_core.parse_undelivered_strings(MONTH, YEAR, '2-monday', '3-wednesday') == set(( date(year=YEAR, month=MONTH, day=8), date(year=YEAR, month=MONTH, day=17) )) @@ -192,22 +187,20 @@ def test_calculating_cost_of_one_paper(): array((False, False, True, True, True, False, True)) ) - test_function = npbc_core.calculate_cost_of_one_paper - - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(()), *COST_AND_DELIVERY_DATA ) == 41 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(()), array((0, 0, 2, 2, 5, 0, 1)), array((False, False, True, True, True, False, False)) ) == 36 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=8), @@ -215,7 +208,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 41 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=8), @@ -224,7 +217,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 41 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=8), @@ -233,7 +226,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 41 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=2), @@ -241,7 +234,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 40 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=2), @@ -250,7 +243,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 40 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=6), @@ -259,7 +252,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 34 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=6), @@ -269,7 +262,7 @@ def test_calculating_cost_of_one_paper(): *COST_AND_DELIVERY_DATA ) == 34 - assert test_function( + assert npbc_core.calculate_cost_of_one_paper( DAYS_PER_WEEK, set(( date(year=2022, month=1, day=6), @@ -285,23 +278,21 @@ def test_calculating_cost_of_one_paper(): def test_validate_month_and_year(): - test_function = npbc_core.validate_month_and_year - - test_function(1, 2020) - test_function(12, 2020) - test_function(1, 2021) - test_function(12, 2021) - test_function(1, 2022) - test_function(12, 2022) + npbc_core.validate_month_and_year(1, 2020) + npbc_core.validate_month_and_year(12, 2020) + npbc_core.validate_month_and_year(1, 2021) + npbc_core.validate_month_and_year(12, 2021) + npbc_core.validate_month_and_year(1, 2022) + npbc_core.validate_month_and_year(12, 2022) with raises(InvalidMonthYear): - test_function(-54, 2020) - test_function(0, 2020) - test_function(13, 2020) - test_function(45, 2020) - test_function(1, -5) - test_function(12, -5) - test_function(1.6, 10) # type: ignore - test_function(12.6, 10) # type: ignore - test_function(1, '10') # type: ignore - test_function(12, '10') # type: ignore + npbc_core.validate_month_and_year(-54, 2020) + npbc_core.validate_month_and_year(0, 2020) + npbc_core.validate_month_and_year(13, 2020) + npbc_core.validate_month_and_year(45, 2020) + npbc_core.validate_month_and_year(1, -5) + npbc_core.validate_month_and_year(12, -5) + npbc_core.validate_month_and_year(1.6, 10) # type: ignore + npbc_core.validate_month_and_year(12.6, 10) # type: ignore + npbc_core.validate_month_and_year(1, '10') # type: ignore + npbc_core.validate_month_and_year(12, '10') # type: ignore From d311deaf78da3c349ea4e23bd3f79d62e6d2db89 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Wed, 13 Jul 2022 20:46:14 +0000 Subject: [PATCH 3/3] use returns --- npbc_cli.py | 18 ++++++++++++++++++ npbc_core.py | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/npbc_cli.py b/npbc_cli.py index e1bfab5..3aec94e 100644 --- a/npbc_cli.py +++ b/npbc_cli.py @@ -180,6 +180,8 @@ def status_print(success: bool, message: str) -> None: colour = Fore.GREEN if success else Fore.RED print(f"{colour}{Style.BRIGHT}{message}{Style.RESET_ALL}\n") + return + def calculate(parsed_arguments: ArgNamespace, connection: Connection) -> None: """calculate the cost for a given month and year @@ -267,6 +269,7 @@ def calculate(parsed_arguments: ArgNamespace, connection: Connection) -> None: # print the results status_print(True, "Success!") print(f"SUMMARY:\n\n{formatted}") + return def addudl(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -315,6 +318,7 @@ def addudl(parsed_arguments: ArgNamespace, connection: Connection) -> None: return status_print(True, "Success!") + return def deludl(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -356,6 +360,7 @@ def deludl(parsed_arguments: ArgNamespace, connection: Connection) -> None: return status_print(True, "Success!") + return def getudl(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -399,6 +404,8 @@ def getudl(parsed_arguments: ArgNamespace, connection: Connection) -> None: for items in undelivered_strings: print(', '.join([str(item) for item in items])) + return + def extract_delivery_from_user_input(input_delivery: str) -> list[bool]: """convert the /[YN]{7}/ user input to a Boolean list""" @@ -499,6 +506,7 @@ def editpaper(parsed_arguments: ArgNamespace, connection: Connection) -> None: return status_print(True, "Success!") + return def addpaper(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -532,6 +540,7 @@ def addpaper(parsed_arguments: ArgNamespace, connection: Connection) -> None: return status_print(True, "Success!") + return def delpaper(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -552,6 +561,7 @@ def delpaper(parsed_arguments: ArgNamespace, connection: Connection) -> None: return status_print(True, "Success!") + return def getpapers(parsed_arguments: ArgNamespace, connection: Connection) -> None: @@ -661,6 +671,8 @@ def getpapers(parsed_arguments: ArgNamespace, connection: Connection) -> None: print() + return + def getlogs(parsed_arguments: ArgNamespace, connection: Connection) -> None: """get a list of all logs in the database @@ -699,6 +711,8 @@ def getlogs(parsed_arguments: ArgNamespace, connection: Connection) -> None: for row in data: print(', '.join(str(item) for item in row)) + return + def update(parsed_arguments: ArgNamespace, _: Connection) -> None: """update the application @@ -706,6 +720,7 @@ def update(parsed_arguments: ArgNamespace, _: Connection) -> None: - if the update CLI argument is provided, this script will never run and the updater will be run instead""" status_print(False, "Update failed.") + return def init(parsed_arguments: ArgNamespace, _: Connection) -> None: @@ -713,6 +728,7 @@ def init(parsed_arguments: ArgNamespace, _: Connection) -> None: - this function should run only once, when the application is first installed""" status_print(True, "Initialized successfully.") + return def main(arguments: list[str]) -> None: @@ -743,6 +759,8 @@ def main(arguments: list[str]) -> None: finally: connection.close() # type: ignore + return + if __name__ == "__main__": main(argv[1:]) diff --git a/npbc_core.py b/npbc_core.py index 76e755c..1483ada 100644 --- a/npbc_core.py +++ b/npbc_core.py @@ -65,17 +65,17 @@ def get_number_of_each_weekday(month: int, year: int) -> Generator[int, None, No number_of_weeks = len(main_calendar) # iterate over each possible weekday - for i in range(len(WEEKDAY_NAMES)): + for weekday_index in range(len(WEEKDAY_NAMES)): # assume that the weekday occurs once per week in the month number_of_weekday: int = number_of_weeks # if the first week doesn't have the weekday, decrement its count - if main_calendar[0][i] == 0: + if main_calendar[0][weekday_index] == 0: number_of_weekday -= 1 # if the last week doesn't have the weekday, decrement its count - if main_calendar[-1][i] == 0: + if main_calendar[-1][weekday_index] == 0: number_of_weekday -= 1 yield number_of_weekday @@ -101,6 +101,7 @@ def validate_undelivered_string(*strings: str) -> None: raise npbc_exceptions.InvalidUndeliveredString(f'{string} is not a valid undelivered string.') # if we get here, all strings passed the regex check + return def extract_number(string: str, month: int, year: int) -> date: """if the date is simply a number, it's a single day. so we just identify that date""" @@ -220,18 +221,18 @@ def parse_undelivered_strings(month: int, year: int, *strings: str) -> set[date] # check for each of the patterns for string in strings: if string: - try: - dates.update(parse_undelivered_string(month, year, string)) + try: + dates.update(parse_undelivered_string(month, year, string)) except npbc_exceptions.InvalidUndeliveredString as e: - print( - f"""Congratulations! You broke the program! - You managed to write a string that the program considers valid, but isn't actually. - Please report it to the developer. - \nThe string you wrote was: {string} + print( + f"""Congratulations! You broke the program! + You managed to write a string that the program considers valid, but isn't actually. + Please report it to the developer. + \nThe string you wrote was: {string} This data has not been counted.\n Exact error message: {e}""" - ) + ) return dates @@ -375,6 +376,8 @@ def save_results( (log_ids[paper_id], day.strftime("%Y-%m-%d")) ) + return + def format_output(connection: Connection, costs: dict[int, float], total: float, month: int, year: int) -> Generator[str, None, None]: """format the output of calculating the cost of all papers""" @@ -416,6 +419,8 @@ def add_new_paper(connection: Connection, name: str, days_delivered: list[bool], (paper_id, day_id, delivered, cost) ) + return + def edit_existing_paper( connection: Connection, @@ -457,6 +462,8 @@ def edit_existing_paper( (delivered, paper_id, day_id) ) + return + def delete_existing_paper(connection: Connection, paper_id: int) -> None: """delete an existing paper @@ -481,6 +488,8 @@ def delete_existing_paper(connection: Connection, paper_id: int) -> None: (paper_id,) ) + return + def add_undelivered_string(connection: Connection, month: int, year: int, paper_id: int | None = None, *undelivered_strings: str) -> None: """record strings for date(s) paper(s) were not delivered @@ -526,6 +535,8 @@ def add_undelivered_string(connection: Connection, month: int, year: int, paper_ connection.executemany("INSERT INTO undelivered_strings (month, year, paper_id, string) VALUES (?, ?, ?, ?);", params) + return + def delete_undelivered_string( connection: Connection, @@ -583,6 +594,8 @@ def delete_undelivered_string( connection.execute(f"{delete_query} WHERE {conditions};", values) + return + def get_papers(connection: Connection) -> tuple[Papers]: """get all papers @@ -617,7 +630,7 @@ def get_undelivered_strings( """get undelivered strings - the user may specify as many as they want parameters - available parameters: string_id, month, year, paper_id, string - - returns a list of tuples containing the following fields: + - returns a tuple of tuples containing the following fields: string_id, paper_id, year, month, string""" # initialize parameters for the WHERE clause of the SQL query @@ -764,3 +777,6 @@ def validate_month_and_year(month: int | None = None, year: int | None = None) - if isinstance(year, int) and (year <= 0): raise npbc_exceptions.InvalidMonthYear("Year must be greater than 0.") + + # if we get here, the month and year are valid + return