Apply black to codes

This commit is contained in:
Griatch 2024-04-01 17:51:05 +02:00
parent 870c0f5f75
commit c5a4a34bac
180 changed files with 495 additions and 288 deletions

View file

@ -61,6 +61,7 @@ Xterm256 greyscale:
----
"""
import functools
import re
from collections import OrderedDict

View file

@ -167,6 +167,7 @@ made available in the script namespace.
script = create.create_script()
"""
import codecs
import re
import sys

View file

@ -10,7 +10,6 @@ evennia.OPTION_CLASSES
"""
from pickle import dumps
from django.conf import settings

View file

@ -18,6 +18,7 @@ in-situ, e.g `obj.db.mynestedlist[3][5] = 3` would never be saved and
be out of sync with the database.
"""
from collections import OrderedDict, defaultdict, deque
from collections.abc import MutableMapping, MutableSequence, MutableSet
from functools import update_wrapper

View file

@ -39,10 +39,12 @@ The editor can also be used to format Python code and be made to
survive a reload. See the `EvEditor` class for more details.
"""
import re
from django.conf import settings
from django.utils.translation import gettext as _
from evennia import CmdSet
from evennia.commands import cmdhandler
from evennia.utils import dedent, fill, is_iter, justify, logger, to_str, utils
@ -305,7 +307,11 @@ class CmdEditorBase(_COMMAND_DEFAULT_CLASS):
if arglist and arglist[0].count(":") == 1:
part1, part2 = arglist[0].split(":")
lstart = min(max(1, int(part1)), nlines) - 1 if utils.value_is_integer(part1) else 0
lend = min(max(lstart + 1, int(part2)), nlines) if utils.value_is_integer(part2) else nlines
lend = (
min(max(lstart + 1, int(part2)), nlines)
if utils.value_is_integer(part2)
else nlines
)
linerange = True
elif arglist and arglist[0].isdigit():
lstart = min(max(0, int(arglist[0]) - 1), nlines)
@ -468,7 +474,7 @@ class CmdEditorGroup(CmdEditorBase):
linebuffer = self.linebuffer
lstart, lend = self.lstart, self.lend
# preserve the cmdname including case (otherwise uu and UU would be the same)
cmd = self.raw_string[:len(self.cmdstring)]
cmd = self.raw_string[: len(self.cmdstring)]
echo_mode = self.editor._echo_mode
if cmd == ":":

View file

@ -43,6 +43,7 @@ The `FuncParser` also accepts a direct dict mapping of `{'name': callable, ...}`
---
"""
import dataclasses
import inspect
import random

View file

@ -1,6 +1,7 @@
"""
IDmapper extension to the default manager.
"""
from django.db.models.manager import Manager

View file

@ -13,7 +13,6 @@ log_typemsg(). This is for historical, back-compatible reasons.
"""
import os
import time
from datetime import datetime

View file

@ -22,25 +22,32 @@ Other:
helper. Used by the command-test classes, but can be used for making a customt test class.
"""
import re
import sys
import types
import evennia
from django.conf import settings
from django.test import TestCase, override_settings
from mock import MagicMock, Mock, patch
from twisted.internet.defer import Deferred
import evennia
from evennia import settings_default
from evennia.accounts.accounts import DefaultAccount
from evennia.commands.command import InterruptCommand
from evennia.commands.default.muxcommand import MuxCommand
from evennia.objects.objects import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom
from evennia.objects.objects import (
DefaultCharacter,
DefaultExit,
DefaultObject,
DefaultRoom,
)
from evennia.scripts.scripts import DefaultScript
from evennia.server.serversession import ServerSession
from evennia.utils import ansi, create
from evennia.utils.idmapper.models import flush_cache
from evennia.utils.utils import all_from_module, to_str
from mock import MagicMock, Mock, patch
from twisted.internet.defer import Deferred
_RE_STRIP_EVMENU = re.compile(r"^\+|-+\+|\+-+|--+|\|(?:\s|$)", re.MULTILINE)

