summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-27 17:13:12 +0300
committerViljami Ilola <+@hix.fi>2024-04-27 17:13:12 +0300
commitaf8c7b959ae66ee529a18ef655f30bff022a5a80 (patch)
tree809b752647453229278c88b4aafd68778726180e
parent9f8247dc4da89219b6eede08d58d96964391a077 (diff)
tests for settings - v0.4b1
-rw-r--r--pyproject.toml2
-rw-r--r--src/sliceitoff/settings/settings.py2
-rw-r--r--tests/test_highscores.py4
-rw-r--r--tests/test_screens.py2
-rw-r--r--tests/test_settings.py65
5 files changed, 70 insertions, 5 deletions
diff --git a/pyproject.toml b/pyproject.toml
index 6f7a108..06fb9da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sliceitoff"
-version = "0.4-alpha1"
+version = "0.4-beta1"
description = "Arcade game where one slices play area off while avoiding slicing happy faces."
repository = "https://git.hix.fi/sliceitoff.git/"
authors = ["Viljami Ilola <+@hix.fi>"]
diff --git a/src/sliceitoff/settings/settings.py b/src/sliceitoff/settings/settings.py
index 48b754c..7ecfbf3 100644
--- a/src/sliceitoff/settings/settings.py
+++ b/src/sliceitoff/settings/settings.py
@@ -35,7 +35,7 @@ class Settings:
data = line.split('=')
if len(data) != 2:
return None
- return data[0], data[1]
+ return data[0].strip(), data[1].strip()
def get_values(self, option):
""" Gets all values for certain option """
diff --git a/tests/test_highscores.py b/tests/test_highscores.py
index 366d60f..58d7121 100644
--- a/tests/test_highscores.py
+++ b/tests/test_highscores.py
@@ -3,7 +3,7 @@ from pathlib import Path
import unittest
import pygame
-os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-hiscores-test"
+os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-settings-test"
from sliceitoff.settings import settings
from sliceitoff.hiscores import hi_scores
@@ -11,7 +11,7 @@ from sliceitoff.hiscores import hi_scores
class TestHiScores(unittest.TestCase):
def setUp(self):
- self.filename = Path("/tmp/sliceitoff-hiscores-test")
+ self.filename = Path("/tmp/sliceitoff-settings-test")
if self.filename.is_file():
self.filename.unlink()
diff --git a/tests/test_screens.py b/tests/test_screens.py
index 800dcd5..cd827d3 100644
--- a/tests/test_screens.py
+++ b/tests/test_screens.py
@@ -63,6 +63,6 @@ class TestScreens(unittest.TestCase):
page = mainmenu_screen(2)
self.assertEqual(TextPage, type(page))
- def test_can_run_mainmenu(self):
+ def test_can_run_settings(self):
page = settings_screen(2)
self.assertEqual(TextPage, type(page))
diff --git a/tests/test_settings.py b/tests/test_settings.py
new file mode 100644
index 0000000..49f00cc
--- /dev/null
+++ b/tests/test_settings.py
@@ -0,0 +1,65 @@
+import os
+from pathlib import Path
+import unittest
+import pygame
+
+os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-settings-test"
+from sliceitoff.settings import settings
+
+class TestSettings(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, settings)
+
+ def test_config_save_can_run(self):
+ settings.save()
+ if self.filename.is_file():
+ self.filename.unlink()
+
+ def test_can_add_value(self):
+ settings.put_value("testing", "666")
+ self.assertEqual(settings.get_value("testing"), "666")
+
+ def test_can_replace_value(self):
+ settings.put_value("testing2", "777")
+ settings.replace_value("testing2", "666")
+ self.assertEqual(settings.get_value("testing2"), "666")
+
+ def test_scores_can_be_saved(self):
+ settings.put_value("testing3", "just_test")
+ settings.save()
+ with open(self.filename, "r", encoding="utf-8") as cfile:
+ for line in cfile:
+ if line == "testing3=just_test\n":
+ break
+ else:
+ self.fail("Problem saving settings.")
+
+ def test_validate_line(self):
+ self.assertEqual(
+ ("option", "value"),
+ settings.validate_line("option=value\n"))
+
+ self.assertEqual(
+ ("option", "value"),
+ settings.validate_line("option = value\n"))
+
+ self.assertEqual(
+ None,
+ settings.validate_line("option = value = lol\n"))
+
+ self.assertEqual(
+ None,
+ settings.validate_line("# option=value\n"))
+
+ self.assertEqual(
+ None,
+ settings.validate_line("kamala lama\n"))