From 65664bf523996e7c7b07d67c9c5d72d45973a3d8 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 28 Oct 2017 22:48:06 +0200 Subject: [PATCH] Add documentation to EvMenu test class --- evennia/utils/tests/test_evmenu.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/evennia/utils/tests/test_evmenu.py b/evennia/utils/tests/test_evmenu.py index a3517c35ac..7f01db63f6 100644 --- a/evennia/utils/tests/test_evmenu.py +++ b/evennia/utils/tests/test_evmenu.py @@ -1,7 +1,17 @@ """ Unit tests for the EvMenu system -TODO: This need expansion. +This sets up a testing parent for testing EvMenu trees. It is configured by subclassing the +`TestEvMenu` class from this module and setting the class variables to point to the menu that should +be tested and how it should be called. + +Without adding any further test methods, the tester will process all nodes of the menu, width first, +by stepping through all options for every node. It will check to make sure all are visited. It will +create a hierarchical list of node names that describes the tree structure. Easiest way to use this +is to run the test once to see how the structure looks. + +The system also allows for testing the returns of each node as part of the parsing. To help debug +the menu, turn on `debug_output`, which will print the traversal process in detail. """ @@ -26,6 +36,11 @@ class TestEvMenu(TestCase): startnode_input = "" kwargs = {} + # if all nodes must be visited for the test to pass. This is not on + # by default since there may be exec-nodes that are made to not be + # visited. + expect_all_nodes = False + # this is compared against the full tree structure generated expected_tree = [] # this allows for verifying that a given node returns a given text. The @@ -136,7 +151,8 @@ class TestEvMenu(TestCase): traversal_tree = [menu.nodename] _depth_first(menu, traversal_tree, visited_nodes, 1) - self.assertGreaterEqual(len(menu._menutree), len(visited_nodes)) + if self.expect_all_nodes: + self.assertGreaterEqual(len(menu._menutree), len(visited_nodes)) self.assertEqual(traversal_tree, self.expected_tree) def setUp(self):