Skip to content

Commit 52cb719

Browse files
committed
additiona unit test to cover show vlan
Signed-off-by: Guohan Lu <[email protected]>
1 parent 0fc783b commit 52cb719

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

show/main.py

-29
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,6 @@
3232

3333
VLAN_SUB_INTERFACE_SEPARATOR = '.'
3434

35-
try:
36-
# noinspection PyPep8Naming
37-
import ConfigParser as configparser
38-
except ImportError:
39-
# noinspection PyUnresolvedReferences
40-
import configparser
41-
42-
43-
# This is from the aliases example:
44-
# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py
45-
class Config(object):
46-
"""Object to hold CLI config"""
47-
48-
def __init__(self):
49-
self.path = os.getcwd()
50-
self.aliases = {}
51-
52-
def read_config(self, filename):
53-
parser = configparser.RawConfigParser()
54-
parser.read([filename])
55-
try:
56-
self.aliases.update(parser.items('aliases'))
57-
except configparser.NoSectionError:
58-
pass
59-
60-
61-
# Global Config object
62-
_config = None
63-
6435
# To be enhanced. Routing-stack information should be collected from a global
6536
# location (configdb?), so that we prevent the continous execution of this
6637
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.

tests/vlan_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def setup_class(cls):
107107
os.environ['UTILITIES_UNIT_TESTING'] = "1"
108108
print("SETUP")
109109

110+
def test_show_vlan(self):
111+
runner = CliRunner()
112+
result = runner.invoke(show.cli.commands["vlan"], [])
113+
print(result.exit_code)
114+
print(result.output)
115+
assert result.exit_code == 0
116+
110117
def test_show_vlan_brief(self):
111118
runner = CliRunner()
112119
result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [])

utilities_common/cli.py

+27
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ def get_command(self, ctx, cmd_name):
5151

5252
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
5353

54+
try:
55+
# noinspection PyPep8Naming
56+
import ConfigParser as configparser
57+
except ImportError:
58+
# noinspection PyUnresolvedReferences
59+
import configparser
60+
61+
# This is from the aliases example:
62+
# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py
63+
class Config(object):
64+
"""Object to hold CLI config"""
65+
66+
def __init__(self):
67+
self.path = os.getcwd()
68+
self.aliases = {}
69+
70+
def read_config(self, filename):
71+
parser = configparser.RawConfigParser()
72+
parser.read([filename])
73+
try:
74+
self.aliases.update(parser.items('aliases'))
75+
except configparser.NoSectionError:
76+
pass
77+
78+
# Global Config object
79+
_config = None
80+
5481
class AliasedGroup(click.Group):
5582
"""This subclass of click.Group supports abbreviations and
5683
looking up aliases in a config file with a bit of magic.

0 commit comments

Comments
 (0)