Skip to content

Commit

Permalink
Enhancement: Clean up test cases (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
FragmentedPacket authored and jmcgill298 committed Nov 26, 2019
1 parent 8298de4 commit f835e75
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions templates/index
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ cisco_nxos_show_interfaces_switchport.template, .*, cisco_nxos, sh[[ow]] int[[er
cisco_nxos_show_ip_dhcp_relay_address.template, .*, cisco_nxos, sh[[ow]] ip dh[[cp]] r[[elay]] a[[ddress]]
cisco_nxos_show_lldp_neighbors_detail.template, .*, cisco_nxos, sh[[ow]] ll[[dp]] nei[[ghbors]] d[[etail]]
cisco_nxos_show_cdp_neighbors_detail.template, .*, cisco_nxos, sh[[ow]] c[[dp]] neig[[hbors]] det[[ail]]
cisco_nxos_show_ip_ospf_neighbor_vrf.template, .*, cisco_nxos, sh[[ow]] ip ospf nei[[ghbor]] vrf (\S+)
cisco_nxos_show_ipv6_interface_brief.template, .*, cisco_nxos, sh[[ow]] ipv[[6]] interf[[ace]] b[[rief]]
cisco_nxos_show_port-channel_summary.template, .*, cisco_nxos, sh[[ow]] po[[rt-channel]] sum[[mary]]
cisco_nxos_show_cts_interface_brief.template, .*, cisco_nxos, sh[[ow]] cts inte[[rface]] br[[ief]]
Expand All @@ -219,6 +218,7 @@ cisco_nxos_show_mac_address-table.template, .*, cisco_nxos, sh[[ow]] m[[ac]] add
cisco_nxos_show_interface_status.template, .*, cisco_nxos, sh[[ow]] int[[erface]] st[[atus]]
cisco_nxos_show_ip_bgp_neighbors.template, .*, cisco_nxos, sh[[ow]] ip bgp nei[[ghbors]]
cisco_nxos_show_ip_ospf_database.template, .*, cisco_nxos, sh[[ow]] ip o[[spf]] d[[atabase]]
cisco_nxos_show_ip_ospf_neighbor.template, .*, cisco_nxos, sh[[ow]] ip ospf nei[[ghbor]]
cisco_nxos_show_interface_brief.template, .*, cisco_nxos, sh[[ow]] int[[erface]] br[[ief]]
cisco_nxos_show_flogi_database.template, .*, cisco_nxos, sh[[ow]] fl[[ogi]] d[[atabase]]
cisco_nxos_show_ip_bgp_summary.template, .*, cisco_nxos, sh[[ow]] ip b[[gp]] s[[ummary]]
Expand Down Expand Up @@ -273,6 +273,7 @@ cisco_xr_show_dhcp_ipv4_proxy_binding.template, .*, cisco_xr, sh[[ow]] dh[[cp]]
cisco_xr_show_mpls_ldp_neighbor_brief.template, .*, cisco_xr, sh[[ow]] mp[[ls]] ld[[p]] neigh[[bor]] br[[ief]]
cisco_xr_admin_show_environment_fan.template, .*, cisco_xr, adm[[in]] sh[[ow]] env[[ironment]] f[[an]]
cisco_xr_show_cdp_neighbors_detail.template, .*, cisco_xr, sh[[ow]] c[[dp]] neig[[hbors]] det[[ail]]
cisco_xr_show_controllers_all_phy.template, .*, cisco_xr, sh[[ow]] contr[[ollers]] (\S+) ph[[y]]
cisco_xr_show_cef_drops_location.template, .*, cisco_xr, sh[[ow]] cef drops loc[[ation]]
cisco_xr_show_ip_interface_brief.template, .*, cisco_xr, sh[[ow]] ip int[[erface]] br[[ief]]
cisco_xr_show_redundancy_summary.template, .*, cisco_xr, sh[[ow]] redun[[dancy]] summ[[ary]]
Expand All @@ -290,7 +291,6 @@ cisco_xr_show_processes_cpu.template, .*, cisco_xr, sh[[ow]] proc[[esses]] c[[pu
cisco_xr_show_bfd_sessions.template, .*, cisco_xr, sh[[ow]] bf[[d]] sess[[ions]]
cisco_xr_show_drops_np_all.template, .*, cisco_xr, sh[[ow]] drops np all
cisco_xr_show_pim_neighbor.template, .*, cisco_xr, sh[[ow]] pi[[m]] neigh[[bor]]
cisco_xr_show_controllers.template, .*, cisco_xr, sh[[ow]] contr[[ollers]] (\S+) phy
cisco_xr_show_interfaces.template, .*, cisco_xr, sh[[ow]] inte[[rfaces]]
cisco_xr_admin_show_vm.template, .*, cisco_xr, adm[[in]] sh[[ow]] vm
cisco_xr_show_ip_route.template, .*, cisco_xr, sh[[ow]] (?:ip )?ro[[ute]]
Expand Down
6 changes: 1 addition & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

def load_index_data():
"""Load data from index file."""
index_data = []
with open("{0}{1}index".format(_get_template_dir(), os.sep)) as indexfs:
data = csv.reader(indexfs)
for row in data:
if len(row) > 2 and row[0] != "Template":
index_data.append(row)
return index_data
return [row for row in data if len(row) > 2 and row[0] != "Template"]
44 changes: 24 additions & 20 deletions tests/test_testcases_exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@
import os
import glob
import re
import pytest

from tests import load_index_data


KNOWN_MISSING_TESTS = {
"cisco_ios_show_vlan",
"cisco_nxos_show_interface_brief",
"cisco_nxos_show_ip_ospf_neighbor_vrf",
"cisco_xr_show_controllers",
}
TEST_DIRECTORIES = os.listdir("tests")


def test_verify_parsed_and_reference_data_exists():
"""Verify that at least one test exists for all entries in the index file.
TODO:
Add test cases for ``KNOWN_MISSING_TESTS`` and remove related conditional.
Remove "_ssh" from ``cisco_wlc_ssh`` and rely on vendor_platform_command syntax
instead of using regex on the directories.
def extract_index_data():
"""Used to parametrize and report each test case with the necessary data.
"""
index = sorted(load_index_data())
mock_directories = []
for row in index:
# Trim template name to only parts making up platform and command directories
template = row[0].strip()
template_short = template.split(".template")[0]
# Get RegEx pattern to strip platform from template name
platform = row[2].strip()
for directory in os.listdir("tests"):
# The platform attribute is a RegEx pattern,
# so need to loop through each platform looking to find a match
# in order to accurately derive platform name
for directory in TEST_DIRECTORIES:
if re.match(platform, directory):
platform_directory = directory
platform = directory
break
cut = len(platform_directory) + 1
cut = len(platform) + 1
command = template_short[cut:]
if template_short not in KNOWN_MISSING_TESTS:
cases = "tests/{0}/{1}/*.raw".format(platform_directory, command)
test_list = glob.glob(cases)
assert len(test_list) != 0, "Could not find tests for {0}".format(template)
mock_directories.append(f"tests/{platform}/{command}")
return mock_directories


@pytest.mark.parametrize("mock_directory", extract_index_data())
def test_verify_parsed_and_reference_data_exists(mock_directory):
"""Verify that at least one test exists for all entries in the index file.
"""
cases = f"{mock_directory}/*.raw"
test_list = glob.glob(cases)
assert len(test_list) != 0, f"Could not find tests for {mock_directory}.template"

0 comments on commit f835e75

Please sign in to comment.