Skip to content

Commit 866f141

Browse files
sangjinhanjustinemarie
authored andcommitted
Make names pytest-friendly (#520)
1 parent 4402b0d commit 866f141

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

bessctl/test_samples.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
class CommandError(subprocess.CalledProcessError):
18+
1819
'''Identical to CalledProcessError, except it also shows the output'''
1920

2021
def __str__(self):
@@ -30,6 +31,7 @@ def run_cmd(cmd):
3031

3132

3233
class TestSamples(unittest.TestCase):
34+
3335
"""
3436
All scripts in conf/samples will be dynamically added here as individual
3537
tests (e.g., test_path_to_conf_samples_exactmatch_bess) in this class.
@@ -47,22 +49,22 @@ def tearDownClass(cls):
4749
run_cmd('%s daemon stop' % bessctl)
4850

4951

50-
def test_generator(path):
51-
def test(self):
52+
def generate_test_method(path):
53+
def template(self):
5254
run_cmd('%s daemon reset -- run file %s' % (bessctl, path))
5355

5456
# 0.5 seconds should be enough to detect packet leaks in the datapath
5557
time.sleep(0.5)
5658

57-
return test
59+
return template
5860

5961

6062
for root, _, file_names in os.walk(sample_dir):
6163
for file_name in fnmatch.filter(file_names, "*.bess"):
6264
path = os.path.join(root, file_name)
63-
test_name = 'test' + path.replace('/', '_').replace('.', '_')
64-
test_method = test_generator(path)
65-
setattr(TestSamples, test_name, test_method)
65+
name = 'test' + path.replace('/', '_').replace('.', '_')
66+
method = generate_test_method(path)
67+
setattr(TestSamples, name, method)
6668

6769
if __name__ == '__main__':
6870
unittest.main()

bessctl/test_sugar.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class TestSugar(unittest.TestCase):
15+
1516
"""
1617
All scripts in conf/ will be dynamically added here as individual
1718
tests (e.g., test_path_to_conf_samples_exactmatch_bess) in this class.
@@ -44,8 +45,10 @@ def test_envvar(self):
4445

4546
def test_module(self):
4647
mod_suite = [
47-
('a::SomeModule()', "__bess_module__('a', 'SomeModule', )"),
48-
('a::SomeModule(b, c, d)', "__bess_module__('a', 'SomeModule', b, c, d)"),
48+
('a::SomeModule()',
49+
"__bess_module__('a', 'SomeModule', )"),
50+
('a::SomeModule(b, c, d)',
51+
"__bess_module__('a', 'SomeModule', b, c, d)"),
4952
('a > b', "a > b"),
5053
('a >- b', "a >- b"),
5154
('a -> b', "a + b"),
@@ -88,20 +91,20 @@ def test_module(self):
8891
self.run_suite(mod_suite)
8992

9093

91-
def test_generator(path):
92-
def test(self):
94+
def generate_test_method(path):
95+
def template(self):
9396
xformed = sugar.xform_file(path)
9497
code = compile(xformed, path, 'exec')
9598

96-
return test
99+
return template
97100

98101

99102
for root, dir_names, file_names in os.walk(script_dir):
100103
for file_name in fnmatch.filter(file_names, "*.bess"):
101104
path = os.path.join(root, file_name)
102-
test_name = 'test' + path.replace('/', '_').replace('.', '_')
103-
test_method = test_generator(path)
104-
setattr(TestSugar, test_name, test_method)
105+
name = 'test' + path.replace('/', '_').replace('.', '_')
106+
method = generate_test_method(path)
107+
setattr(TestSugar, name, method)
105108

106109
if __name__ == '__main__':
107110
unittest.main()

pybess/test_bess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import service_pb2
1010

1111

12-
class TestServiceImpl(service_pb2.BESSControlServicer):
12+
class DummyServiceImpl(service_pb2.BESSControlServicer):
1313

1414
def __init__(self):
1515
pass
@@ -39,7 +39,7 @@ class TestBESS(unittest.TestCase):
3939
def setUp(self):
4040
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=2))
4141
service_pb2.add_BESSControlServicer_to_server(
42-
TestServiceImpl(),
42+
DummyServiceImpl(),
4343
self.server)
4444
self.server.add_insecure_port('[::]:%d' % self.PORT)
4545
self.server.start()

0 commit comments

Comments
 (0)