Add unittests for gendersub contrib as per #1105.
This commit is contained in:
parent
1b9016d26a
commit
7e762245c8
2 changed files with 26 additions and 12 deletions
|
|
@ -12,18 +12,18 @@ When in use, all messages being sent to the character will make use of
|
|||
the character's gender, for example the echo
|
||||
|
||||
```
|
||||
char.msg("%s falls on {p face with a thud." % char.key)
|
||||
char.msg("%s falls on |p face with a thud." % char.key)
|
||||
```
|
||||
|
||||
will result in "Tom falls on his|her|its face with a thud" depending
|
||||
on the gender of the object being messaged. Default gender is
|
||||
"neutral".
|
||||
will result in "Tom falls on his|her|its|their face with a thud"
|
||||
depending on the gender of the object being messaged. Default gender
|
||||
is "ambiguous" (they).
|
||||
|
||||
To use, have DefaultCharacter inherit from this, or change
|
||||
setting.DEFAULT_CHARACTER to point to this class.
|
||||
|
||||
The `@gender` command needs to be added to the default cmdset
|
||||
before it becomes available.
|
||||
The `@gender` command needs to be added to the default cmdset before
|
||||
it becomes available.
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ _GENDER_PRONOUN_MAP = {"male": {"s": "he",
|
|||
"p": "their",
|
||||
"a": "theirs"}
|
||||
}
|
||||
_RE_GENDER_PRONOUN = re.compile(r'({s|{S|{o|{O|{p|{P|{a|{A)')
|
||||
_RE_GENDER_PRONOUN = re.compile(r'(\|s|\|S|\|o|\|O|\|p|\|P|\|a|\|A)')
|
||||
|
||||
# in-game command for setting the gender
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ class SetGender(Command):
|
|||
caller.msg("Usage: @gender male|female|neutral|ambiguous")
|
||||
return
|
||||
caller.db.gender = arg
|
||||
caller.msg("Your gender was set to %s." % arg)
|
||||
caller.msg("Your gender was set to %s." % arg)
|
||||
|
||||
|
||||
# Gender-aware character class
|
||||
|
|
@ -103,10 +103,10 @@ class GenderCharacter(DefaultCharacter):
|
|||
regex_match (MatchObject): the regular expression match.
|
||||
|
||||
Notes:
|
||||
- `{s`, `{S`: Subjective form: he, she, it, He, She, It, They
|
||||
- `{o`, `{O`: Objective form: him, her, it, Him, Her, It, Them
|
||||
- `{p`, `{P`: Possessive form: his, her, its, His, Her, Its, Their
|
||||
- `{a`, `{A`: Absolute Possessive form: his, hers, its, His, Hers, Its, Theirs
|
||||
- `|s`, `|S`: Subjective form: he, she, it, He, She, It, They
|
||||
- `|o`, `|O`: Objective form: him, her, it, Him, Her, It, Them
|
||||
- `|p`, `|P`: Possessive form: his, her, its, His, Her, Its, Their
|
||||
- `|a`, `|A`: Absolute Possessive form: his, hers, its, His, Hers, Its, Theirs
|
||||
|
||||
"""
|
||||
typ = regex_match.group()[1] # "s", "O" etc
|
||||
|
|
|
|||
|
|
@ -504,3 +504,17 @@ class TestEmailLogin(CommandTest):
|
|||
self.call(email_login.CmdUnconnectedLook(), "", "==========")
|
||||
def test_unconnectedhelp(self):
|
||||
self.call(email_login.CmdUnconnectedHelp(), "", "You are not yet logged into the game.")
|
||||
|
||||
# test gendersub contrib
|
||||
|
||||
from evennia.contrib import gendersub
|
||||
|
||||
class TestGenderSub(CommandTest):
|
||||
def test_setgender(self):
|
||||
self.call(gendersub.SetGender(), "male", "Your gender was set to male.")
|
||||
self.call(gendersub.SetGender(), "ambiguous", "Your gender was set to ambiguous.")
|
||||
self.call(gendersub.SetGender(), "Foo", "Usage: @gender")
|
||||
def test_gendercharacter(self):
|
||||
char = create_object(gendersub.GenderCharacter, key="Gendered", location=self.room1)
|
||||
txt = "Test |p gender"
|
||||
self.assertEqual(gendersub._RE_GENDER_PRONOUN.sub(char._get_pronoun, txt), "Test their gender")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue