1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_ipconfig.py
Jose E. Rodriguez a2e0e6d549 feat: Add Windows ipconfig parser to jc (#596)
* feat: Introduce ipconfig parser

* fix: add parsing support for "connection_specific_dns_suffix_search_list" and windows XP ipv4 addresses, remove dateutil dependency

* fix: introduce unit tests, correct import of datetime

* fix: changed preferred to status to account for other ip statuses, and parsed link local ipv6 prefix length

* fix: compress _parse_header_line and _parse_adapter_line + fix casing in unit test file

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-10-18 14:17:14 -07:00

49 lines
1.5 KiB
Python

import json
import os
import unittest
import jc.parsers.ipconfig
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
test_files = [
"tests/fixtures/windows/windows-xp/ipconfig",
"tests/fixtures/windows/windows-7/ipconfig",
"tests/fixtures/windows/windows-10/ipconfig",
"tests/fixtures/windows/windows-11/ipconfig",
"tests/fixtures/windows/windows-2008/ipconfig",
"tests/fixtures/windows/windows-2016/ipconfig",
]
def setUp(self):
for tf in MyTests.test_files:
in_file = os.path.join(THIS_DIR, os.pardir, f"{tf}.out")
out_file = os.path.join(THIS_DIR, os.pardir, f"{tf}.json")
with open(in_file, "r", encoding="utf-8") as f:
setattr(self, self.varName(tf), f.read())
with open(out_file, "r", encoding="utf-8") as f:
setattr(self, self.varName(tf) + "_json", json.loads(f.read()))
def varName(self, path):
return (
path.replace("tests/fixtures/windows", "")
.replace("-", "_")
.replace("/", "_")
)
def test_windows_ipconfig(self):
"""
Test a sample Windows "ipconfig" command output
"""
for tf in MyTests.test_files:
in_var = getattr(self, self.varName(tf))
out_var = getattr(self, self.varName(tf) + "_json")
self.assertEqual(jc.parsers.ipconfig.parse(in_var, quiet=True), out_var)
if __name__ == "__main__":
unittest.main()