View file

@ -23,7 +23,7 @@ class TestEvEditor(BaseEvenniaCommandTest):
self.call(eveditor.CmdLineInput(), "line 5", raw_string="line 5", msg="05line 5")
self.call(
eveditor.CmdEditorGroup(),
"", # list whole buffer
"", # list whole buffer
raw_string=":",
msg="Line Editor []\n01line 1\n02line 2\n"
"03line 3\n04line 4\n05line 5\n"
@ -31,7 +31,7 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(),
":", # list empty range
":", # list empty range
raw_string=":",
msg="Line Editor []\n01line 1\n02line 2\n"
"03line 3\n04line 4\n05line 5\n"
@ -39,7 +39,7 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(),
":4", # list from start to line 4
":4", # list from start to line 4
raw_string=":",
msg="Line Editor []\n01line 1\n02line 2\n"
"03line 3\n04line 4\n"
@ -47,7 +47,7 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(),
"2:", # list from line 2 to end
"2:", # list from line 2 to end
raw_string=":",
msg="Line Editor []\n02line 2\n03line 3\n"
"04line 4\n05line 5\n"
@ -55,7 +55,7 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(),
"-10:10", # try to list invalid range (too large)
"-10:10", # try to list invalid range (too large)
raw_string=":",
msg="Line Editor []\n01line 1\n02line 2\n"
"03line 3\n04line 4\n05line 5\n"
@ -63,10 +63,9 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(),
"3:1", # try to list invalid range (reversed)
"3:1", # try to list invalid range (reversed)
raw_string=":",
msg="Line Editor []\n03line 3\n"
"[l:01 w:002 c:0006](:h for help)",
msg="Line Editor []\n03line 3\n" "[l:01 w:002 c:0006](:h for help)",
)
def test_eveditor_view_cmd(self):
@ -184,7 +183,10 @@ class TestEvEditor(BaseEvenniaCommandTest):
)
self.call(
eveditor.CmdEditorGroup(), "3", raw_string=":x", msg="Line 3, [' test line'] cut." # cut
eveditor.CmdEditorGroup(),
"3",
raw_string=":x",
msg="Line 3, [' test line'] cut.", # cut
)
self.call(

View file

@ -2,6 +2,7 @@
Unit tests for the EvForm text form generator
"""
from unittest import skip
from django.test import TestCase

View file

@ -2,6 +2,7 @@
Unit tests for all sorts of inline text-tag parsing, like ANSI, html conversion, inlinefuncs etc
"""
import re
from django.test import TestCase, override_settings

View file

@ -11,11 +11,12 @@ from datetime import datetime, timedelta
import mock
from django.test import TestCase
from parameterized import parameterized
from twisted.internet import task
from evennia.utils import utils
from evennia.utils.ansi import ANSIString
from evennia.utils.test_resources import BaseEvenniaTest
from parameterized import parameterized
from twisted.internet import task
class TestIsIter(TestCase):
@ -58,15 +59,26 @@ class TestCompressWhitespace(TestCase):
# No text, return no text
self.assertEqual("", utils.compress_whitespace(""))
# If no whitespace is exceeded, should return the same
self.assertEqual("One line\nTwo spaces", utils.compress_whitespace("One line\nTwo spaces"))
self.assertEqual(
"One line\nTwo spaces", utils.compress_whitespace("One line\nTwo spaces")
)
# Extra newlines are removed
self.assertEqual("First line\nSecond line", utils.compress_whitespace("First line\n\nSecond line"))
self.assertEqual(
"First line\nSecond line", utils.compress_whitespace("First line\n\nSecond line")
)
# Extra spaces are removed
self.assertEqual("Too many spaces", utils.compress_whitespace("Too many spaces"))
# "Invisible" extra lines with whitespace are removed
self.assertEqual("First line\nSecond line", utils.compress_whitespace("First line\n \n \nSecond line"))
self.assertEqual(
"First line\nSecond line", utils.compress_whitespace("First line\n \n \nSecond line")
)
# Max kwargs are respected
self.assertEqual("First line\n\nSecond line", utils.compress_whitespace("First line\n\nSecond line", max_spacing=1, max_linebreaks=2))
self.assertEqual(
"First line\n\nSecond line",
utils.compress_whitespace(
"First line\n\nSecond line", max_spacing=1, max_linebreaks=2
),
)
def test_preserve_indents(self):
"""Ensure that indentation spacing is preserved."""
@ -78,6 +90,7 @@ Hanging Indents
# since there is no doubled-up spacing besides indents, input should equal output
self.assertEqual(indented, utils.compress_whitespace(indented))
class TestListToString(TestCase):
"""
Default function header from time.py:

View file

@ -28,7 +28,6 @@ from os.path import join as osjoin
from string import punctuation
from unicodedata import east_asian_width
import evennia
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError
@ -36,12 +35,14 @@ from django.core.validators import validate_email as django_validate_email
from django.utils import timezone
from django.utils.html import strip_tags
from django.utils.translation import gettext as _
from evennia.utils import logger
from simpleeval import simple_eval
from twisted.internet import reactor, threads
from twisted.internet.defer import returnValue # noqa - used as import target
from twisted.internet.task import deferLater
import evennia
from evennia.utils import logger
_MULTIMATCH_TEMPLATE = settings.SEARCH_MULTIMATCH_TEMPLATE
_EVENNIA_DIR = settings.EVENNIA_DIR
_GAME_DIR = settings.GAME_DIR
@ -474,6 +475,7 @@ iter_to_string = iter_to_str
re_empty = re.compile("\n\s*\n")
def compress_whitespace(text, max_linebreaks=1, max_spacing=2):
"""
Removes extra sequential whitespace in a block of text. This will also remove any trailing
@ -492,9 +494,9 @@ def compress_whitespace(text, max_linebreaks=1, max_spacing=2):
# this allows the blank-line compression to eliminate them if needed
text = re_empty.sub("\n\n", text)
# replace groups of extra spaces with the maximum number of spaces
text = re.sub(f"(?<=\S) {{{max_spacing},}}", " "*max_spacing, text)
text = re.sub(f"(?<=\S) {{{max_spacing},}}", " " * max_spacing, text)
# replace groups of extra newlines with the maximum number of newlines
text = re.sub(f"\n{{{max_linebreaks},}}", "\n"*max_linebreaks, text)
text = re.sub(f"\n{{{max_linebreaks},}}", "\n" * max_linebreaks, text)
return text
@ -2402,20 +2404,18 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs):
# result is a typeclassed entity where `.aliases` is an AliasHandler.
aliases = result.aliases.all(return_objs=True)
# remove pluralization aliases
aliases = [
alias.db_key
for alias in aliases
if alias.db_category != "plural_key"
]
aliases = [alias.db_key for alias in aliases if alias.db_category != "plural_key"]
else:
# result is likely a Command, where `.aliases` is a list of strings.
aliases = result.aliases
error += _MULTIMATCH_TEMPLATE.format(
number=num + 1,
name=result.get_display_name(caller)
if hasattr(result, "get_display_name")
else query,
name=(
result.get_display_name(caller)
if hasattr(result, "get_display_name")
else query
),
aliases=" [{alias}]".format(alias=";".join(aliases)) if aliases else "",
info=result.get_extra_info(caller),
)

View file

@ -25,6 +25,7 @@ viewpoint/pronouns Subject Object Possessive Possessive Reflexive
3rd person plural they them their theirs themselves
==================== ======= ======== ========== ========== ===========
"""
from evennia.utils.utils import copy_word_case, is_iter
DEFAULT_PRONOUN_TYPE = "subject pronoun"