diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-27 17:13:12 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-27 17:13:12 +0300 |
commit | af8c7b959ae66ee529a18ef655f30bff022a5a80 (patch) | |
tree | 809b752647453229278c88b4aafd68778726180e /tests/test_settings.py | |
parent | 9f8247dc4da89219b6eede08d58d96964391a077 (diff) |
tests for settings - v0.4b1
Diffstat (limited to 'tests/test_settings.py')
-rw-r--r-- | tests/test_settings.py | 65 |
1 files changed, 65 insertions, 0 deletions
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")) |