mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add tests for key/value files
This commit is contained in:
1
tests/fixtures/generic/keyvalue-ifcfg.json
vendored
Normal file
1
tests/fixtures/generic/keyvalue-ifcfg.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"type": "Ethernet", "proxy_method": "none", "browser_only": "no", "bootproto": "dhcp", "defroute": "yes", "ipv4_failure_fatal": "no", "ipv6init": "yes", "ipv6_autoconf": "yes", "ipv6_defroute": "yes", "ipv6_failure_fatal": "no", "ipv6_addr_gen_mode": "stable-privacy", "name": "ens33", "uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", "device": "ens33", "onboot": "yes", "value_with_spaces": "this value includes spaces", "value_with_quotes_inside": "this value \"has quotation marks\" inside", "value_with_quotes_inside2": "\"this value\" has quotations at the beginning but not the end", "value_with_quotes_inside3": "this value has quotation marks \"at the end\""}
|
19
tests/fixtures/generic/keyvalue-ifcfg.txt
vendored
Normal file
19
tests/fixtures/generic/keyvalue-ifcfg.txt
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
TYPE="Ethernet"
|
||||||
|
PROXY_METHOD="none"
|
||||||
|
BROWSER_ONLY="no"
|
||||||
|
BOOTPROTO="dhcp"
|
||||||
|
DEFROUTE="yes"
|
||||||
|
IPV4_FAILURE_FATAL="no"
|
||||||
|
IPV6INIT="yes"
|
||||||
|
IPV6_AUTOCONF="yes"
|
||||||
|
IPV6_DEFROUTE="yes"
|
||||||
|
IPV6_FAILURE_FATAL="no"
|
||||||
|
IPV6_ADDR_GEN_MODE="stable-privacy"
|
||||||
|
NAME="ens33"
|
||||||
|
UUID="d92ece08-9e02-47d5-b2d2-92c80e155744"
|
||||||
|
DEVICE="ens33"
|
||||||
|
ONBOOT="yes"
|
||||||
|
value_with_spaces: this value includes spaces
|
||||||
|
value_with_quotes_inside = this value "has quotation marks" inside
|
||||||
|
value_with_quotes_inside2 = "this value" has quotations at the beginning but not the end
|
||||||
|
value_with_quotes_inside3 : this value has quotation marks "at the end"
|
1
tests/fixtures/generic/keyvalue.json
vendored
Normal file
1
tests/fixtures/generic/keyvalue.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"value1": "hello", "value2": "true", "no_value": "", "value4": "3.14", "value5": "42"}
|
5
tests/fixtures/generic/keyvalue.txt
vendored
Normal file
5
tests/fixtures/generic/keyvalue.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
value1 = hello
|
||||||
|
value2 = true
|
||||||
|
no_value
|
||||||
|
value4 = 3.14
|
||||||
|
value5: 42
|
@ -16,6 +16,12 @@ 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:
|
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()
|
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
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.json'), 'r', encoding='utf-8') as f:
|
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())
|
self.generic_ini_test_json = json.loads(f.read())
|
||||||
@ -23,6 +29,12 @@ 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:
|
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())
|
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):
|
def test_ini_nodata(self):
|
||||||
"""
|
"""
|
||||||
Test the test ini file with no data
|
Test the test ini file with no data
|
||||||
@ -41,6 +53,18 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.ini.parse(self.generic_ini_iptelserver, quiet=True), self.generic_ini_iptelserver_json)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user