import os from pathlib import Path import unittest import pygame os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-settings-test" from sliceitoff.settings import settings from sliceitoff.hiscores import hi_scores class TestHiScores(unittest.TestCase): def setUp(self): self.filename = Path("/tmp/sliceitoff-settings-test") if self.filename.is_file(): self.filename.unlink() def tearDown(self): if self.filename.is_file(): self.filename.unlink() def test_can_create(self): self.assertNotEqual(None, hi_scores) def test_config_save_can_run(self): hi_scores.save() def test_scores_can_be_added(self): hi_scores.add(500_000,"HUH") def test_scores_can_be_saved(self): 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)