Correct funcparser tests

This commit is contained in:
Griatch 2022-09-18 00:49:41 +02:00
parent 705d47fe47
commit 6fa68745ba
3 changed files with 31 additions and 19 deletions

View file

@ -28,6 +28,7 @@ class TestDungeon(EvAdventureMixin, BaseEvenniaTest):
super().setUp() super().setUp()
droomclass = dungeon.EvAdventureDungeonStartRoom droomclass = dungeon.EvAdventureDungeonStartRoom
droomclass.recycle_time = 0 # disable the tick droomclass.recycle_time = 0 # disable the tick
droomclass.branch_check_time = 0
self.start_room = create_object(droomclass, key="bottom of well") self.start_room = create_object(droomclass, key="bottom of well")

View file

@ -5,13 +5,13 @@ Test the funcparser module.
""" """
import time import time
from unittest.mock import MagicMock, patch
from ast import literal_eval from ast import literal_eval
from simpleeval import simple_eval from unittest.mock import MagicMock, patch
from parameterized import parameterized
from django.test import TestCase, override_settings
from django.test import TestCase, override_settings
from evennia.utils import funcparser, test_resources from evennia.utils import funcparser, test_resources
from parameterized import parameterized
from simpleeval import simple_eval
def _test_callable(*args, **kwargs): def _test_callable(*args, **kwargs):
@ -20,9 +20,7 @@ def _test_callable(*args, **kwargs):
argstr = ", ".join(args) argstr = ", ".join(args)
kwargstr = "" kwargstr = ""
if kwargs: if kwargs:
kwargstr = (", " if args else "") + ( kwargstr = (", " if args else "") + ", ".join(f"{key}={val}" for key, val in kwargs.items())
", ".join(f"{key}={val}" for key, val in kwargs.items())
)
return f"_test({argstr}{kwargstr})" return f"_test({argstr}{kwargstr})"
@ -402,13 +400,18 @@ class TestDefaultCallables(TestCase):
("Some $rjust(Hello, 30)", "Some Hello"), ("Some $rjust(Hello, 30)", "Some Hello"),
("Some $rjust(Hello, width=30)", "Some Hello"), ("Some $rjust(Hello, width=30)", "Some Hello"),
("Some $cjust(Hello, 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 $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.",
"There is one goose 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 $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.",
"There is one murderer, but twelve suspects."), "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"), ("There is $an(thing) here", "There is a thing here"),
("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"), ("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"),
('$crop("spider\'s silk", 5)', "spide"), ('$crop("spider\'s silk", 5)', "spide"),
@ -474,14 +477,22 @@ class TestDefaultCallables(TestCase):
def test_escaped(self): def test_escaped(self):
self.assertEqual( self.assertEqual(
self.parser.parse( 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): def test_escaped2(self):
raw_str = 'this should be $pad("""escaped,""" and """instead,""" cropped $crop(with a long,5) text., 80)' raw_str = (
expected = "this should be escaped, and instead, cropped with text. " '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) result = self.parser.parse(raw_str)
self.assertEqual( self.assertEqual(
result, result,

View file

@ -2745,7 +2745,7 @@ def int2str(number, adjective=False):
str: The number expressed as a string. str: The number expressed as a string.
""" """
number = int(adjective) number = int(number)
if adjective: if adjective:
return _INT2STR_MAP_ADJ.get(number, f"{number}th") return _INT2STR_MAP_ADJ.get(number, f"{number}th")
return _INT2STR_MAP_NOUN.get(number, str(number)) return _INT2STR_MAP_NOUN.get(number, str(number))