mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Merge pull request #2923 from InspectorCaracal/pronoun-tests
Expand pronoun tests
This commit is contained in:
commit
74084744f7
3 changed files with 73 additions and 46 deletions
|
|
@ -477,7 +477,7 @@ class TestDefaultCallables(TestCase):
|
|||
("male", "Char1 smiles at himself"),
|
||||
("female", "Char1 smiles at herself"),
|
||||
("neutral", "Char1 smiles at itself"),
|
||||
("plural", "Char1 smiles at itself"),
|
||||
("plural", "Char1 smiles at themselves"),
|
||||
]
|
||||
)
|
||||
def test_pronoun_gender(self, gender, expected):
|
||||
|
|
|
|||
|
|
@ -104,11 +104,11 @@ PRONOUN_MAPPING = {
|
|||
}
|
||||
|
||||
PRONOUN_TABLE = {
|
||||
"I": ("1st person", ("neutral", "male", "female"), "subject pronoun"),
|
||||
"me": ("1st person", ("neutral", "male", "female"), "object pronoun"),
|
||||
"my": ("1st person", ("neutral", "male", "female"), "possessive adjective"),
|
||||
"mine": ("1st person", ("neutral", "male", "female"), "possessive pronoun"),
|
||||
"myself": ("1st person", ("neutral", "male", "female"), "reflexive pronoun"),
|
||||
"I": ("1st person", ("neutral", "male", "female", "plural"), "subject pronoun"),
|
||||
"me": ("1st person", ("neutral", "male", "female", "plural"), "object pronoun"),
|
||||
"my": ("1st person", ("neutral", "male", "female", "plural"), "possessive adjective"),
|
||||
"mine": ("1st person", ("neutral", "male", "female", "plural"), "possessive pronoun"),
|
||||
"myself": ("1st person", ("neutral", "male", "female", "plural"), "reflexive pronoun"),
|
||||
"we": ("1st person", "plural", "subject pronoun"),
|
||||
"us": ("1st person", "plural", "object pronoun"),
|
||||
"our": ("1st person", "plural", "possessive adjective"),
|
||||
|
|
@ -161,7 +161,7 @@ PRONOUN_TABLE = {
|
|||
VIEWPOINT_CONVERSION = {
|
||||
"1st person": "3rd person",
|
||||
"2nd person": "3rd person",
|
||||
"3rd person": ("1st person", "2nd person"),
|
||||
"3rd person": ("2nd person", "1st person"),
|
||||
}
|
||||
|
||||
ALIASES = {
|
||||
|
|
@ -185,15 +185,9 @@ ALIASES = {
|
|||
}
|
||||
|
||||
|
||||
def pronoun_to_viewpoints(
|
||||
pronoun,
|
||||
options=None,
|
||||
pronoun_type=DEFAULT_PRONOUN_TYPE,
|
||||
gender=DEFAULT_GENDER,
|
||||
viewpoint=DEFAULT_VIEWPOINT,
|
||||
):
|
||||
def pronoun_to_viewpoints(pronoun, options=None, pronoun_type=None, gender=None, viewpoint=None):
|
||||
"""
|
||||
Access function for determining the forms of a pronount from different viewpoints.
|
||||
Access function for determining the forms of a pronoun from different viewpoints.
|
||||
|
||||
Args:
|
||||
pronoun (str): A valid English pronoun, such as 'you', 'his', 'themselves' etc.
|
||||
|
|
@ -244,13 +238,13 @@ def pronoun_to_viewpoints(
|
|||
# get the default data for the input pronoun
|
||||
source_viewpoint, source_gender, source_type = PRONOUN_TABLE[pronoun_lower]
|
||||
|
||||
# differentiators
|
||||
# use the source pronoun's attributes as defaults
|
||||
if pronoun_type not in PRONOUN_TYPES:
|
||||
pronoun_type = DEFAULT_PRONOUN_TYPE
|
||||
pronoun_type = source_type[0] if is_iter(source_type) else source_type
|
||||
if viewpoint not in VIEWPOINTS:
|
||||
viewpoint = DEFAULT_VIEWPOINT
|
||||
viewpoint = source_viewpoint
|
||||
if gender not in GENDERS:
|
||||
gender = DEFAULT_GENDER
|
||||
gender = source_gender[0] if is_iter(source_gender) else source_gender
|
||||
|
||||
if options:
|
||||
# option string/list will override the kwargs differentiators given
|
||||
|
|
@ -279,19 +273,8 @@ def pronoun_to_viewpoints(
|
|||
else:
|
||||
viewpoint = target_viewpoint
|
||||
|
||||
# special handling for the royal "we"
|
||||
if is_iter(source_gender):
|
||||
gender_opts = list(source_gender)
|
||||
else:
|
||||
gender_opts = [source_gender]
|
||||
if viewpoint == "1st person":
|
||||
# make sure plural is always an option when converting to 1st person
|
||||
# it doesn't matter if it's in the list twice, so don't bother checking
|
||||
gender_opts.append("plural")
|
||||
# if the gender is still not in the extended options, fall back to source pronoun's default
|
||||
gender = gender if gender in gender_opts else gender_opts[0]
|
||||
|
||||
# step down into the mapping
|
||||
# by this point, gender will be a valid option from GENDERS and type/viewpoint will be validated
|
||||
# step down into the mapping to get the converted pronoun
|
||||
viewpoint_map = PRONOUN_MAPPING[viewpoint]
|
||||
pronouns = viewpoint_map.get(pronoun_type, viewpoint_map[DEFAULT_PRONOUN_TYPE])
|
||||
mapped_pronoun = pronouns.get(gender, pronouns[DEFAULT_GENDER])
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ Unit tests for verb conjugation.
|
|||
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
from parameterized import parameterized
|
||||
|
||||
from django.test import TestCase
|
||||
from . import conjugate, pronouns
|
||||
|
||||
|
||||
|
|
@ -272,33 +271,51 @@ class TestVerbConjugate(TestCase):
|
|||
class TestPronounMapping(TestCase):
|
||||
"""
|
||||
Test pronoun viewpoint mapping
|
||||
|
||||
"""
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
("you", "you", "it"), # default 3rd is "neutral"
|
||||
("I", "I", "it"),
|
||||
("Me", "Me", "It"),
|
||||
("ours", "ours", "theirs"),
|
||||
("yourself", "yourself", "itself"),
|
||||
("yourselves", "yourselves", "themselves"),
|
||||
("he", "you", "he"), # assume 2nd person
|
||||
("her", "you", "her"),
|
||||
("their", "your", "their"),
|
||||
("itself", "yourself", "itself"),
|
||||
("herself", "yourself", "herself"),
|
||||
("themselves", "yourselves", "themselves"),
|
||||
]
|
||||
)
|
||||
def test_default_mapping(self, pronoun, expected_1st_or_2nd_person, expected_3rd_person):
|
||||
"""
|
||||
Test the pronoun mapper.
|
||||
|
||||
"""
|
||||
received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints(pronoun)
|
||||
|
||||
self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person)
|
||||
self.assertEqual(expected_3rd_person, received_3rd_person)
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
("you", "m", "you", "he"),
|
||||
("you", "f op", "you", "her"),
|
||||
("I", "", "I", "it"),
|
||||
("I", "p", "I", "it"), # plural is invalid
|
||||
("you", "p op", "you", "them"),
|
||||
("I", "m", "I", "he"),
|
||||
("Me", "n", "Me", "It"),
|
||||
("your", "p", "your", "their"),
|
||||
("ours", "", "ours", "theirs"),
|
||||
("yourself", "", "yourself", "itself"),
|
||||
("yourself", "m", "yourself", "himself"),
|
||||
("yourself", "f", "yourself", "herself"),
|
||||
("yourself", "p", "yourself", "itself"), # plural is invalid
|
||||
("yourselves", "", "yourselves", "themselves"),
|
||||
("he", "", "you", "he"), # assume 2nd person
|
||||
("he", "1", "I", "he"),
|
||||
("he", "1 p", "we", "he"),
|
||||
("he", "1 p", "we", "he"), # royal we
|
||||
("we", "m", "we", "he"), # royal we, other way
|
||||
("her", "p", "you", "her"),
|
||||
("her", "pa", "your", "her"),
|
||||
("their", "pa", "your", "their"),
|
||||
("itself", "", "yourself", "itself"),
|
||||
("themselves", "", "yourselves", "themselves"),
|
||||
("herself", "", "yourself", "herself"),
|
||||
("their", "ma", "your", "their"),
|
||||
]
|
||||
)
|
||||
def test_mapping_with_options(
|
||||
|
|
@ -313,3 +330,30 @@ class TestPronounMapping(TestCase):
|
|||
)
|
||||
self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person)
|
||||
self.assertEqual(expected_3rd_person, received_3rd_person)
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
("you", "p", "you", "they"),
|
||||
("I", "p", "I", "they"),
|
||||
("Me", "p", "Me", "Them"),
|
||||
("your", "p", "your", "their"),
|
||||
("they", "1 p", "we", "they"),
|
||||
("they", "", "you", "they"),
|
||||
("yourself", "p", "yourself", "themselves"),
|
||||
("myself", "p", "myself", "themselves"),
|
||||
]
|
||||
)
|
||||
def test_colloquial_plurals(
|
||||
self, pronoun, options, expected_1st_or_2nd_person, expected_3rd_person
|
||||
):
|
||||
"""
|
||||
The use of this module by the funcparser expects a default person-pronoun
|
||||
of the neutral "they", which is categorized here by the plural.
|
||||
|
||||
"""
|
||||
received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints(
|
||||
pronoun, options
|
||||
)
|
||||
|
||||
self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person)
|
||||
self.assertEqual(expected_3rd_person, received_3rd_person)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue