mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Correct funcparser tests
This commit is contained in:
parent
705d47fe47
commit
6fa68745ba
3 changed files with 31 additions and 19 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue