summaryrefslogtreecommitdiff
path: root/tests/test_highscores.py
blob: 048a42ceb4f6e5c1581da3689f321cf6a209faab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pathlib import Path
import unittest
import pygame

from sliceitoff.hiscores import HiScores

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)

    def test_config_file_is_created_on_exit(self):
        del self.hiscores
        self.assertTrue(self.filename.is_file())

    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))