diff --git a/tests/assets/sample.ini b/tests/assets/sample.ini new file mode 100644 index 0000000..065ee46 --- /dev/null +++ b/tests/assets/sample.ini @@ -0,0 +1,13 @@ +[types] +float = 1.23 +int = 42 +string = Some text here + +[booleans] +bool_false = false +bool_true = true +switch_false = off +switch_true = on +yn_false = no +yn_true = yes + diff --git a/tests/base/__init__.py b/tests/base/__init__.py index f8734bc..6d70816 100644 --- a/tests/base/__init__.py +++ b/tests/base/__init__.py @@ -10,14 +10,16 @@ import unittest +from .test_cli import CLITestCase +from .test_config import ConfigTestCase from .test_db import DbTestCase from .test_scanner import ScannerTestCase from .test_watcher import suite as watcher_suite -from .test_cli import CLITestCase def suite(): suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(ConfigTestCase)) suite.addTest(unittest.makeSuite(DbTestCase)) suite.addTest(unittest.makeSuite(ScannerTestCase)) suite.addTest(watcher_suite()) diff --git a/tests/base/test_config.py b/tests/base/test_config.py new file mode 100644 index 0000000..8165175 --- /dev/null +++ b/tests/base/test_config.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# This file is part of Supysonic. +# Supysonic is a Python implementation of the Subsonic server API. +# +# Copyright (C) 2017 Alban 'spl0k' FĂ©ron +# +# Distributed under terms of the GNU AGPLv3 license. + +import unittest + +from supysonic.config import IniConfig + +class ConfigTestCase(unittest.TestCase): + def test_sections(self): + conf = IniConfig('tests/assets/sample.ini') + for attr in ('TYPES', 'BOOLEANS'): + self.assertTrue(hasattr(conf, attr)) + self.assertIsInstance(getattr(conf, attr), dict) + + def test_types(self): + conf = IniConfig('tests/assets/sample.ini') + + self.assertIsInstance(conf.TYPES['float'], float) + self.assertIsInstance(conf.TYPES['int'], int) + self.assertIsInstance(conf.TYPES['string'], basestring) + + for t in ('bool', 'switch', 'yn'): + self.assertIsInstance(conf.BOOLEANS[t + '_false'], bool) + self.assertIsInstance(conf.BOOLEANS[t + '_true'], bool) + self.assertFalse(conf.BOOLEANS[t + '_false']) + self.assertTrue(conf.BOOLEANS[t + '_true']) + +if __name__ == '__main__': + unittest.main() +