mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Merge branch 'master' into develop
This commit is contained in:
commit
87abbbcd2e
6 changed files with 120 additions and 7 deletions
|
|
@ -612,12 +612,12 @@ class CmdDesc(COMMAND_DEFAULT_CLASS):
|
|||
self.edit_handler()
|
||||
return
|
||||
|
||||
if self.rhs:
|
||||
if '=' in self.args:
|
||||
# We have an =
|
||||
obj = caller.search(self.lhs)
|
||||
if not obj:
|
||||
return
|
||||
desc = self.rhs
|
||||
desc = self.rhs or ''
|
||||
else:
|
||||
obj = caller.location or self.msg("|rYou can't describe oblivion.|n")
|
||||
if not obj:
|
||||
|
|
|
|||
|
|
@ -318,6 +318,24 @@ class TestBuilding(CommandTest):
|
|||
def test_desc(self):
|
||||
self.call(building.CmdDesc(), "Obj2=TestDesc", "The description was set on Obj2(#5).")
|
||||
|
||||
def test_empty_desc(self):
|
||||
"""
|
||||
empty desc sets desc as ''
|
||||
"""
|
||||
o2d = self.obj2.db.desc
|
||||
r1d = self.room1.db.desc
|
||||
self.call(building.CmdDesc(), "Obj2=", "The description was set on Obj2(#5).")
|
||||
assert self.obj2.db.desc == '' and self.obj2.db.desc != o2d
|
||||
assert self.room1.db.desc == r1d
|
||||
|
||||
def test_desc_default_to_room(self):
|
||||
"""no rhs changes room's desc"""
|
||||
o2d = self.obj2.db.desc
|
||||
r1d = self.room1.db.desc
|
||||
self.call(building.CmdDesc(), "Obj2", "The description was set on Room(#1).")
|
||||
assert self.obj2.db.desc == o2d
|
||||
assert self.room1.db.desc == 'Obj2' and self.room1.db.desc != r1d
|
||||
|
||||
def test_wipe(self):
|
||||
confirm = building.CmdDestroy.confirm
|
||||
building.CmdDestroy.confirm = False
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
|
||||
from evennia.utils.utils import delay
|
||||
# timeout the handshakes in case the client doesn't reply at all
|
||||
delay(2, callback=self.handshake_done, timeout=True)
|
||||
self._handshake_delay = delay(2, callback=self.handshake_done, timeout=True)
|
||||
|
||||
# TCP/IP keepalive watches for dead links
|
||||
self.transport.setTcpKeepAlive(1)
|
||||
|
|
|
|||
|
|
@ -8,9 +8,24 @@ try:
|
|||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from mock import Mock
|
||||
import string
|
||||
from evennia.server.portal import irc
|
||||
|
||||
from twisted.conch.telnet import IAC, WILL, DONT, SB, SE, NAWS, DO
|
||||
from twisted.test import proto_helpers
|
||||
from twisted.trial.unittest import TestCase as TwistedTestCase
|
||||
|
||||
from .telnet import TelnetServerFactory, TelnetProtocol
|
||||
from .portal import PORTAL_SESSIONS
|
||||
from .suppress_ga import SUPPRESS_GA
|
||||
from .naws import DEFAULT_HEIGHT, DEFAULT_WIDTH
|
||||
from .ttype import TTYPE, IS
|
||||
from .mccp import MCCP
|
||||
from .mssp import MSSP
|
||||
from .mxp import MXP
|
||||
from .telnet_oob import MSDP, MSDP_VAL, MSDP_VAR
|
||||
|
||||
|
||||
class TestIRC(TestCase):
|
||||
|
||||
|
|
@ -73,3 +88,64 @@ class TestIRC(TestCase):
|
|||
s = r'|wthis|Xis|gis|Ma|C|complex|*string'
|
||||
|
||||
self.assertEqual(irc.parse_irc_to_ansi(irc.parse_ansi_to_irc(s)), s)
|
||||
|
||||
|
||||
class TestTelnet(TwistedTestCase):
|
||||
def setUp(self):
|
||||
super(TestTelnet, self).setUp()
|
||||
factory = TelnetServerFactory()
|
||||
factory.protocol = TelnetProtocol
|
||||
factory.sessionhandler = PORTAL_SESSIONS
|
||||
factory.sessionhandler.portal = Mock()
|
||||
self.proto = factory.buildProtocol(("localhost", 0))
|
||||
self.transport = proto_helpers.StringTransport()
|
||||
self.addCleanup(factory.sessionhandler.disconnect_all)
|
||||
|
||||
def test_mudlet_ttype(self):
|
||||
self.transport.client = ["localhost"]
|
||||
self.transport.setTcpKeepAlive = Mock()
|
||||
d = self.proto.makeConnection(self.transport)
|
||||
# test suppress_ga
|
||||
self.assertTrue(self.proto.protocol_flags["NOGOAHEAD"])
|
||||
self.proto.dataReceived(IAC + DONT + SUPPRESS_GA)
|
||||
self.assertFalse(self.proto.protocol_flags["NOGOAHEAD"])
|
||||
self.assertEqual(self.proto.handshakes, 7)
|
||||
# test naws
|
||||
self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'], {0: DEFAULT_WIDTH})
|
||||
self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'], {0: DEFAULT_HEIGHT})
|
||||
self.proto.dataReceived(IAC + WILL + NAWS)
|
||||
self.proto.dataReceived([IAC, SB, NAWS, '', 'x', '', 'd', IAC, SE])
|
||||
self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'][0], 120)
|
||||
self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'][0], 100)
|
||||
self.assertEqual(self.proto.handshakes, 6)
|
||||
# test ttype
|
||||
self.assertTrue(self.proto.protocol_flags["FORCEDENDLINE"])
|
||||
self.assertFalse(self.proto.protocol_flags["TTYPE"])
|
||||
self.assertTrue(self.proto.protocol_flags["ANSI"])
|
||||
self.proto.dataReceived(IAC + WILL + TTYPE)
|
||||
self.proto.dataReceived([IAC, SB, TTYPE, IS, "MUDLET", IAC, SE])
|
||||
self.assertTrue(self.proto.protocol_flags["XTERM256"])
|
||||
self.assertEqual(self.proto.protocol_flags["CLIENTNAME"], "MUDLET")
|
||||
self.proto.dataReceived([IAC, SB, TTYPE, IS, "XTERM", IAC, SE])
|
||||
self.proto.dataReceived([IAC, SB, TTYPE, IS, "MTTS 137", IAC, SE])
|
||||
self.assertEqual(self.proto.handshakes, 5)
|
||||
# test mccp
|
||||
self.proto.dataReceived(IAC + DONT + MCCP)
|
||||
self.assertFalse(self.proto.protocol_flags['MCCP'])
|
||||
self.assertEqual(self.proto.handshakes, 4)
|
||||
# test mssp
|
||||
self.proto.dataReceived(IAC + DONT + MSSP)
|
||||
self.assertEqual(self.proto.handshakes, 3)
|
||||
# test oob
|
||||
self.proto.dataReceived(IAC + DO + MSDP)
|
||||
self.proto.dataReceived([IAC, SB, MSDP, MSDP_VAR, "LIST", MSDP_VAL, "COMMANDS", IAC, SE])
|
||||
self.assertTrue(self.proto.protocol_flags['OOB'])
|
||||
self.assertEqual(self.proto.handshakes, 2)
|
||||
# test mxp
|
||||
self.proto.dataReceived(IAC + DONT + MXP)
|
||||
self.assertFalse(self.proto.protocol_flags['MXP'])
|
||||
self.assertEqual(self.proto.handshakes, 1)
|
||||
# clean up to prevent Unclean reactor
|
||||
self.proto.nop_keep_alive.stop()
|
||||
self.proto._handshake_delay.cancel()
|
||||
return d
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ import time
|
|||
# TODO!
|
||||
#sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
#os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
|
||||
import ev
|
||||
from evennia.utils.idmapper import base as _idmapper
|
||||
import evennia
|
||||
from evennia.utils.idmapper import models as _idmapper
|
||||
|
||||
LOGFILE = "logs/memoryusage.log"
|
||||
INTERVAL = 30 # log every 30 seconds
|
||||
|
||||
|
||||
class Memplot(ev.Script):
|
||||
class Memplot(evennia.DefaultScript):
|
||||
"""
|
||||
Describes a memory plotting action.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from django.test import TestCase
|
||||
from mock import Mock
|
||||
from mock import Mock, patch, mock_open
|
||||
from .dummyrunner_settings import (c_creates_button, c_creates_obj, c_digs, c_examines, c_help, c_idles, c_login,
|
||||
c_login_nodig, c_logout, c_looks, c_moves, c_moves_n, c_moves_s, c_socialize)
|
||||
import memplot
|
||||
|
||||
|
||||
class TestDummyrunnerSettings(TestCase):
|
||||
|
|
@ -91,3 +92,21 @@ class TestDummyrunnerSettings(TestCase):
|
|||
|
||||
def test_c_move_s(self):
|
||||
self.assertEqual(c_moves_s(self.client), "south")
|
||||
|
||||
|
||||
class TestMemPlot(TestCase):
|
||||
@patch.object(memplot, "_idmapper")
|
||||
@patch.object(memplot, "os")
|
||||
@patch.object(memplot, "open", new_callable=mock_open, create=True)
|
||||
@patch.object(memplot, "time")
|
||||
def test_memplot(self, mock_time, mocked_open, mocked_os, mocked_idmapper):
|
||||
from evennia.utils.create import create_script
|
||||
mocked_idmapper.cache_size.return_value = (9, 5000)
|
||||
mock_time.time = Mock(return_value=6000.0)
|
||||
script = create_script(memplot.Memplot)
|
||||
script.db.starttime = 0.0
|
||||
mocked_os.popen.read.return_value = 5000.0
|
||||
script.at_repeat()
|
||||
handle = mocked_open()
|
||||
handle.write.assert_called_with('100.0, 0.001, 0.001, 9\n')
|
||||
script.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue