mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
update tests for kv parser
This commit is contained in:
@ -16,12 +16,6 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.ini'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_iptelserver = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.txt'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.txt'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_ifcfg = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_test_json = json.loads(f.read())
|
||||
@ -29,12 +23,6 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_iptelserver_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_ifcfg_json = json.loads(f.read())
|
||||
|
||||
def test_ini_nodata(self):
|
||||
"""
|
||||
Test the test ini file with no data
|
||||
@ -53,18 +41,6 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_iptelserver, quiet=True), self.generic_ini_iptelserver_json)
|
||||
|
||||
def test_ini_keyvalue(self):
|
||||
"""
|
||||
Test a file that only includes key/value lines
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_keyvalue, quiet=True), self.generic_ini_keyvalue_json)
|
||||
|
||||
def test_ini_keyvalue_ifcfg(self):
|
||||
"""
|
||||
Test a sample ifcfg key/value file that has quotation marks in the values
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_keyvalue_ifcfg, quiet=True), self.generic_ini_keyvalue_ifcfg_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
46
tests/test_kv.py
Normal file
46
tests/test_kv.py
Normal file
@ -0,0 +1,46 @@
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
import jc.parsers.kv
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# input
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.txt'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.txt'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_ifcfg = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ini_keyvalue_ifcfg_json = json.loads(f.read())
|
||||
|
||||
def test_kv_nodata(self):
|
||||
"""
|
||||
Test the test kv file with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.kv.parse('', quiet=True), {})
|
||||
|
||||
def test_kv_keyvalue(self):
|
||||
"""
|
||||
Test a file that only includes key/value lines
|
||||
"""
|
||||
self.assertEqual(jc.parsers.kv.parse(self.generic_ini_keyvalue, quiet=True), self.generic_ini_keyvalue_json)
|
||||
|
||||
def test_kv_keyvalue_ifcfg(self):
|
||||
"""
|
||||
Test a sample ifcfg key/value file that has quotation marks in the values
|
||||
"""
|
||||
self.assertEqual(jc.parsers.kv.parse(self.generic_ini_keyvalue_ifcfg, quiet=True), self.generic_ini_keyvalue_ifcfg_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user