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

67 lines
2.3 KiB
Python
Raw Normal View History

2022-12-19 22:13:58 -05:00
import os
import json
import unittest
import jc.parsers.iwconfig
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class iwconfigTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig.out'), 'r', encoding='utf-8') as f:
iwconfig_output = f.read()
2022-12-19 22:13:58 -05:00
2022-12-21 17:25:57 -05:00
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-many.out'), 'r', encoding='utf-8') as f:
iwconfig_many_output = f.read()
2023-04-02 12:57:50 -07:00
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-space-dash-ssid.out'), 'r', encoding='utf-8') as f:
iwconfig_space_dash_ssid = f.read()
2022-12-19 22:13:58 -05:00
# output
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig.json'), 'r', encoding='utf-8') as f:
iwconfig_json = json.loads(f.read())
2022-12-19 22:13:58 -05:00
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-raw.json'), 'r', encoding='utf-8') as f:
iwconfig_raw_json = json.loads(f.read())
2022-12-19 22:36:48 -05:00
2022-12-21 17:25:57 -05:00
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-many.json'), 'r', encoding='utf-8') as f:
2023-04-02 12:57:50 -07:00
iwconfig_many_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-space-dash-ssid.json'), 'r', encoding='utf-8') as f:
iwconfig_space_dash_ssid_json = json.loads(f.read())
2022-12-21 17:25:57 -05:00
2022-12-19 22:36:48 -05:00
2022-12-19 22:13:58 -05:00
def test_iwconfig_nodata(self):
"""
Test 'iwconfig' with no data
"""
self.assertEqual(jc.parsers.iwconfig.parse('', quiet=True), [])
def test_iwconfig_raw(self):
2022-12-19 22:36:48 -05:00
"""
Test 'iwconfig' raw
2022-12-19 22:36:48 -05:00
"""
self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_output, quiet=True, raw=True), self.iwconfig_raw_json)
2022-12-19 22:36:48 -05:00
def test_iwconfig(self):
2022-12-19 22:13:58 -05:00
"""
Test 'iwconfig'
2022-12-19 22:13:58 -05:00
"""
self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_output, quiet=True), self.iwconfig_json)
2022-12-19 22:13:58 -05:00
2022-12-21 17:25:57 -05:00
def test_iwconfig_many(self):
"""
Test 'iwconfig' many interface
"""
self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_many_output, quiet=True), self.iwconfig_many_json)
2023-04-02 12:57:50 -07:00
def test_iwconfig_space_dash_ssid(self):
"""
Test 'iwconfig' many spaces and dashes in the SSID
"""
self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_space_dash_ssid, quiet=True), self.iwconfig_space_dash_ssid_json)
2022-12-19 22:13:58 -05:00
if __name__ == '__main__':
unittest.main()