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

71 lines
2.7 KiB
Python
Raw Normal View History

2021-02-10 10:47:56 -08:00
import os
import json
import unittest
import jc.parsers.hciconfig
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
2022-09-23 10:58:28 -07:00
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig.out'), 'r', encoding='utf-8') as f:
centos_7_7_hciconfig = f.read()
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig-a.out'), 'r', encoding='utf-8') as f:
centos_7_7_hciconfig_a = f.read()
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig.out'), 'r', encoding='utf-8') as f:
ubuntu_20_4_hciconfig = f.read()
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig-a.out'), 'r', encoding='utf-8') as f:
ubuntu_20_4_hciconfig_a = f.read()
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig.json'), 'r', encoding='utf-8') as f:
centos_7_7_hciconfig_json = json.loads(f.read())
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig-a.json'), 'r', encoding='utf-8') as f:
centos_7_7_hciconfig_a_json = json.loads(f.read())
2021-02-10 10:47:56 -08:00
2022-09-23 10:58:28 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig.json'), 'r', encoding='utf-8') as f:
ubuntu_20_4_hciconfig_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig-a.json'), 'r', encoding='utf-8') as f:
ubuntu_20_4_hciconfig_a_json = json.loads(f.read())
2021-02-10 10:47:56 -08:00
def test_hciconfig_nodata(self):
"""
Test plain 'hciconfig' with no data
"""
self.assertEqual(jc.parsers.hciconfig.parse('', quiet=True), [])
def test_hciconfig_centos_7_7(self):
"""
Test plain 'hciconfig' on Centos 7.7
"""
self.assertEqual(jc.parsers.hciconfig.parse(self.centos_7_7_hciconfig, quiet=True), self.centos_7_7_hciconfig_json)
def test_hciconfig_a_centos_7_7(self):
"""
Test 'hciconfig -a' on Centos 7.7
"""
self.assertEqual(jc.parsers.hciconfig.parse(self.centos_7_7_hciconfig_a, quiet=True), self.centos_7_7_hciconfig_a_json)
def test_hciconfig_ubuntu_18_4(self):
"""
Test plain 'hciconfig' on Ubuntu 20.4
"""
self.assertEqual(jc.parsers.hciconfig.parse(self.ubuntu_20_4_hciconfig, quiet=True), self.ubuntu_20_4_hciconfig_json)
def test_hciconfig_a_ubuntu_18_4(self):
"""
Test 'hciconfig -a' on Ubuntu 20.4
"""
self.assertEqual(jc.parsers.hciconfig.parse(self.ubuntu_20_4_hciconfig_a, quiet=True), self.ubuntu_20_4_hciconfig_a_json)
if __name__ == '__main__':
unittest.main()