Skip to content

Commit 28dc1d5

Browse files
Removed UTILITIES_UNIT_TESTING
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.
1 parent 735bccd commit 28dc1d5

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

pfc/main.py

-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
#!/usr/bin/env python3
22
import click
3-
import os
4-
import sys
53
from swsscommon.swsscommon import ConfigDBConnector
64
from tabulate import tabulate
75
from natsort import natsorted
86

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

12-
# mock the redis for unit test purposes #
13-
try:
14-
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
15-
modules_path = os.path.join(os.path.dirname(__file__), "..")
16-
tests_path = os.path.join(modules_path, "tests")
17-
sys.path.insert(0, modules_path)
18-
sys.path.insert(0, tests_path)
19-
except KeyError:
20-
pass
21-
2210

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

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

36-
if "UTILITIES_UNIT_TESTING" in os.environ and os.environ["UTILITIES_UNIT_TESTING"] == "2":
37-
self.showPfcAsym(interface)
38-
3924
def showPfcAsym(self, interface):
4025
"""
4126
PFC handler to display asymmetric PFC information.

tests/pfc_input/assert_show_output.py

-8
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@
7373
7474
"""
7575

76-
pfc_config_asymmetric = """\
77-
78-
Interface Asymmetric
79-
----------- ------------
80-
Ethernet0 on
81-
82-
"""
83-
8476
pfc_config_priority_on = """\
8577
8678
Interface Lossless priorities

tests/pfc_test.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import sys
33
import pfc.main as pfc
4-
from pfc_input.assert_show_output import pfc_cannot_find_intf, pfc_show_asymmetric_all, \
4+
from .pfc_input.assert_show_output import pfc_cannot_find_intf, pfc_show_asymmetric_all, \
55
pfc_show_asymmetric_intf, pfc_show_priority_all, pfc_show_priority_intf, \
6-
pfc_config_asymmetric, pfc_config_priority_on, pfc_asym_cannot_find_intf
6+
pfc_config_priority_on, pfc_asym_cannot_find_intf
77
from utilities_common.db import Db
88

99
from click.testing import CliRunner
@@ -18,37 +18,30 @@
1818

1919
class TestPfcBase(object):
2020

21-
@classmethod
22-
def setup_class(cls):
23-
print("SETUP")
24-
os.environ["PATH"] += os.pathsep + scripts_path
25-
os.environ['UTILITIES_UNIT_TESTING'] = "2"
26-
27-
def executor(self, cliobj, command, expected_rc=0, expected_output=None, runner=CliRunner()):
21+
def executor(self, cliobj, command, expected_rc=0, expected_output=None, expected_cfgdb_entry=None, runner=CliRunner()):
2822
db = Db()
2923
result = runner.invoke(cliobj, command, obj=db)
3024
print(result.exit_code)
3125
print(result.output)
3226

3327
if result.exit_code != expected_rc:
3428
print(result.exception)
35-
3629
assert result.exit_code == expected_rc
30+
3731
if expected_output:
3832
assert result.output == expected_output
3933

40-
@classmethod
41-
def teardown_class(cls):
42-
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
43-
os.environ["UTILITIES_UNIT_TESTING"] = "0"
44-
print("TEARDOWN")
34+
if expected_cfgdb_entry:
35+
(table, key, field, expected_val) = expected_cfgdb_entry
36+
configdb = db.cfgdb
37+
entry = configdb.get_entry(table, key)
38+
assert entry.get(field) == expected_val
4539

4640

4741
class TestPfc(TestPfcBase):
4842

4943
@classmethod
5044
def setup_class(cls):
51-
super().setup_class()
5245
from mock_tables import dbconnector
5346
from mock_tables import mock_single_asic
5447
reload(mock_single_asic)
@@ -80,7 +73,7 @@ def test_pfc_show_priority_intf_fake(self):
8073

8174
def test_pfc_config_asymmetric(self):
8275
self.executor(pfc.cli, ['config', 'asymmetric', 'on', 'Ethernet0'],
83-
expected_output=pfc_config_asymmetric)
76+
expected_cfgdb_entry=('PORT', 'Ethernet0', 'pfc_asym', 'on'))
8477

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

0 commit comments

Comments
 (0)