diff --git a/pfc/main.py b/pfc/main.py index 6cc1e40fe7..f0b376e242 100644 --- a/pfc/main.py +++ b/pfc/main.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 import click -import os -import sys from swsscommon.swsscommon import ConfigDBConnector from tabulate import tabulate from natsort import natsorted @@ -9,16 +7,6 @@ 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): @@ -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. diff --git a/tests/pfc_input/assert_show_output.py b/tests/pfc_input/assert_show_output.py index 6adab2e0f0..2406f8b49f 100644 --- a/tests/pfc_input/assert_show_output.py +++ b/tests/pfc_input/assert_show_output.py @@ -73,14 +73,6 @@ """ -pfc_config_asymmetric = """\ - -Interface Asymmetric ------------ ------------ -Ethernet0 on - -""" - pfc_config_priority_on = """\ Interface Lossless priorities diff --git a/tests/pfc_test.py b/tests/pfc_test.py index 3f142eb35a..101aa476cc 100644 --- a/tests/pfc_test.py +++ b/tests/pfc_test.py @@ -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 @@ -18,13 +18,8 @@ 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) @@ -32,23 +27,22 @@ def executor(self, cliobj, command, expected_rc=0, expected_output=None, runner= 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) @@ -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'],