|
12 | 12 |
|
13 | 13 |
|
14 | 14 | class TestSugar(unittest.TestCase): |
| 15 | + |
15 | 16 | """ |
16 | 17 | All scripts in conf/ will be dynamically added here as individual |
17 | 18 | tests (e.g., test_path_to_conf_samples_exactmatch_bess) in this class. |
@@ -44,8 +45,10 @@ def test_envvar(self): |
44 | 45 |
|
45 | 46 | def test_module(self): |
46 | 47 | 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)"), |
49 | 52 | ('a > b', "a > b"), |
50 | 53 | ('a >- b', "a >- b"), |
51 | 54 | ('a -> b', "a + b"), |
@@ -88,20 +91,20 @@ def test_module(self): |
88 | 91 | self.run_suite(mod_suite) |
89 | 92 |
|
90 | 93 |
|
91 | | -def test_generator(path): |
92 | | - def test(self): |
| 94 | +def generate_test_method(path): |
| 95 | + def template(self): |
93 | 96 | xformed = sugar.xform_file(path) |
94 | 97 | code = compile(xformed, path, 'exec') |
95 | 98 |
|
96 | | - return test |
| 99 | + return template |
97 | 100 |
|
98 | 101 |
|
99 | 102 | for root, dir_names, file_names in os.walk(script_dir): |
100 | 103 | for file_name in fnmatch.filter(file_names, "*.bess"): |
101 | 104 | 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) |
105 | 108 |
|
106 | 109 | if __name__ == '__main__': |
107 | 110 | unittest.main() |
0 commit comments