diff --git a/pyproject.toml b/pyproject.toml index 4b514db..60aefd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ license = { file = "LICENSE" } dependencies = [] [project.optional-dependencies] -dev = ["pytest>=8"] +dev = ["pytest>=9,<10", "ruff>=0.16,<0.17", "mypy>=2.4,<3"] [tool.setuptools.packages.find] where = ["src"] @@ -20,3 +20,16 @@ where = ["src"] [tool.pytest.ini_options] testpaths = ["tests"] pythonpath = ["src"] + +[tool.ruff] +line-length = 88 + +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "FLY", "B"] + +[tool.ruff.lint.per-file-ignores] +"src/higher_lower/game_data.py" = ["E501"] # assignment data kept verbatim + +[tool.mypy] +strict = true +mypy_path = "src" diff --git a/src/higher_lower/art.py b/src/higher_lower/art.py index bd09c03..ed221f8 100644 --- a/src/higher_lower/art.py +++ b/src/higher_lower/art.py @@ -9,23 +9,37 @@ string, so Doxygen does not read the backticks in the art as markup. ## The game logo. logo = ( "\n" - r" __ ___ __ " "\n" - r" / / / (_)___ _/ /_ ___ _____" "\n" - r" / /_/ / / __ `/ __ \/ _ \/ ___/" "\n" - r" / __ / / /_/ / / / / __/ / " "\n" - r"/_/ ///_/\__, /_/ /_/\___/_/ " "\n" - r" / / /____/_ _____ _____" "\n" - r" / / / __ \ | /| / / _ \/ ___/" "\n" - r" / /___/ /_/ / |/ |/ / __/ / " "\n" - r"/_____/\____/|__/|__/\___/_/ " "\n" + r" __ ___ __ " + "\n" + r" / / / (_)___ _/ /_ ___ _____" + "\n" + r" / /_/ / / __ `/ __ \/ _ \/ ___/" + "\n" + r" / __ / / /_/ / / / / __/ / " + "\n" + r"/_/ ///_/\__, /_/ /_/\___/_/ " + "\n" + r" / / /____/_ _____ _____" + "\n" + r" / / / __ \ | /| / / _ \/ ___/" + "\n" + r" / /___/ /_/ / |/ |/ / __/ / " + "\n" + r"/_____/\____/|__/|__/\___/_/ " + "\n" ) ## The "vs" shown between the two accounts. vs = ( "\n" - r" _ __ " "\n" - r"| | / /____" "\n" - r"| | / / ___/" "\n" - r"| |/ (__ ) " "\n" - r"|___/____(_)" "\n" + r" _ __ " + "\n" + r"| | / /____" + "\n" + r"| | / / ___/" + "\n" + r"| |/ (__ ) " + "\n" + r"|___/____(_)" + "\n" ) diff --git a/src/higher_lower/constants.py b/src/higher_lower/constants.py index 90574fc..cfd1993 100644 --- a/src/higher_lower/constants.py +++ b/src/higher_lower/constants.py @@ -2,11 +2,13 @@ @brief Constants shared by the game modules. """ +from typing import Final + ## Keys of an account dictionary. -KEY_NAME = "name" -KEY_FOLLOWER_COUNT = "follower_count" -KEY_DESCRIPTION = "description" -KEY_COUNTRY = "country" +KEY_NAME: Final = "name" +KEY_FOLLOWER_COUNT: Final = "follower_count" +KEY_DESCRIPTION: Final = "description" +KEY_COUNTRY: Final = "country" ## The two choices the player can type, in lower case. CHOICE_A = "a" diff --git a/src/higher_lower/game_logic.py b/src/higher_lower/game_logic.py index c28223d..a8c5260 100644 --- a/src/higher_lower/game_logic.py +++ b/src/higher_lower/game_logic.py @@ -1,5 +1,5 @@ """@file game_logic.py -@brief Pure functions of the game: drawing accounts, describing them and checking guesses. +@brief Pure game functions: draw accounts, describe them, check guesses. """ import random @@ -9,9 +9,9 @@ from higher_lower.constants import ( ACCOUNT_TEMPLATE, CHOICE_A, CHOICE_B, + KEY_COUNTRY, KEY_DESCRIPTION, KEY_NAME, - KEY_COUNTRY, ) from higher_lower.game_data import Account, data diff --git a/tests/test_game.py b/tests/test_game.py index 427f9d1..285a3aa 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -14,20 +14,37 @@ from higher_lower.game import ask_choice, play_game, show_round from higher_lower.game_data import Account ACCOUNTS: list[Account] = [ - {"name": "First", "follower_count": 30, "description": "Test one", "country": "Denmark"}, - {"name": "Second", "follower_count": 20, "description": "Test two", "country": "Norway"}, - {"name": "Third", "follower_count": 10, "description": "Test three", "country": "Sweden"}, + { + "name": "First", + "follower_count": 30, + "description": "Test one", + "country": "Denmark", + }, + { + "name": "Second", + "follower_count": 20, + "description": "Test two", + "country": "Norway", + }, + { + "name": "Third", + "follower_count": 10, + "description": "Test three", + "country": "Sweden", + }, ] class FirstRng(random.Random): - """@brief Random generator that always takes the first entries, so a game is fixed.""" + """@brief Random generator that takes the first entries, so a game is fixed.""" - def sample(self, population: Sequence, k: int, **kwargs: object) -> list: # type: ignore[override] + def sample( # type: ignore[override] + self, population: Sequence[Account], k: int, **kwargs: object + ) -> list[Account]: """@brief Return the first k entries.""" return list(population)[:k] - def choice(self, seq: Sequence) -> Account: # type: ignore[override] + def choice(self, seq: Sequence[Account]) -> Account: # type: ignore[override] """@brief Return the first entry.""" return seq[0] diff --git a/tests/test_game_logic.py b/tests/test_game_logic.py index b153b65..5c6b0fb 100644 --- a/tests/test_game_logic.py +++ b/tests/test_game_logic.py @@ -58,8 +58,7 @@ def test_format_data_describes_the_account() -> None: "country": "United States", } assert ( - format_data(account) - == "Nike, a Sportswear multinational, from United States" + format_data(account) == "Nike, a Sportswear multinational, from United States" )