def other_character(): """Create another Character instance for all tests to share.""" _character = Character(savable=False) _character.active = True _character.name = "Target" _character.session = _other_session return _character
def test_character_act(self, character, other_character): """Test that we can generate 'act' messages for a character.""" assert not character.session._output assert not other_character.session._output # Generate messages for neither the source nor the target. character.act("a tree falls and nobody is around.", and_self=False) assert not character.session._output assert not other_character.session._output # Generate messages for the source but not the target. character.act("{s} dance{ss} {x} jigs.", context={"x": "five"}) assert character.session._output assert character.session._output.pop() == "You dance five jigs.\n" assert not other_character.session._output # Generate messages for the target but not the source. character.act("{s} explode{ss}, hard.", target=other_character, and_self=False) assert not character.session._output assert other_character.session._output assert (other_character.session._output.pop() == "Testing explodes, hard.\n") # Generate messages for the source and the target. character.act("{s} hit{ss} {t} in the face!", target=other_character) assert ( character.session._output.pop() == "You hit Target in the face!\n") assert (other_character.session._output.pop() == "Testing hits you in the face!\n") character.act("{s} speak{ss} gibberish for a moment.", to=Character.all()) assert (character.session._output.pop() == "You speak gibberish for a moment.\n") assert (other_character.session._output.pop() == "Testing speaks gibberish for a moment.\n") character.act("{s} does something to {t}.", target=other_character, to=Character.all(), and_self=False) assert not character.session._output assert (other_character.session._output.pop() == "Testing does something to you.\n")
def test_room_chars(self): """Test that a room's character list functions properly.""" assert not self.room.chars char = Character() char.resume(quiet=True) char.room = self.room assert set(self.room.chars) == {char} del Character._caches[char.get_key_name()][char.key] del char gc.collect() assert not self.room.chars
def test_character_create(self): """Test that we can create a new character instance.""" assert Character()
def character(): """Create a Character instance for all tests to share.""" return Character(savable=False)