summaryrefslogtreecommitdiff
path: root/tests/test_highscores.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_highscores.py')
-rw-r--r--tests/test_highscores.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/tests/test_highscores.py b/tests/test_highscores.py
index 048a42c..366d60f 100644
--- a/tests/test_highscores.py
+++ b/tests/test_highscores.py
@@ -1,37 +1,50 @@
+import os
from pathlib import Path
import unittest
import pygame
-from sliceitoff.hiscores import HiScores
+os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-hiscores-test"
+
+from sliceitoff.settings import settings
+from sliceitoff.hiscores import hi_scores
+
class TestHiScores(unittest.TestCase):
def setUp(self):
self.filename = Path("/tmp/sliceitoff-hiscores-test")
if self.filename.is_file():
self.filename.unlink()
- self.hiscores = HiScores(filename = self.filename)
def tearDown(self):
- try:
- del self.hiscores
- except AttributeError:
- pass
if self.filename.is_file():
self.filename.unlink()
def test_can_create(self):
- self.assertNotEqual(None, self.hiscores)
+ self.assertNotEqual(None, hi_scores)
- def test_config_file_is_created_on_exit(self):
- del self.hiscores
- self.assertTrue(self.filename.is_file())
+ def test_config_save_can_run(self):
+ hi_scores.save()
def test_scores_can_be_added(self):
- self.hiscores.add(500_000,"HUH")
+ hi_scores.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))
+ hi_scores.add(230_000,"ZAP")
+ hi_scores.save()
+ settings.save()
+ with open(self.filename, "r", encoding="utf-8") as cfile:
+ for line in cfile:
+ if line == "hiscore=230000!ZAP\n":
+ break
+ else:
+ self.fail("Problem saving hiscores.")
+
+ def test_high_enough(self):
+ for _ in range(20):
+ hi_scores.add(100_000,"LOL")
+ self.assertFalse( hi_scores.high_enough(99_999) )
+ self.assertFalse( hi_scores.high_enough(100_000) )
+ self.assertTrue( hi_scores.high_enough(100_001) )
+
+ def test_str_can_run(self):
+ str(hi_scores)