1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

IniConfig tests

This commit is contained in:
spl0k 2017-12-10 18:22:03 +01:00
parent 332fd0446f
commit daf34271b4
3 changed files with 53 additions and 1 deletions

13
tests/assets/sample.ini Normal file
View File

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

View File

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

37
tests/base/test_config.py Normal file
View File

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