aboutsummaryrefslogtreecommitdiff
path: root/src/match_up
diff options
context:
space:
mode:
Diffstat (limited to 'src/match_up')
-rw-r--r--src/match_up/__init__.py8
-rw-r--r--src/match_up/__main__.py4
-rw-r--r--src/match_up/model.py8
-rw-r--r--src/match_up/tests/__init__.py13
4 files changed, 29 insertions, 4 deletions
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py
index 7b30c1b..c9c3d0b 100644
--- a/src/match_up/__init__.py
+++ b/src/match_up/__init__.py
@@ -8,6 +8,12 @@ class PlaySession:
def __init__(self, database_location: PurePath):
self.data = PlayerDatabase(database_location)
+ def end(self):
+ self.data.close()
+
+ def __del__(self):
+ self.end()
+
def main():
generate_test_database()
@@ -15,5 +21,5 @@ def main():
for player in s.data.get_players():
print(player)
sleep(2)
- s.data._database.close()
+ s.end()
remove_test_database()
diff --git a/src/match_up/__main__.py b/src/match_up/__main__.py
new file mode 100644
index 0000000..3500cdb
--- /dev/null
+++ b/src/match_up/__main__.py
@@ -0,0 +1,4 @@
+from match_up import main
+
+if __name__ == "__main__":
+ main()
diff --git a/src/match_up/model.py b/src/match_up/model.py
index 1de0811..924e674 100644
--- a/src/match_up/model.py
+++ b/src/match_up/model.py
@@ -25,7 +25,7 @@ class PlayerDatabase:
first_name=row["first_name"],
last_name=row["last_name"],
skill=row["skill"],
- status=row["skill"],
+ status=row["status"],
wait_time=row["wait_time"],
)
)
@@ -57,3 +57,9 @@ class PlayerDatabase:
def deactivate_all_players(self) -> bool:
for row in self._database:
row["status"] = False
+
+ def close(self) -> None:
+ self._database.close()
+
+ def __del__(self):
+ self.close()
diff --git a/src/match_up/tests/__init__.py b/src/match_up/tests/__init__.py
index 0a2bd15..38e377f 100644
--- a/src/match_up/tests/__init__.py
+++ b/src/match_up/tests/__init__.py
@@ -1,15 +1,24 @@
from os import remove
+from random import randint
from pathlib import PurePath
from names import get_first_name, get_last_name
from match_up.model import Player, PlayerDatabase
TEST_DATABASE_LOCATION = PurePath("test_storage.json")
+MIN_SKILL = 1
+MAX_SKILL = 10
-def generate_test_database(total_players: int = 10) -> None:
+def generate_test_database(total_players: int = 20, active_players: int = 17) -> None:
p = PlayerDatabase(TEST_DATABASE_LOCATION)
for _ in range(total_players):
- p.add_player(Player(first_name=get_first_name(), last_name=get_last_name()))
+ p.add_player(
+ Player(
+ first_name=get_first_name(),
+ last_name=get_last_name(),
+ skill=randint(MIN_SKILL, MAX_SKILL),
+ )
+ )
def remove_test_database() -> None: