1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_ini.py

59 lines
1.9 KiB
Python
Raw Normal View History

2020-02-04 12:18:31 -08:00
import os
import unittest
import json
import jc.parsers.ini
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.ini'), 'r', encoding='utf-8') as f:
2020-02-04 12:18:31 -08:00
self.generic_ini_test = f.read()
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.ini'), 'r', encoding='utf-8') as f:
2020-02-04 12:18:31 -08:00
self.generic_ini_iptelserver = f.read()
# output
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.json'), 'r', encoding='utf-8') as f:
2020-02-04 12:18:31 -08:00
self.generic_ini_test_json = json.loads(f.read())
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.json'), 'r', encoding='utf-8') as f:
2020-02-04 12:18:31 -08:00
self.generic_ini_iptelserver_json = json.loads(f.read())
2020-06-10 17:54:06 -07:00
def test_ini_nodata(self):
"""
Test the test ini file with no data
"""
self.assertEqual(jc.parsers.ini.parse('', quiet=True), {})
2020-02-04 12:18:31 -08:00
def test_ini_test(self):
"""
Test the test ini file
"""
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_test, quiet=True), self.generic_ini_test_json)
def test_ini_iptelserver(self):
"""
Test the iptelserver ini file
"""
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_iptelserver, quiet=True), self.generic_ini_iptelserver_json)
2022-04-04 11:38:52 -07:00
def test_ini_duplicate_keys(self):
"""
Test input that contains duplicate keys. Only the last value should be used.
"""
data = '''
duplicate_key: value1
another_key = foo
duplicate_key = value2
'''
expected = {'duplicate_key': 'value2', 'another_key': 'foo'}
self.assertEqual(jc.parsers.ini.parse(data, quiet=True), expected)
2020-02-04 12:18:31 -08:00
if __name__ == '__main__':
unittest.main()