diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-10 18:04:27 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-10 18:04:27 +0300 |
commit | 6f2eeab32b08c75399c971a52238bdcdc16085b2 (patch) | |
tree | 6972e845a3351023d56e8e7e4882262722041b9b /tests/test_highscores.py | |
parent | 7b312aab1af3b2c67bc29df1faf46e39947b51fe (diff) |
tests for highscores
Diffstat (limited to 'tests/test_highscores.py')
-rw-r--r-- | tests/test_highscores.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_highscores.py b/tests/test_highscores.py new file mode 100644 index 0000000..26545f0 --- /dev/null +++ b/tests/test_highscores.py @@ -0,0 +1,39 @@ +import os +import unittest +import pygame + +from pathlib import Path + +from sliceitoff.hiscores import HiScores + +class TestHiScores(unittest.TestCase): + def setUp(self): + self.filename = "/tmp/sliceitoff-hiscores-test" + if os.path.isfile(self.filename): + os.remove(self.filename) + self.hiscores = HiScores(filename = self.filename) + + def tearDown(self): + try: + del self.hiscores + except AttributeError: + pass + if os.path.isfile(self.filename): + os.remove(self.filename) + + def test_can_create(self): + self.assertNotEqual(None, self.hiscores) + + def test_config_file_is_created_on_exit(self): + del self.hiscores + self.assertTrue(os.path.isfile(self.filename)) + + def test_scores_can_be_added(self): + self.hiscores.add(500_000,"HUH") + + def test_scores_can_be_saved(self): + self.hiscores.add(230_000,"HAH") + old_scores = str(self.hiscores) + del self.hiscores + self.hiscores = HiScores(filename = self.filename) + self.assertEqual(old_scores, str(self.hiscores)) |