From 6fa68745ba1f57bbb1464a0f285f239805ab3545 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 18 Sep 2022 00:49:41 +0200 Subject: [PATCH] Correct funcparser tests --- .../evadventure/tests/test_dungeon.py | 1 + evennia/utils/tests/test_funcparser.py | 47 ++++++++++++------- evennia/utils/utils.py | 2 +- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/evennia/contrib/tutorials/evadventure/tests/test_dungeon.py b/evennia/contrib/tutorials/evadventure/tests/test_dungeon.py index f96d82a2ff..6fe521e1ab 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_dungeon.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_dungeon.py @@ -28,6 +28,7 @@ class TestDungeon(EvAdventureMixin, BaseEvenniaTest): super().setUp() droomclass = dungeon.EvAdventureDungeonStartRoom droomclass.recycle_time = 0 # disable the tick + droomclass.branch_check_time = 0 self.start_room = create_object(droomclass, key="bottom of well") diff --git a/evennia/utils/tests/test_funcparser.py b/evennia/utils/tests/test_funcparser.py index a1347b14fe..85e1cb2386 100644 --- a/evennia/utils/tests/test_funcparser.py +++ b/evennia/utils/tests/test_funcparser.py @@ -5,13 +5,13 @@ Test the funcparser module. """ import time -from unittest.mock import MagicMock, patch from ast import literal_eval -from simpleeval import simple_eval -from parameterized import parameterized -from django.test import TestCase, override_settings +from unittest.mock import MagicMock, patch +from django.test import TestCase, override_settings from evennia.utils import funcparser, test_resources +from parameterized import parameterized +from simpleeval import simple_eval def _test_callable(*args, **kwargs): @@ -20,9 +20,7 @@ def _test_callable(*args, **kwargs): argstr = ", ".join(args) kwargstr = "" if kwargs: - kwargstr = (", " if args else "") + ( - ", ".join(f"{key}={val}" for key, val in kwargs.items()) - ) + kwargstr = (", " if args else "") + ", ".join(f"{key}={val}" for key, val in kwargs.items()) return f"_test({argstr}{kwargstr})" @@ -402,13 +400,18 @@ class TestDefaultCallables(TestCase): ("Some $rjust(Hello, 30)", "Some Hello"), ("Some $rjust(Hello, width=30)", "Some Hello"), ("Some $cjust(Hello, 30)", "Some Hello "), - ("Some $eval('-'*20)Hello", "Some --------------------Hello"), - ("There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.", - "There is one goose here."), - ("There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.", - "There are two geese here."), - ("There is $int2str(1) murderer, but $int2str(12) suspects.", - "There is one murderer, but twelve suspects."), + ( + "There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.", + "There is one goose here.", + ), + ( + "There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.", + "There are two geese here.", + ), + ( + "There is $int2str(1) murderer, but $int2str(12) suspects.", + "There is one murderer, but twelve suspects.", + ), ("There is $an(thing) here", "There is a thing here"), ("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"), ('$crop("spider\'s silk", 5)', "spide"), @@ -474,14 +477,22 @@ class TestDefaultCallables(TestCase): def test_escaped(self): self.assertEqual( self.parser.parse( - "this should be $pad('''escaped,''' and '''instead,''' cropped $crop(with a long,5) text., 80)" + "this should be $pad('''escaped,''' and '''instead,''' cropped $crop(with a long,5)" + " text., 80)" ), - "this should be escaped, and instead, cropped with text. ", + "this should be escaped, and instead, cropped with text. " + " ", ) def test_escaped2(self): - raw_str = 'this should be $pad("""escaped,""" and """instead,""" cropped $crop(with a long,5) text., 80)' - expected = "this should be escaped, and instead, cropped with text. " + raw_str = ( + 'this should be $pad("""escaped,""" and """instead,""" cropped $crop(with a long,5)' + " text., 80)" + ) + expected = ( + "this should be escaped, and instead, cropped with text. " + " " + ) result = self.parser.parse(raw_str) self.assertEqual( result, diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 274459adbc..d598dde7e9 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -2745,7 +2745,7 @@ def int2str(number, adjective=False): str: The number expressed as a string. """ - number = int(adjective) + number = int(number) if adjective: return _INT2STR_MAP_ADJ.get(number, f"{number}th") return _INT2STR_MAP_NOUN.get(number, str(number))