Skip to content

Commit

Permalink
Removed UTILITIES_UNIT_TESTING
Browse files Browse the repository at this point in the history
Removed the use of the environment variable to test `config asymmetric
on`. Instead replaced the validation method with a direct check for the
expected CONFIG_DB entry. Also removed the unnecessary classmethods in
TestPfcBase.
  • Loading branch information
kenneth-arista committed May 29, 2024
1 parent 735bccd commit cc424b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
15 changes: 0 additions & 15 deletions pfc/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
#!/usr/bin/env python3
import click
import os
import sys
from swsscommon.swsscommon import ConfigDBConnector
from tabulate import tabulate
from natsort import natsorted

ALL_PRIORITIES = [str(x) for x in range(8)]
PRIORITY_STATUS = ['on', 'off']

# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), "..")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
except KeyError:
pass


class Pfc(object):
def __init__(self, cfgdb=None):
Expand All @@ -33,9 +21,6 @@ def configPfcAsym(self, interface, pfc_asym):

configdb.mod_entry("PORT", interface, {'pfc_asym': pfc_asym})

if "UTILITIES_UNIT_TESTING" in os.environ and os.environ["UTILITIES_UNIT_TESTING"] == "2":
self.showPfcAsym(interface)

def showPfcAsym(self, interface):
"""
PFC handler to display asymmetric PFC information.
Expand Down
8 changes: 0 additions & 8 deletions tests/pfc_input/assert_show_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
"""

pfc_config_asymmetric = """\
Interface Asymmetric
----------- ------------
Ethernet0 on
"""

pfc_config_priority_on = """\
Interface Lossless priorities
Expand Down
28 changes: 11 additions & 17 deletions tests/pfc_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import sys
import pfc.main as pfc
from pfc_input.assert_show_output import pfc_cannot_find_intf, pfc_show_asymmetric_all, \
from .pfc_input.assert_show_output import pfc_cannot_find_intf, pfc_show_asymmetric_all, \
pfc_show_asymmetric_intf, pfc_show_priority_all, pfc_show_priority_intf, \
pfc_config_asymmetric, pfc_config_priority_on, pfc_asym_cannot_find_intf
pfc_config_priority_on, pfc_asym_cannot_find_intf
from utilities_common.db import Db

from click.testing import CliRunner
Expand All @@ -18,37 +18,31 @@

class TestPfcBase(object):

@classmethod
def setup_class(cls):
print("SETUP")
os.environ["PATH"] += os.pathsep + scripts_path
os.environ['UTILITIES_UNIT_TESTING'] = "2"

def executor(self, cliobj, command, expected_rc=0, expected_output=None, runner=CliRunner()):
def executor(self, cliobj, command, expected_rc=0, expected_output=None, expected_cfgdb_entry=None,
runner=CliRunner()):
db = Db()
result = runner.invoke(cliobj, command, obj=db)
print(result.exit_code)
print(result.output)

if result.exit_code != expected_rc:
print(result.exception)

assert result.exit_code == expected_rc

if expected_output:
assert result.output == expected_output

@classmethod
def teardown_class(cls):
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
print("TEARDOWN")
if expected_cfgdb_entry:
(table, key, field, expected_val) = expected_cfgdb_entry
configdb = db.cfgdb
entry = configdb.get_entry(table, key)
assert entry.get(field) == expected_val


class TestPfc(TestPfcBase):

@classmethod
def setup_class(cls):
super().setup_class()
from mock_tables import dbconnector
from mock_tables import mock_single_asic
reload(mock_single_asic)
Expand Down Expand Up @@ -80,7 +74,7 @@ def test_pfc_show_priority_intf_fake(self):

def test_pfc_config_asymmetric(self):
self.executor(pfc.cli, ['config', 'asymmetric', 'on', 'Ethernet0'],
expected_output=pfc_config_asymmetric)
expected_cfgdb_entry=('PORT', 'Ethernet0', 'pfc_asym', 'on'))

def test_pfc_config_priority(self):
self.executor(pfc.cli, ['config', 'priority', 'on', 'Ethernet0', '5'],
Expand Down

0 comments on commit cc424b4

Please sign in to comment.