diff options
Diffstat (limited to 'tests/topotests/example-test')
| -rwxr-xr-x | tests/topotests/example-test/test_example.py | 33 | ||||
| -rwxr-xr-x | tests/topotests/example-test/test_template.py | 29 |
2 files changed, 39 insertions, 23 deletions
diff --git a/tests/topotests/example-test/test_example.py b/tests/topotests/example-test/test_example.py index 8e37ad11d4..72eceee612 100755 --- a/tests/topotests/example-test/test_example.py +++ b/tests/topotests/example-test/test_example.py @@ -9,52 +9,61 @@ import pytest fatal_error = "" + def setup_module(module): - print ("setup_module module:%s" % module.__name__) + print("setup_module module:%s" % module.__name__) + def teardown_module(module): - print ("teardown_module module:%s" % module.__name__) + print("teardown_module module:%s" % module.__name__) + def setup_function(function): - print ("setup_function function:%s" % function.__name__) + print("setup_function function:%s" % function.__name__) + def teardown_function(function): - print ("teardown_function function:%s" % function.__name__) + print("teardown_function function:%s" % function.__name__) + def test_numbers_compare(): a = 12 - print ("Dummy Output") - assert( a == 12 ) + print("Dummy Output") + assert a == 12 + def test_fail_example(): assert True, "Some Text with explaination in case of failure" + def test_ls_exits_zero(): "Tests for ls command on invalid file" global fatal_error proc = subprocess.Popen( - ["ls", "/some/nonexistant/file"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + ["ls", "/some/nonexistant/file"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() - if (proc.returncode != 0): + if proc.returncode != 0: # Mark this as a fatal error which skips some other tests on failure fatal_error = "test_fail_example failed" assert proc.returncode == 0, "Return Code is non-Zero:\n%s" % stderr + def test_skipped_on_fatalerror(): global fatal_error # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) assert True, "Some Text with explaination in case of failure" -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/example-test/test_template.py b/tests/topotests/example-test/test_template.py index 4e35ce8b9f..afe974876a 100755 --- a/tests/topotests/example-test/test_template.py +++ b/tests/topotests/example-test/test_template.py @@ -32,7 +32,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -43,8 +43,10 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class TemplateTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -56,17 +58,18 @@ class TemplateTopo(Topo): # # Create 2 routers for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create a switch with just one router connected to it to simulate a # empty network. - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) # Create a connection between r1 and r2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + def setup_module(mod): "Sets up the pytest environment" @@ -83,12 +86,13 @@ def setup_module(mod): router.load_config( TopoRouter.RD_ZEBRA, # Uncomment next line to load configuration from ./router/zebra.conf - #os.path.join(CWD, '{}/zebra.conf'.format(rname)) + # os.path.join(CWD, '{}/zebra.conf'.format(rname)) ) # After loading the configurations, this function loads configured daemons. tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -96,6 +100,7 @@ def teardown_module(mod): # This function tears down the whole topology. tgen.stop_topology() + def test_call_mininet_cli(): "Dummy test that just calls mininet CLI so we can interact with the build." tgen = get_topogen() @@ -103,18 +108,20 @@ def test_call_mininet_cli(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('calling mininet CLI') + logger.info("calling mininet CLI") tgen.mininet_cli() + # Memory leak test template def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) |
