Run black on sources; add black config
This commit is contained in:
parent
b5d148b00a
commit
b24d4f0e1e
41 changed files with 400 additions and 344 deletions
|
|
@ -369,8 +369,9 @@ help_entry = create_help_entry
|
|||
# Comm system methods
|
||||
|
||||
|
||||
def create_message(senderobj, message, channels=None, receivers=None,
|
||||
locks=None, tags=None, header=None):
|
||||
def create_message(
|
||||
senderobj, message, channels=None, receivers=None, locks=None, tags=None, header=None
|
||||
):
|
||||
"""
|
||||
Create a new communication Msg. Msgs represent a unit of
|
||||
database-persistent communication between entites.
|
||||
|
|
@ -424,7 +425,9 @@ message = create_message
|
|||
create_msg = create_message
|
||||
|
||||
|
||||
def create_channel(key, aliases=None, desc=None, locks=None, keep_log=True, typeclass=None, tags=None):
|
||||
def create_channel(
|
||||
key, aliases=None, desc=None, locks=None, keep_log=True, typeclass=None, tags=None
|
||||
):
|
||||
"""
|
||||
Create A communication Channel. A Channel serves as a central hub
|
||||
for distributing Msgs to groups of people without specifying the
|
||||
|
|
|
|||
|
|
@ -235,7 +235,6 @@ class _SaverMutable(object):
|
|||
def __gt__(self, other):
|
||||
return self._data > other
|
||||
|
||||
|
||||
@_save
|
||||
def __setitem__(self, key, value):
|
||||
self._data.__setitem__(key, self._convert_mutables(value))
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ _STACK_MAXSIZE = settings.INLINEFUNC_STACK_MAXSIZE
|
|||
|
||||
# example/testing inline functions
|
||||
|
||||
|
||||
def random(*args, **kwargs):
|
||||
"""
|
||||
Inlinefunc. Returns a random number between
|
||||
|
|
@ -99,11 +100,11 @@ def random(*args, **kwargs):
|
|||
nargs = len(args)
|
||||
if nargs == 1:
|
||||
# only maxval given
|
||||
minval, maxval = '0', args[0]
|
||||
minval, maxval = "0", args[0]
|
||||
elif nargs > 1:
|
||||
minval, maxval = args[:2]
|
||||
else:
|
||||
minval, maxval = ('0', '1')
|
||||
minval, maxval = ("0", "1")
|
||||
|
||||
if "." in minval or "." in maxval:
|
||||
# float mode
|
||||
|
|
@ -518,10 +519,13 @@ def raw(string):
|
|||
Args:
|
||||
string (str): String with inlinefuncs to escape.
|
||||
"""
|
||||
|
||||
def _escape(match):
|
||||
return "\\" + match.group(0)
|
||||
|
||||
return _RE_STARTTOKEN.sub(_escape, string)
|
||||
|
||||
|
||||
#
|
||||
# Nick templating
|
||||
#
|
||||
|
|
|
|||
|
|
@ -102,7 +102,6 @@ def dbsafe_encode(value, compress_object=False, pickle_protocol=DEFAULT_PROTOCOL
|
|||
|
||||
value = dumps(value, protocol=pickle_protocol)
|
||||
|
||||
|
||||
if compress_object:
|
||||
value = compress(value)
|
||||
value = b64encode(value).decode() # decode bytes to str
|
||||
|
|
|
|||
|
|
@ -205,29 +205,33 @@ help_entries = search_help
|
|||
# not the attribute object itself (this is usually what you want)
|
||||
|
||||
|
||||
def search_object_attribute(key=None, category=None, value=None,
|
||||
strvalue=None, attrtype=None, **kwargs):
|
||||
def search_object_attribute(
|
||||
key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
|
||||
):
|
||||
return ObjectDB.objects.get_by_attribute(
|
||||
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def search_account_attribute(key=None, category=None, value=None,
|
||||
strvalue=None, attrtype=None, **kwargs):
|
||||
def search_account_attribute(
|
||||
key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
|
||||
):
|
||||
return AccountDB.objects.get_by_attribute(
|
||||
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def search_script_attribute(key=None, category=None, value=None,
|
||||
strvalue=None, attrtype=None, **kwargs):
|
||||
def search_script_attribute(
|
||||
key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
|
||||
):
|
||||
return ScriptDB.objects.get_by_attribute(
|
||||
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def search_channel_attribute(key=None, category=None, value=None,
|
||||
strvalue=None, attrtype=None, **kwargs):
|
||||
def search_channel_attribute(
|
||||
key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
|
||||
):
|
||||
return Channel.objects.get_by_attribute(
|
||||
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
|
||||
)
|
||||
|
|
|
|||
|
|
@ -158,11 +158,13 @@ class EvenniaTest(TestCase):
|
|||
self.account2.delete()
|
||||
super().tearDown()
|
||||
|
||||
|
||||
class LocalEvenniaTest(EvenniaTest):
|
||||
"""
|
||||
This test class is intended for inheriting in mygame tests.
|
||||
It helps ensure your tests are run with your own objects.
|
||||
"""
|
||||
|
||||
account_typeclass = settings.BASE_ACCOUNT_TYPECLASS
|
||||
object_typeclass = settings.BASE_OBJECT_TYPECLASS
|
||||
character_typeclass = settings.BASE_CHARACTER_TYPECLASS
|
||||
|
|
|
|||
|
|
@ -109,11 +109,17 @@ class TestCreateHelpEntry(TestCase):
|
|||
|
||||
def test_create_help_entry__complex(self):
|
||||
locks = "foo:false();bar:true()"
|
||||
aliases = ['foo', 'bar', 'tst']
|
||||
aliases = ["foo", "bar", "tst"]
|
||||
tags = [("tag1", "help"), ("tag2", "help"), ("tag3", "help")]
|
||||
|
||||
entry = create.create_help_entry("testentry", self.help_entry, category="Testing",
|
||||
locks=locks, aliases=aliases, tags=tags)
|
||||
entry = create.create_help_entry(
|
||||
"testentry",
|
||||
self.help_entry,
|
||||
category="Testing",
|
||||
locks=locks,
|
||||
aliases=aliases,
|
||||
tags=tags,
|
||||
)
|
||||
self.assertTrue(all(lock in entry.locks.all() for lock in locks.split(";")))
|
||||
self.assertEqual(list(entry.aliases.all()).sort(), aliases.sort())
|
||||
self.assertEqual(entry.tags.all(return_key_and_category=True), tags)
|
||||
|
|
@ -137,21 +143,28 @@ class TestCreateMessage(EvenniaTest):
|
|||
def test_create_msg__channel(self):
|
||||
chan1 = create.create_channel("DummyChannel1")
|
||||
chan2 = create.create_channel("DummyChannel2")
|
||||
msg = create.create_message(self.char1, self.msgtext, channels=[chan1, chan2], header="TestHeader")
|
||||
msg = create.create_message(
|
||||
self.char1, self.msgtext, channels=[chan1, chan2], header="TestHeader"
|
||||
)
|
||||
self.assertEqual(list(msg.channels), [chan1, chan2])
|
||||
|
||||
def test_create_msg__custom(self):
|
||||
locks = "foo:false();bar:true()"
|
||||
tags = ["tag1", "tag2", "tag3"]
|
||||
msg = create.create_message(self.char1, self.msgtext, header="TestHeader",
|
||||
receivers=[self.char1, self.char2], locks=locks, tags=tags)
|
||||
msg = create.create_message(
|
||||
self.char1,
|
||||
self.msgtext,
|
||||
header="TestHeader",
|
||||
receivers=[self.char1, self.char2],
|
||||
locks=locks,
|
||||
tags=tags,
|
||||
)
|
||||
self.assertEqual(msg.receivers, [self.char1, self.char2])
|
||||
self.assertTrue(all(lock in msg.locks.all() for lock in locks.split(";")))
|
||||
self.assertEqual(msg.tags.all(), tags)
|
||||
|
||||
|
||||
class TestCreateChannel(TestCase):
|
||||
|
||||
def test_create_channel__simple(self):
|
||||
chan = create.create_channel("TestChannel1", desc="Testing channel")
|
||||
self.assertEqual(chan.key, "TestChannel1")
|
||||
|
|
@ -160,10 +173,11 @@ class TestCreateChannel(TestCase):
|
|||
def test_create_channel__complex(self):
|
||||
locks = "foo:false();bar:true()"
|
||||
tags = ["tag1", "tag2", "tag3"]
|
||||
aliases = ['foo', 'bar', 'tst']
|
||||
aliases = ["foo", "bar", "tst"]
|
||||
|
||||
chan = create.create_channel("TestChannel2", desc="Testing channel",
|
||||
aliases=aliases, locks=locks, tags=tags)
|
||||
chan = create.create_channel(
|
||||
"TestChannel2", desc="Testing channel", aliases=aliases, locks=locks, tags=tags
|
||||
)
|
||||
self.assertTrue(all(lock in chan.locks.all() for lock in locks.split(";")))
|
||||
self.assertEqual(chan.tags.all(), tags)
|
||||
self.assertEqual(list(chan.aliases.all()).sort(), aliases.sort())
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ class TestDbSerialize(TestCase):
|
|||
"""
|
||||
Database serialization operations.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.obj = DefaultObject(db_key="Tester", )
|
||||
self.obj = DefaultObject(db_key="Tester",)
|
||||
self.obj.save()
|
||||
|
||||
def test_constants(self):
|
||||
|
|
@ -54,5 +55,5 @@ class TestDbSerialize(TestCase):
|
|||
self.assertEqual(self.obj.db.test, [[1, 2, 3], [4, 5, 6]])
|
||||
self.obj.db.test = [{1: 0}, {0: 1}]
|
||||
self.assertEqual(self.obj.db.test, [{1: 0}, {0: 1}])
|
||||
self.obj.db.test.sort(key=lambda d: str(d))
|
||||
self.obj.db.test.sort(key=lambda d: str(d))
|
||||
self.assertEqual(self.obj.db.test, [{0: 1}, {1: 0}])
|
||||
|
|
|
|||
|
|
@ -390,6 +390,7 @@ def iter_to_string(initer, endsep="and", addquote=False):
|
|||
return str(initer[0])
|
||||
return ", ".join(str(v) for v in initer[:-1]) + "%s %s" % (endsep, initer[-1])
|
||||
|
||||
|
||||
# legacy alias
|
||||
list_to_string = iter_to_string
|
||||
|
||||
|
|
@ -1862,8 +1863,6 @@ def display_len(target):
|
|||
return len(target)
|
||||
|
||||
|
||||
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Search handler function
|
||||
# -------------------------------------------------------------------
|
||||
|
|
@ -1911,7 +1910,9 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs):
|
|||
if multimatch_string:
|
||||
error = "%s\n" % multimatch_string
|
||||
else:
|
||||
error = _("More than one match for '{query}' (please narrow target):\n").format(query=query)
|
||||
error = _("More than one match for '{query}' (please narrow target):\n").format(
|
||||
query=query
|
||||
)
|
||||
|
||||
for num, result in enumerate(matches):
|
||||
# we need to consider Commands, where .aliases is a list
|
||||
|
|
|
|||
|
|
@ -65,7 +65,11 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs)
|
|||
try:
|
||||
from_tz = _pytz.timezone(acct_tz)
|
||||
except Exception as err:
|
||||
raise ValueError(_("Timezone string '{acct_tz}' is not a valid timezone ({err})").format(acct_tz=acct_tz, err=err))
|
||||
raise ValueError(
|
||||
_("Timezone string '{acct_tz}' is not a valid timezone ({err})").format(
|
||||
acct_tz=acct_tz, err=err
|
||||
)
|
||||
)
|
||||
else:
|
||||
from_tz = _pytz.UTC
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue