1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import os
import unittest
import json
import jc.parsers.iw_scan
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan0.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan0 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan1.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan1 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan2.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan2 = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan0.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan0_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan1.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan1_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan2.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan2_json = json.loads(f.read())
def test_iw_scan_nodata(self):
"""
Test 'iw_scan' parser with no data
"""
self.assertEqual(jc.parsers.iw_scan.parse('', quiet=True), [])
def test_iw_scan0_centos_7_7(self):
"""
Test 'iw_scan' on Centos 7.7
"""
self.assertEqual(jc.parsers.iw_scan.parse(self.centos_7_7_iw_scan0, quiet=True), self.centos_7_7_iw_scan0_json)
def test_iw_scan1_centos_7_7(self):
"""
Test 'iw_scan' on Centos 7.7
"""
self.assertEqual(jc.parsers.iw_scan.parse(self.centos_7_7_iw_scan1, quiet=True), self.centos_7_7_iw_scan1_json)
def test_iw_scan2_centos_7_7(self):
"""
Test 'iw_scan' on Centos 7.7
"""
self.assertEqual(jc.parsers.iw_scan.parse(self.centos_7_7_iw_scan2, quiet=True), self.centos_7_7_iw_scan2_json)
if __name__ == '__main__':
unittest.main()
|