Added unit tests for tree_select contrib

This commit is contained in:
FlutterSprite 2017-10-30 16:21:32 -07:00 committed by GitHub
parent 8b95b4718a
commit 2fcf1b3c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1206,6 +1206,36 @@ class TestTurnBattleFunc(EvenniaTest):
# Remove the script at the end
turnhandler.stop()
# Test tree select
from evennia.contrib import tree_select
TREE_MENU_TESTSTR = """Foo
Bar
-Baz
--Baz 1
--Baz 2
-Qux"""
class TestTreeSelectFunc(EvenniaTest):
def test_tree_functions(self):
# Dash counter
self.assertTrue(tree_select.dashcount("--test") == 2)
# Is category
self.assertTrue(tree_select.is_category(TREE_MENU_TESTSTR, 1) == True)
# Parse options
self.assertTrue(tree_select.parse_opts(TREE_MENU_TESTSTR, category_index=2) == [(3, "Baz 1"), (4, "Baz 2")])
# Index to selection
self.assertTrue(tree_select.index_to_selection(TREE_MENU_TESTSTR, 2) == "Baz")
# Go up one category
self.assertTrue(tree_select.go_up_one_category(TREE_MENU_TESTSTR, 4) == 2)
# Option list to menu options
test_optlist = tree_select.parse_opts(TREE_MENU_TESTSTR, category_index=2)
optlist_to_menu_expected_result = [{'goto': ['menunode_treeselect', {'newindex': 3}], 'key': 'Baz 1'},
{'goto': ['menunode_treeselect', {'newindex': 4}], 'key': 'Baz 2'},
{'goto': ['menunode_treeselect', {'newindex': 1}], 'key': ['<< Go Back', 'go back', 'back'], 'desc': 'Return to the previous menu.'}]
self.assertTrue(tree_select.optlist_to_menuoptions(TREE_MENU_TESTSTR, test_optlist, 2, True, True) == optlist_to_menu_expected_result)
# Test of the unixcommand module