Use isort to order imports.

This commit is contained in:
2021-02-22 19:04:23 +01:00
committed by Valentin Lorentz
parent 8016e01daf
commit 836cc5d6d2
33 changed files with 209 additions and 180 deletions

View File

@ -4,3 +4,8 @@ repos:
hooks: hooks:
- id: black - id: black
language_version: python3.7 language_version: python3.7
- repo: https://github.com/PyCQA/isort
rev: 5.5.2
hooks:
- id: isort

View File

@ -11,6 +11,9 @@ In short:
* closing brackets/parentheses/... go on the same indent level as the line * closing brackets/parentheses/... go on the same indent level as the line
that opened them that opened them
You can use [pre-commit](https://pre-commit.com/) to automatically run it We also use `isort` to order imports (in short: just
for you when you create a git commit. [follow PEP 8](https://www.python.org/dev/peps/pep-0008/#imports))
You can use [pre-commit](https://pre-commit.com/) to automatically run them
when you create a git commit.
Alternatively, run `pre-commit run -a` Alternatively, run `pre-commit run -a`

View File

@ -2,11 +2,11 @@ import importlib
import sys import sys
import unittest import unittest
import pytest
import _pytest.unittest import _pytest.unittest
import pytest
from irctest.cases import _IrcTestCase, BaseClientTestCase, BaseServerTestCase
from irctest.basecontrollers import BaseClientController, BaseServerController from irctest.basecontrollers import BaseClientController, BaseServerController
from irctest.cases import BaseClientTestCase, BaseServerTestCase, _IrcTestCase
def pytest_addoption(parser): def pytest_addoption(parser):

View File

@ -1,5 +1,5 @@
import enum
import collections import collections
import enum
@enum.unique @enum.unique

View File

@ -1,9 +1,9 @@
import os import os
import shutil import shutil
import socket import socket
import subprocess
import tempfile import tempfile
import time import time
import subprocess
from .runner import NotImplementedByController from .runner import NotImplementedByController

View File

@ -1,28 +1,26 @@
import ssl
import time
import socket
import tempfile
import unittest
import functools import functools
import socket
import ssl
import tempfile
import time
import unittest
import pytest import pytest
from . import runner from . import client_mock, runner
from . import client_mock from .exceptions import ConnectionClosed
from .irc_utils import capabilities from .irc_utils import capabilities, message_parser
from .irc_utils import message_parser
from .irc_utils.junkdrawer import normalizeWhitespace, random_name from .irc_utils.junkdrawer import normalizeWhitespace, random_name
from .irc_utils.sasl import sasl_plain_blob from .irc_utils.sasl import sasl_plain_blob
from .exceptions import ConnectionClosed
from .specifications import Specifications
from .numerics import ( from .numerics import (
ERR_BADCHANNELKEY,
ERR_BANNEDFROMCHAN,
ERR_INVITEONLYCHAN,
ERR_NEEDREGGEDNICK,
ERR_NOSUCHCHANNEL, ERR_NOSUCHCHANNEL,
ERR_TOOMANYCHANNELS, ERR_TOOMANYCHANNELS,
ERR_BADCHANNELKEY,
ERR_INVITEONLYCHAN,
ERR_BANNEDFROMCHAN,
ERR_NEEDREGGEDNICK,
) )
from .specifications import Specifications
CHANNEL_JOIN_FAIL_NUMERICS = frozenset( CHANNEL_JOIN_FAIL_NUMERICS = frozenset(
[ [

View File

@ -1,9 +1,10 @@
import socket
import ssl import ssl
import sys import sys
import time import time
import socket
from .exceptions import ConnectionClosed, NoMessageException
from .irc_utils import message_parser from .irc_utils import message_parser
from .exceptions import NoMessageException, ConnectionClosed
class ClientMock: class ClientMock:

View File

@ -2,15 +2,14 @@ import base64
import hashlib import hashlib
import ecdsa import ecdsa
from ecdsa.util import sigencode_der, sigdecode_der from ecdsa.util import sigdecode_der, sigencode_der
try: try:
import pyxmpp2_scram as scram import pyxmpp2_scram as scram
except ImportError: except ImportError:
scram = None scram = None
from irctest import cases from irctest import authentication, cases
from irctest import authentication
from irctest.irc_utils.message_parser import Message from irctest.irc_utils.message_parser import Message
ECDSA_KEY = """ ECDSA_KEY = """

View File

@ -1,8 +1,7 @@
import socket import socket
import ssl import ssl
from irctest import tls from irctest import cases, tls
from irctest import cases
from irctest.exceptions import ConnectionClosed from irctest.exceptions import ConnectionClosed
from irctest.irc_utils.message_parser import Message from irctest.irc_utils.message_parser import Message

View File

@ -1,13 +1,15 @@
import os import os
import time
import shutil import shutil
import tempfile
import subprocess import subprocess
import tempfile
import time
from irctest import client_mock from irctest import authentication, client_mock
from irctest import authentication from irctest.basecontrollers import (
from irctest.basecontrollers import NotImplementedByController BaseServerController,
from irctest.basecontrollers import BaseServerController, DirectoryBasedController DirectoryBasedController,
NotImplementedByController,
)
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
serverinfo {{ serverinfo {{

View File

@ -1,13 +1,15 @@
import os import os
import time
import shutil import shutil
import tempfile
import subprocess import subprocess
import tempfile
import time
from irctest import client_mock from irctest import authentication, client_mock
from irctest import authentication from irctest.basecontrollers import (
from irctest.basecontrollers import NotImplementedByController BaseServerController,
from irctest.basecontrollers import BaseServerController, DirectoryBasedController DirectoryBasedController,
NotImplementedByController,
)
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
serverinfo {{ serverinfo {{

View File

@ -1,12 +1,15 @@
import os import os
import time
import shutil import shutil
import tempfile
import subprocess import subprocess
import tempfile
import time
from irctest import authentication from irctest import authentication
from irctest.basecontrollers import NotImplementedByController from irctest.basecontrollers import (
from irctest.basecontrollers import BaseServerController, DirectoryBasedController BaseServerController,
DirectoryBasedController,
NotImplementedByController,
)
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
<bind address="{hostname}" port="{port}" type="clients"> <bind address="{hostname}" port="{port}" type="clients">

View File

@ -1,10 +1,12 @@
import os import os
import subprocess import subprocess
from irctest import authentication from irctest import authentication, tls
from irctest import tls from irctest.basecontrollers import (
from irctest.basecontrollers import NotImplementedByController BaseClientController,
from irctest.basecontrollers import BaseClientController, DirectoryBasedController DirectoryBasedController,
NotImplementedByController,
)
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
supybot.directories.conf: {directory}/conf supybot.directories.conf: {directory}/conf

View File

@ -1,9 +1,12 @@
import os import os
import time
import subprocess import subprocess
import time
from irctest.basecontrollers import NotImplementedByController from irctest.basecontrollers import (
from irctest.basecontrollers import BaseServerController, DirectoryBasedController BaseServerController,
DirectoryBasedController,
NotImplementedByController,
)
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
clients: clients:

View File

@ -3,8 +3,11 @@ import json
import os import os
import subprocess import subprocess
from irctest.basecontrollers import NotImplementedByController from irctest.basecontrollers import (
from irctest.basecontrollers import BaseServerController, DirectoryBasedController BaseServerController,
DirectoryBasedController,
NotImplementedByController,
)
OPER_PWD = "frenchfries" OPER_PWD = "frenchfries"

View File

@ -1,9 +1,8 @@
import os import os
import tempfile
import subprocess import subprocess
import tempfile
from irctest.basecontrollers import BaseClientController from irctest.basecontrollers import BaseClientController, NotImplementedByController
from irctest.basecontrollers import NotImplementedByController
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
[core] [core]

View File

@ -1,7 +1,7 @@
from collections import namedtuple
import datetime import datetime
import re import re
import secrets import secrets
from collections import namedtuple
HistoryMessage = namedtuple("HistoryMessage", ["time", "msgid", "target", "text"]) HistoryMessage = namedtuple("HistoryMessage", ["time", "msgid", "target", "text"])

View File

@ -1,5 +1,5 @@
import re
import collections import collections
import re
from .junkdrawer import MultipleReplacer from .junkdrawer import MultipleReplacer

View File

@ -1,6 +1,6 @@
import unittest
import operator
import collections import collections
import operator
import unittest
class NotImplementedByController(unittest.SkipTest, NotImplementedError): class NotImplementedByController(unittest.SkipTest, NotImplementedError):

View File

@ -1,8 +1,6 @@
from irctest import cases from irctest import cases
from irctest.irc_utils.sasl import sasl_plain_blob from irctest.irc_utils.sasl import sasl_plain_blob
from irctest.numerics import ERR_NICKNAMEINUSE, RPL_WELCOME
from irctest.numerics import RPL_WELCOME
from irctest.numerics import ERR_NICKNAMEINUSE
class Bouncer(cases.BaseServerTestCase): class Bouncer(cases.BaseServerTestCase):

View File

@ -3,27 +3,23 @@ Section 3.2 of RFC 2812
<https://tools.ietf.org/html/rfc2812#section-3.2> <https://tools.ietf.org/html/rfc2812#section-3.2>
""" """
from irctest import cases from irctest import cases, client_mock, runner
from irctest import client_mock
from irctest import runner
from irctest.irc_utils import ambiguities from irctest.irc_utils import ambiguities
from irctest.numerics import ( from irctest.numerics import (
ERR_BADCHANNELKEY,
ERR_CANNOTSENDTOCHAN,
ERR_CHANOPRIVSNEEDED,
ERR_INVALIDMODEPARAM,
ERR_INVITEONLYCHAN,
ERR_NOSUCHCHANNEL,
ERR_NOSUCHNICK,
ERR_NOTONCHANNEL,
ERR_UNKNOWNERROR,
RPL_INVITING,
RPL_NAMREPLY,
RPL_NOTOPIC,
RPL_TOPIC, RPL_TOPIC,
RPL_TOPICTIME, RPL_TOPICTIME,
RPL_NOTOPIC,
RPL_NAMREPLY,
RPL_INVITING,
)
from irctest.numerics import (
ERR_NOSUCHCHANNEL,
ERR_NOTONCHANNEL,
ERR_CHANOPRIVSNEEDED,
ERR_NOSUCHNICK,
ERR_INVITEONLYCHAN,
ERR_CANNOTSENDTOCHAN,
ERR_BADCHANNELKEY,
ERR_INVALIDMODEPARAM,
ERR_UNKNOWNERROR,
) )
MODERN_CAPS = [ MODERN_CAPS = [

View File

@ -2,7 +2,7 @@ import secrets
import time import time
from irctest import cases from irctest import cases
from irctest.irc_utils.junkdrawer import to_history_message, random_name from irctest.irc_utils.junkdrawer import random_name, to_history_message
CHATHISTORY_CAP = "draft/chathistory" CHATHISTORY_CAP = "draft/chathistory"
EVENT_PLAYBACK_CAP = "draft/event-playback" EVENT_PLAYBACK_CAP = "draft/event-playback"

View File

@ -1,5 +1,5 @@
from irctest import cases from irctest import cases
from irctest.numerics import RPL_WELCOME, ERR_NICKNAMEINUSE from irctest.numerics import ERR_NICKNAMEINUSE, RPL_WELCOME
class ConfusablesTestCase(cases.BaseServerTestCase): class ConfusablesTestCase(cases.BaseServerTestCase):

View File

@ -1,16 +1,25 @@
from dataclasses import dataclass
import re import re
import time import time
from dataclasses import dataclass
from irctest import cases from irctest import cases
from irctest.numerics import (
from irctest.numerics import RPL_LUSERCLIENT, RPL_LUSEROP, RPL_LUSERUNKNOWN, RPL_LUSERCHANNELS, RPL_LUSERME, RPL_LOCALUSERS, RPL_GLOBALUSERS, ERR_NOTREGISTERED ERR_NOTREGISTERED,
from irctest.numerics import RPL_YOUREOPER RPL_GLOBALUSERS,
RPL_LOCALUSERS,
RPL_LUSERCHANNELS,
RPL_LUSERCLIENT,
RPL_LUSERME,
RPL_LUSEROP,
RPL_LUSERUNKNOWN,
RPL_YOUREOPER,
)
# 3 numbers, delimited by spaces, possibly negative (eek) # 3 numbers, delimited by spaces, possibly negative (eek)
LUSERCLIENT_REGEX = re.compile(r'^.*( [-0-9]* ).*( [-0-9]* ).*( [-0-9]* ).*$') LUSERCLIENT_REGEX = re.compile(r"^.*( [-0-9]* ).*( [-0-9]* ).*( [-0-9]* ).*$")
# 2 numbers # 2 numbers
LUSERME_REGEX = re.compile(r'^.*( [-0-9]* ).*( [-0-9]* ).*$') LUSERME_REGEX = re.compile(r"^.*( [-0-9]* ).*( [-0-9]* ).*$")
@dataclass @dataclass
class LusersResult: class LusersResult:
@ -25,10 +34,10 @@ class LusersResult:
GlobalTotal: int = None GlobalTotal: int = None
GlobalMax: int = None GlobalMax: int = None
class LusersTestCase(cases.BaseServerTestCase):
class LusersTestCase(cases.BaseServerTestCase):
def getLusers(self, client): def getLusers(self, client):
self.sendLine(client, 'LUSERS') self.sendLine(client, "LUSERS")
messages = self.getMessages(client) messages = self.getMessages(client)
by_numeric = dict((msg.command, msg) for msg in messages) by_numeric = dict((msg.command, msg) for msg in messages)
@ -38,7 +47,7 @@ class LusersTestCase(cases.BaseServerTestCase):
for message in messages: for message in messages:
self.assertEqual(client, message.params[0]) self.assertEqual(client, message.params[0])
luserclient = by_numeric[RPL_LUSERCLIENT] # 251 luserclient = by_numeric[RPL_LUSERCLIENT] # 251
self.assertEqual(len(luserclient.params), 2) self.assertEqual(len(luserclient.params), 2)
luserclient_param = luserclient.params[1] luserclient_param = luserclient.params[1]
try: try:
@ -77,12 +86,12 @@ class LusersTestCase(cases.BaseServerTestCase):
return result return result
class BasicLusersTest(LusersTestCase):
@cases.SpecificationSelector.requiredBySpecification('RFC2812') class BasicLusersTest(LusersTestCase):
@cases.SpecificationSelector.requiredBySpecification("RFC2812")
def testLusers(self): def testLusers(self):
self.connectClient('bar', name='bar') self.connectClient("bar", name="bar")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertIn(lusers.Unregistered, (0, None)) self.assertIn(lusers.Unregistered, (0, None))
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
@ -92,8 +101,8 @@ class BasicLusersTest(LusersTestCase):
self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalTotal, 1)
self.assertEqual(lusers.LocalMax, 1) self.assertEqual(lusers.LocalMax, 1)
self.connectClient('qux', name='qux') self.connectClient("qux", name="qux")
lusers = self.getLusers('qux') lusers = self.getLusers("qux")
self.assertIn(lusers.Unregistered, (0, None)) self.assertIn(lusers.Unregistered, (0, None))
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
@ -103,9 +112,9 @@ class BasicLusersTest(LusersTestCase):
self.assertEqual(lusers.LocalTotal, 2) self.assertEqual(lusers.LocalTotal, 2)
self.assertEqual(lusers.LocalMax, 2) self.assertEqual(lusers.LocalMax, 2)
self.sendLine('qux', 'QUIT') self.sendLine("qux", "QUIT")
self.assertDisconnected('qux') self.assertDisconnected("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertIn(lusers.Unregistered, (0, None)) self.assertIn(lusers.Unregistered, (0, None))
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
@ -117,28 +126,27 @@ class BasicLusersTest(LusersTestCase):
class LusersUnregisteredTestCase(LusersTestCase): class LusersUnregisteredTestCase(LusersTestCase):
@cases.SpecificationSelector.requiredBySpecification("RFC2812")
@cases.SpecificationSelector.requiredBySpecification('RFC2812')
def testLusers(self): def testLusers(self):
self.doLusersTest() self.doLusersTest()
def _synchronize(self, client_name): def _synchronize(self, client_name):
"""Synchronizes using a PING, but accept ERR_NOTREGISTERED as a response.""" """Synchronizes using a PING, but accept ERR_NOTREGISTERED as a response."""
self.sendLine(client_name, 'PING') self.sendLine(client_name, "PING")
for _ in range(1000): for _ in range(1000):
msg = self.getRegistrationMessage(client_name) msg = self.getRegistrationMessage(client_name)
if msg.command in (ERR_NOTREGISTERED, 'PONG'): if msg.command in (ERR_NOTREGISTERED, "PONG"):
break break
time.sleep(0.01) time.sleep(0.01)
else: else:
assert False, ( assert False, (
'Sent a PING before registration, ' "Sent a PING before registration, "
'got neither PONG or ERR_NOTREGISTERED' "got neither PONG or ERR_NOTREGISTERED"
) )
def doLusersTest(self): def doLusersTest(self):
self.connectClient('bar', name='bar') self.connectClient("bar", name="bar")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertIn(lusers.Unregistered, (0, None)) self.assertIn(lusers.Unregistered, (0, None))
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
@ -148,10 +156,10 @@ class LusersUnregisteredTestCase(LusersTestCase):
self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalTotal, 1)
self.assertEqual(lusers.LocalMax, 1) self.assertEqual(lusers.LocalMax, 1)
self.addClient('qux') self.addClient("qux")
self.sendLine('qux', 'NICK qux') self.sendLine("qux", "NICK qux")
self._synchronize('qux') self._synchronize("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.Unregistered, 1) self.assertEqual(lusers.Unregistered, 1)
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
@ -161,10 +169,10 @@ class LusersUnregisteredTestCase(LusersTestCase):
self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalTotal, 1)
self.assertEqual(lusers.LocalMax, 1) self.assertEqual(lusers.LocalMax, 1)
self.addClient('bat') self.addClient("bat")
self.sendLine('bat', 'NICK bat') self.sendLine("bat", "NICK bat")
self._synchronize('bat') self._synchronize("bat")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.Unregistered, 2) self.assertEqual(lusers.Unregistered, 2)
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
@ -175,9 +183,9 @@ class LusersUnregisteredTestCase(LusersTestCase):
self.assertEqual(lusers.LocalMax, 1) self.assertEqual(lusers.LocalMax, 1)
# complete registration on one client # complete registration on one client
self.sendLine('qux', 'USER u s e r') self.sendLine("qux", "USER u s e r")
self.getMessages('qux') self.getMessages("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.Unregistered, 1) self.assertEqual(lusers.Unregistered, 1)
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
@ -188,9 +196,9 @@ class LusersUnregisteredTestCase(LusersTestCase):
self.assertEqual(lusers.LocalMax, 2) self.assertEqual(lusers.LocalMax, 2)
# QUIT the other without registering # QUIT the other without registering
self.sendLine('bat', 'QUIT') self.sendLine("bat", "QUIT")
self.assertDisconnected('bat') self.assertDisconnected("bat")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertIn(lusers.Unregistered, (0, None)) self.assertIn(lusers.Unregistered, (0, None))
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
@ -203,18 +211,19 @@ class LusersUnregisteredTestCase(LusersTestCase):
class LusersUnregisteredDefaultInvisibleTest(LusersUnregisteredTestCase): class LusersUnregisteredDefaultInvisibleTest(LusersUnregisteredTestCase):
"""Same as above but with +i as the default.""" """Same as above but with +i as the default."""
@staticmethod @staticmethod
def config(): def config():
return { return {
"oragono_config": lambda config: config['accounts'].update( "oragono_config": lambda config: config["accounts"].update(
{'default-user-modes': '+i'} {"default-user-modes": "+i"}
) )
} }
@cases.SpecificationSelector.requiredBySpecification('Oragono') @cases.SpecificationSelector.requiredBySpecification("Oragono")
def testLusers(self): def testLusers(self):
self.doLusersTest() self.doLusersTest()
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.Unregistered, 0) self.assertEqual(lusers.Unregistered, 0)
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
@ -225,11 +234,10 @@ class LusersUnregisteredDefaultInvisibleTest(LusersUnregisteredTestCase):
class LuserOpersTest(LusersTestCase): class LuserOpersTest(LusersTestCase):
@cases.SpecificationSelector.requiredBySpecification("Oragono")
@cases.SpecificationSelector.requiredBySpecification('Oragono')
def testLuserOpers(self): def testLuserOpers(self):
self.connectClient('bar', name='bar') self.connectClient("bar", name="bar")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
self.assertGreaterEqual(lusers.GlobalInvisible, 0) self.assertGreaterEqual(lusers.GlobalInvisible, 0)
@ -240,10 +248,10 @@ class LuserOpersTest(LusersTestCase):
self.assertIn(lusers.Opers, (0, None)) self.assertIn(lusers.Opers, (0, None))
# add 1 oper # add 1 oper
self.sendLine('bar', 'OPER root frenchfries') self.sendLine("bar", "OPER root frenchfries")
msgs = self.getMessages('bar') msgs = self.getMessages("bar")
self.assertIn(RPL_YOUREOPER, {msg.command for msg in msgs}) self.assertIn(RPL_YOUREOPER, {msg.command for msg in msgs})
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
self.assertGreaterEqual(lusers.GlobalInvisible, 0) self.assertGreaterEqual(lusers.GlobalInvisible, 0)
@ -254,10 +262,10 @@ class LuserOpersTest(LusersTestCase):
self.assertEqual(lusers.Opers, 1) self.assertEqual(lusers.Opers, 1)
# now 2 opers # now 2 opers
self.connectClient('qux', name='qux') self.connectClient("qux", name="qux")
self.sendLine('qux', 'OPER root frenchfries') self.sendLine("qux", "OPER root frenchfries")
self.getMessages('qux') self.getMessages("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertGreaterEqual(lusers.GlobalInvisible, 0) self.assertGreaterEqual(lusers.GlobalInvisible, 0)
@ -268,10 +276,10 @@ class LuserOpersTest(LusersTestCase):
self.assertEqual(lusers.Opers, 2) self.assertEqual(lusers.Opers, 2)
# remove oper with MODE # remove oper with MODE
self.sendLine('bar', 'MODE bar -o') self.sendLine("bar", "MODE bar -o")
msgs = self.getMessages('bar') msgs = self.getMessages("bar")
self.assertIn('MODE', {msg.command for msg in msgs}) self.assertIn("MODE", {msg.command for msg in msgs})
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertGreaterEqual(lusers.GlobalInvisible, 0) self.assertGreaterEqual(lusers.GlobalInvisible, 0)
@ -282,9 +290,9 @@ class LuserOpersTest(LusersTestCase):
self.assertEqual(lusers.Opers, 1) self.assertEqual(lusers.Opers, 1)
# remove oper by quit # remove oper by quit
self.sendLine('qux', 'QUIT') self.sendLine("qux", "QUIT")
self.assertDisconnected('qux') self.assertDisconnected("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertGreaterEqual(lusers.GlobalInvisible, 0) self.assertGreaterEqual(lusers.GlobalInvisible, 0)
@ -299,15 +307,15 @@ class OragonoInvisibleDefaultTest(LusersTestCase):
@staticmethod @staticmethod
def config(): def config():
return { return {
"oragono_config": lambda config: config['accounts'].update( "oragono_config": lambda config: config["accounts"].update(
{'default-user-modes': '+i'} {"default-user-modes": "+i"}
) )
} }
@cases.SpecificationSelector.requiredBySpecification('Oragono') @cases.SpecificationSelector.requiredBySpecification("Oragono")
def testLusers(self): def testLusers(self):
self.connectClient('bar', name='bar') self.connectClient("bar", name="bar")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalMax, 1)
self.assertEqual(lusers.GlobalInvisible, 1) self.assertEqual(lusers.GlobalInvisible, 1)
@ -315,8 +323,8 @@ class OragonoInvisibleDefaultTest(LusersTestCase):
self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalTotal, 1)
self.assertEqual(lusers.LocalMax, 1) self.assertEqual(lusers.LocalMax, 1)
self.connectClient('qux', name='qux') self.connectClient("qux", name="qux")
lusers = self.getLusers('qux') lusers = self.getLusers("qux")
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertEqual(lusers.GlobalInvisible, 2) self.assertEqual(lusers.GlobalInvisible, 2)
@ -325,10 +333,10 @@ class OragonoInvisibleDefaultTest(LusersTestCase):
self.assertEqual(lusers.LocalMax, 2) self.assertEqual(lusers.LocalMax, 2)
# remove +i with MODE # remove +i with MODE
self.sendLine('bar', 'MODE bar -i') self.sendLine("bar", "MODE bar -i")
msgs = self.getMessages('bar') msgs = self.getMessages("bar")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertIn('MODE', {msg.command for msg in msgs}) self.assertIn("MODE", {msg.command for msg in msgs})
self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalTotal, 2)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertEqual(lusers.GlobalInvisible, 1) self.assertEqual(lusers.GlobalInvisible, 1)
@ -337,9 +345,9 @@ class OragonoInvisibleDefaultTest(LusersTestCase):
self.assertEqual(lusers.LocalMax, 2) self.assertEqual(lusers.LocalMax, 2)
# disconnect invisible user # disconnect invisible user
self.sendLine('qux', 'QUIT') self.sendLine("qux", "QUIT")
self.assertDisconnected('qux') self.assertDisconnected("qux")
lusers = self.getLusers('bar') lusers = self.getLusers("bar")
self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalTotal, 1)
self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalMax, 2)
self.assertEqual(lusers.GlobalInvisible, 0) self.assertEqual(lusers.GlobalInvisible, 0)

View File

@ -3,13 +3,13 @@
""" """
from irctest import cases from irctest import cases
from irctest.client_mock import NoMessageException
from irctest.basecontrollers import NotImplementedByController from irctest.basecontrollers import NotImplementedByController
from irctest.client_mock import NoMessageException
from irctest.numerics import ( from irctest.numerics import (
RPL_MONLIST,
RPL_ENDOFMONLIST, RPL_ENDOFMONLIST,
RPL_MONONLINE, RPL_MONLIST,
RPL_MONOFFLINE, RPL_MONOFFLINE,
RPL_MONONLINE,
) )

View File

@ -4,16 +4,16 @@ from irctest import cases
class ReadqTestCase(cases.BaseServerTestCase): class ReadqTestCase(cases.BaseServerTestCase):
"""Test responses to DoS attacks using long lines.""" """Test responses to DoS attacks using long lines."""
@cases.SpecificationSelector.requiredBySpecification('Oragono') @cases.SpecificationSelector.requiredBySpecification("Oragono")
def testReadqTags(self): def testReadqTags(self):
self.connectClient('mallory', name='mallory', capabilities=['message-tags']) self.connectClient("mallory", name="mallory", capabilities=["message-tags"])
self.joinChannel('mallory', '#test') self.joinChannel("mallory", "#test")
self.sendLine('mallory', 'PRIVMSG #test ' + 'a' * 16384) self.sendLine("mallory", "PRIVMSG #test " + "a" * 16384)
self.assertDisconnected('mallory') self.assertDisconnected("mallory")
@cases.SpecificationSelector.requiredBySpecification('Oragono') @cases.SpecificationSelector.requiredBySpecification("Oragono")
def testReadqNoTags(self): def testReadqNoTags(self):
self.connectClient('mallory', name='mallory') self.connectClient("mallory", name="mallory")
self.joinChannel('mallory', '#test') self.joinChannel("mallory", "#test")
self.sendLine('mallory', 'PRIVMSG #test ' + 'a' * 16384) self.sendLine("mallory", "PRIVMSG #test " + "a" * 16384)
self.assertDisconnected('mallory') self.assertDisconnected("mallory")

View File

@ -3,7 +3,6 @@ Regression tests for bugs in oragono.
""" """
from irctest import cases from irctest import cases
from irctest.numerics import ERR_ERRONEUSNICKNAME, ERR_NICKNAMEINUSE, RPL_WELCOME from irctest.numerics import ERR_ERRONEUSNICKNAME, ERR_NICKNAMEINUSE, RPL_WELCOME

View File

@ -2,7 +2,6 @@ from irctest import cases
from irctest.irc_utils.junkdrawer import random_name from irctest.irc_utils.junkdrawer import random_name
from irctest.server_tests.test_chathistory import CHATHISTORY_CAP, EVENT_PLAYBACK_CAP from irctest.server_tests.test_chathistory import CHATHISTORY_CAP, EVENT_PLAYBACK_CAP
RELAYMSG_CAP = "draft/relaymsg" RELAYMSG_CAP = "draft/relaymsg"
RELAYMSG_TAG_NAME = "draft/relaymsg" RELAYMSG_TAG_NAME = "draft/relaymsg"

View File

@ -5,7 +5,6 @@
import secrets import secrets
from irctest import cases from irctest import cases
from irctest.numerics import RPL_AWAY from irctest.numerics import RPL_AWAY
ANCIENT_TIMESTAMP = "2006-01-02T15:04:05.999Z" ANCIENT_TIMESTAMP = "2006-01-02T15:04:05.999Z"

View File

@ -1,6 +1,6 @@
from irctest import cases from irctest import cases
from irctest.numerics import ERR_CANNOTSENDRP
from irctest.irc_utils.junkdrawer import random_name from irctest.irc_utils.junkdrawer import random_name
from irctest.numerics import ERR_CANNOTSENDRP
class RoleplayTestCase(cases.BaseServerTestCase): class RoleplayTestCase(cases.BaseServerTestCase):

View File

@ -5,11 +5,11 @@ User commands as specified in Section 3.6 of RFC 2812:
from irctest import cases from irctest import cases
from irctest.numerics import ( from irctest.numerics import (
RPL_WHOISUSER,
RPL_WHOISCHANNELS,
RPL_AWAY, RPL_AWAY,
RPL_NOWAWAY, RPL_NOWAWAY,
RPL_UNAWAY, RPL_UNAWAY,
RPL_WHOISCHANNELS,
RPL_WHOISUSER,
) )

View File

@ -1,9 +1,11 @@
import time import time
from irctest import cases from irctest import cases
from irctest.irc_utils.junkdrawer import ircv3_timestamp_to_unixtime from irctest.irc_utils.junkdrawer import (
from irctest.irc_utils.junkdrawer import to_history_message ircv3_timestamp_to_unixtime,
from irctest.irc_utils.junkdrawer import random_name random_name,
to_history_message,
)
def extract_playback_privmsgs(messages): def extract_playback_privmsgs(messages):

View File

@ -1,2 +1,11 @@
[tool.black] [tool.black]
target-version = ['py37'] target-version = ['py37']
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
force_sort_within_sections = true