Skip to content

Commit

Permalink
Fix CiscoRange() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Oct 22, 2023
1 parent f3f0060 commit 79ea1e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
53 changes: 34 additions & 19 deletions tests/test_Ccp_Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,41 +856,56 @@ def test_CiscoRange_18():
assert CiscoRange(uut_str).as_set(result_type=str) == result_correct


if False:
def test_CiscoRange_19():
"""Parse a string with a common prefix on all of the CiscoRange() inputs"""
result_correct = {
"interface Eth1/1", "interface Eth1/10", "interface Eth1/12",
"interface Eth1/13", "interface Eth1/14", "interface Eth1/15",
"interface Eth1/16", "interface Eth1/17", "interface Eth1/18",
"interface Eth1/19", "interface Eth1/20"
}
uut_str = "interface Eth1/1,interface Eth1/12-20,interface Eth1/16,interface Eth1/10"
assert isinstance(uut_str, str)
assert CiscoRange(uut_str).as_set(result_type=str) == result_correct
def test_CiscoRange_19():
"""Check that the exact results are correct for CiscoRange().as_set() with a redundant input ('Eth1/1')"""
result_correct = {
CiscoInterface("Eth1/1"),
CiscoInterface("Eth1/2"),
CiscoInterface("Eth1/3"),
CiscoInterface("Eth1/4"),
CiscoInterface("Eth1/5"),
CiscoInterface("Eth1/16"),
}
uut_str = "Eth1/1,Eth1/1-5,Eth1/16"
assert CiscoRange(uut_str).as_set() == result_correct

def test_CiscoRange_20():
"""Check that the exact results are correct for CiscoRange().as_list() with a redundant input ('Eth1/1')"""
result_correct = [
CiscoInterface("Eth1/1"),
CiscoInterface("Eth1/2"),
CiscoInterface("Eth1/3"),
CiscoInterface("Eth1/4"),
CiscoInterface("Eth1/5"),
CiscoInterface("Eth1/16"),
]
uut_str = "Eth1/1,Eth1/1-5,Eth1/16"
assert CiscoRange(uut_str).as_list() == result_correct

def test_CiscoRange_compressed_str_01():
"""compressed_str test with a very basic set of vlan numbers"""
uut_str = "1,2,911"
assert isinstance(uut_str, str)
assert CiscoRange(uut_str, result_type=str).as_compressed_str() == "1,2,911"
assert "2" in CiscoRange(uut_str).as_compressed_str()
assert "911" in CiscoRange(uut_str).as_compressed_str()

def test_CiscoRange_compressed_str_02():
"""compressed_str test with vlan number ranges"""
uut_str = "1,2, 3, 6, 7, 8 , 9, 911"
assert isinstance(uut_str, str)
assert CiscoRange(uut_str, result_type=str).as_compressed_str() == "1-3,6-9,911"


def test_CiscoRange_contains():
def test_CiscoRange_contains_01():
"""Check that the exact results are correct that a CiscoRange() contains an input"""
uut_str = "Ethernet1/1-20"
# Ethernet1/5 is in CiscoRange("Ethernet1/1-20")...
assert CiscoInterface("Ethernet1/5") in CiscoRange(uut_str)

def test_CiscoRange_contains_02():
"""Check that the exact results are correct that a CiscoRange() does not contain an input"""
uut_str = "Ethernet1/1-20"
assert isinstance(uut_str, str)
# Ethernet1/5 is in CiscoRange("Ethernet1/1-20")...
assert "1/1" in CiscoRange(uut_str).as_compressed_str()
assert "20" in CiscoRange(uut_str).as_compressed_str()
assert "Ethernet1/5" in CiscoRange(uut_str).as_list()
assert (CiscoInterface("Ethernet1/48") in CiscoRange(uut_str)) is False

#pragma warning restore S1192
#pragma warning restore S1313
Expand Down
20 changes: 10 additions & 10 deletions tests/test_Models_Cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

sys.path.insert(0, "..")

from ciscoconfparse.ccp_util import IPv4Obj, CiscoRange, CiscoInterface
from ciscoconfparse.errors import DynamicAddressException
from ciscoconfparse.ciscoconfparse import CiscoConfParse
from ciscoconfparse.ccp_util import IPv4Obj, CiscoRange
import pytest

from loguru import logger
Expand Down Expand Up @@ -281,8 +281,8 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_01():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert len(intf_obj.trunk_vlans_allowed.as_set(result_type=str)) == len(range(1, 4095))
assert intf_obj.trunk_vlans_allowed.as_set(result_type=str) == {str(ii) for ii in range(1, 4095)}
assert len(intf_obj.trunk_vlans_allowed.as_set(result_type=int)) == len(range(1, 4095))
assert intf_obj.trunk_vlans_allowed.as_list(result_type=int) == list(range(1, 4095))


def testVal_IOSIntfLine_trunk_vlan_allowed_02():
Expand All @@ -296,7 +296,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_02():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed.as_set(result_type=str) == {"2", "4", "6", "911"}
assert intf_obj.trunk_vlans_allowed.as_set(result_type=int) == {2, 4, 6, 911}


def testVal_IOSIntfLine_trunk_vlan_allowed_03():
Expand All @@ -311,7 +311,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_03():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed.as_set(result_type=str) == {"4", "6", "911"}
assert intf_obj.trunk_vlans_allowed.as_set(result_type=int) == {4, 6, 911}


def testVal_IOSIntfLine_trunk_vlan_allowed_04():
Expand All @@ -326,7 +326,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_04():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed.as_set(result_type=str) == {"1"}
assert intf_obj.trunk_vlans_allowed.as_set(result_type=int) == {1}


def testVal_IOSIntfLine_trunk_vlan_allowed_05():
Expand All @@ -341,7 +341,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_05():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed.as_set(result_type=str) == {"1",}
assert intf_obj.trunk_vlans_allowed.as_set(result_type=int) == {1,}


def testVal_IOSIntfLine_trunk_vlan_allowed_06():
Expand All @@ -357,7 +357,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_06():
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed == CiscoRange(text="2-5,17-19", result_type=str)
assert intf_obj.trunk_vlans_allowed.as_set(result_type=int) == {2,3,4,5,17,18,19}


def testVal_IOSIntfLine_trunk_vlan_allowed_07():
Expand All @@ -374,7 +374,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_07():
"""
cfg = CiscoConfParse(config.splitlines(), factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed == CiscoRange("2-19,21-4094", result_type=str)
assert intf_obj.trunk_vlans_allowed == CiscoRange("2-19,21-4094", result_type=int)


def testVal_IOSIntfLine_trunk_vlan_allowed_08():
Expand All @@ -387,7 +387,7 @@ def testVal_IOSIntfLine_trunk_vlan_allowed_08():
"""
cfg = CiscoConfParse(config.splitlines(), factory=True)
intf_obj = cfg.find_objects("^interface")[0]
assert intf_obj.trunk_vlans_allowed == CiscoRange(text="", result_type=str)
assert intf_obj.trunk_vlans_allowed == CiscoRange(text="", result_type=int)


def testVal_IOSIntfLine_abbvs(parse_c03_factory):
Expand Down

0 comments on commit 79ea1e9

Please sign in to comment.