diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4e6356..ef4bdd8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,3 +4,8 @@ repos: hooks: - id: black language_version: python3.7 + + - repo: https://github.com/PyCQA/isort + rev: 5.5.2 + hooks: + - id: isort diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07c1419..790154e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,9 @@ In short: * closing brackets/parentheses/... go on the same indent level as the line that opened them -You can use [pre-commit](https://pre-commit.com/) to automatically run it -for you when you create a git commit. +We also use `isort` to order imports (in short: just +[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` diff --git a/conftest.py b/conftest.py index 8aea757..f991321 100644 --- a/conftest.py +++ b/conftest.py @@ -2,11 +2,11 @@ import importlib import sys import unittest -import pytest import _pytest.unittest +import pytest -from irctest.cases import _IrcTestCase, BaseClientTestCase, BaseServerTestCase from irctest.basecontrollers import BaseClientController, BaseServerController +from irctest.cases import BaseClientTestCase, BaseServerTestCase, _IrcTestCase def pytest_addoption(parser): diff --git a/irctest/authentication.py b/irctest/authentication.py index e6c2dde..eec2bec 100644 --- a/irctest/authentication.py +++ b/irctest/authentication.py @@ -1,5 +1,5 @@ -import enum import collections +import enum @enum.unique diff --git a/irctest/basecontrollers.py b/irctest/basecontrollers.py index 211c9db..aaaf67d 100644 --- a/irctest/basecontrollers.py +++ b/irctest/basecontrollers.py @@ -1,9 +1,9 @@ import os import shutil import socket +import subprocess import tempfile import time -import subprocess from .runner import NotImplementedByController diff --git a/irctest/cases.py b/irctest/cases.py index 782afad..0f3b75f 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -1,28 +1,26 @@ -import ssl -import time -import socket -import tempfile -import unittest import functools +import socket +import ssl +import tempfile +import time +import unittest import pytest -from . import runner -from . import client_mock -from .irc_utils import capabilities -from .irc_utils import message_parser +from . import client_mock, runner +from .exceptions import ConnectionClosed +from .irc_utils import capabilities, message_parser from .irc_utils.junkdrawer import normalizeWhitespace, random_name from .irc_utils.sasl import sasl_plain_blob -from .exceptions import ConnectionClosed -from .specifications import Specifications from .numerics import ( + ERR_BADCHANNELKEY, + ERR_BANNEDFROMCHAN, + ERR_INVITEONLYCHAN, + ERR_NEEDREGGEDNICK, ERR_NOSUCHCHANNEL, ERR_TOOMANYCHANNELS, - ERR_BADCHANNELKEY, - ERR_INVITEONLYCHAN, - ERR_BANNEDFROMCHAN, - ERR_NEEDREGGEDNICK, ) +from .specifications import Specifications CHANNEL_JOIN_FAIL_NUMERICS = frozenset( [ diff --git a/irctest/client_mock.py b/irctest/client_mock.py index 1c679c4..dd2086c 100644 --- a/irctest/client_mock.py +++ b/irctest/client_mock.py @@ -1,9 +1,10 @@ +import socket import ssl import sys import time -import socket + +from .exceptions import ConnectionClosed, NoMessageException from .irc_utils import message_parser -from .exceptions import NoMessageException, ConnectionClosed class ClientMock: diff --git a/irctest/client_tests/test_sasl.py b/irctest/client_tests/test_sasl.py index e8a4f45..81743a0 100644 --- a/irctest/client_tests/test_sasl.py +++ b/irctest/client_tests/test_sasl.py @@ -2,15 +2,14 @@ import base64 import hashlib import ecdsa -from ecdsa.util import sigencode_der, sigdecode_der +from ecdsa.util import sigdecode_der, sigencode_der try: import pyxmpp2_scram as scram except ImportError: scram = None -from irctest import cases -from irctest import authentication +from irctest import authentication, cases from irctest.irc_utils.message_parser import Message ECDSA_KEY = """ diff --git a/irctest/client_tests/test_tls.py b/irctest/client_tests/test_tls.py index c13832c..34be0e0 100644 --- a/irctest/client_tests/test_tls.py +++ b/irctest/client_tests/test_tls.py @@ -1,8 +1,7 @@ import socket import ssl -from irctest import tls -from irctest import cases +from irctest import cases, tls from irctest.exceptions import ConnectionClosed from irctest.irc_utils.message_parser import Message diff --git a/irctest/controllers/charybdis.py b/irctest/controllers/charybdis.py index 498c989..1336155 100644 --- a/irctest/controllers/charybdis.py +++ b/irctest/controllers/charybdis.py @@ -1,13 +1,15 @@ import os -import time import shutil -import tempfile import subprocess +import tempfile +import time -from irctest import client_mock -from irctest import authentication -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseServerController, DirectoryBasedController +from irctest import authentication, client_mock +from irctest.basecontrollers import ( + BaseServerController, + DirectoryBasedController, + NotImplementedByController, +) TEMPLATE_CONFIG = """ serverinfo {{ diff --git a/irctest/controllers/hybrid.py b/irctest/controllers/hybrid.py index 3b2fc28..c277259 100644 --- a/irctest/controllers/hybrid.py +++ b/irctest/controllers/hybrid.py @@ -1,13 +1,15 @@ import os -import time import shutil -import tempfile import subprocess +import tempfile +import time -from irctest import client_mock -from irctest import authentication -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseServerController, DirectoryBasedController +from irctest import authentication, client_mock +from irctest.basecontrollers import ( + BaseServerController, + DirectoryBasedController, + NotImplementedByController, +) TEMPLATE_CONFIG = """ serverinfo {{ diff --git a/irctest/controllers/inspircd.py b/irctest/controllers/inspircd.py index 0ea8502..9ead13f 100644 --- a/irctest/controllers/inspircd.py +++ b/irctest/controllers/inspircd.py @@ -1,12 +1,15 @@ import os -import time import shutil -import tempfile import subprocess +import tempfile +import time from irctest import authentication -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseServerController, DirectoryBasedController +from irctest.basecontrollers import ( + BaseServerController, + DirectoryBasedController, + NotImplementedByController, +) TEMPLATE_CONFIG = """ diff --git a/irctest/controllers/limnoria.py b/irctest/controllers/limnoria.py index ae00f63..1b74143 100644 --- a/irctest/controllers/limnoria.py +++ b/irctest/controllers/limnoria.py @@ -1,10 +1,12 @@ import os import subprocess -from irctest import authentication -from irctest import tls -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseClientController, DirectoryBasedController +from irctest import authentication, tls +from irctest.basecontrollers import ( + BaseClientController, + DirectoryBasedController, + NotImplementedByController, +) TEMPLATE_CONFIG = """ supybot.directories.conf: {directory}/conf diff --git a/irctest/controllers/mammon.py b/irctest/controllers/mammon.py index de786f2..54bcd00 100644 --- a/irctest/controllers/mammon.py +++ b/irctest/controllers/mammon.py @@ -1,9 +1,12 @@ import os -import time import subprocess +import time -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseServerController, DirectoryBasedController +from irctest.basecontrollers import ( + BaseServerController, + DirectoryBasedController, + NotImplementedByController, +) TEMPLATE_CONFIG = """ clients: diff --git a/irctest/controllers/oragono.py b/irctest/controllers/oragono.py index 85db19c..a025317 100644 --- a/irctest/controllers/oragono.py +++ b/irctest/controllers/oragono.py @@ -3,8 +3,11 @@ import json import os import subprocess -from irctest.basecontrollers import NotImplementedByController -from irctest.basecontrollers import BaseServerController, DirectoryBasedController +from irctest.basecontrollers import ( + BaseServerController, + DirectoryBasedController, + NotImplementedByController, +) OPER_PWD = "frenchfries" diff --git a/irctest/controllers/sopel.py b/irctest/controllers/sopel.py index 26d6a20..56f6129 100644 --- a/irctest/controllers/sopel.py +++ b/irctest/controllers/sopel.py @@ -1,9 +1,8 @@ import os -import tempfile import subprocess +import tempfile -from irctest.basecontrollers import BaseClientController -from irctest.basecontrollers import NotImplementedByController +from irctest.basecontrollers import BaseClientController, NotImplementedByController TEMPLATE_CONFIG = """ [core] diff --git a/irctest/irc_utils/junkdrawer.py b/irctest/irc_utils/junkdrawer.py index 3bd7bb3..2c4bf22 100644 --- a/irctest/irc_utils/junkdrawer.py +++ b/irctest/irc_utils/junkdrawer.py @@ -1,7 +1,7 @@ +from collections import namedtuple import datetime import re import secrets -from collections import namedtuple HistoryMessage = namedtuple("HistoryMessage", ["time", "msgid", "target", "text"]) diff --git a/irctest/irc_utils/message_parser.py b/irctest/irc_utils/message_parser.py index d6303b4..3b68fd0 100644 --- a/irctest/irc_utils/message_parser.py +++ b/irctest/irc_utils/message_parser.py @@ -1,5 +1,5 @@ -import re import collections +import re from .junkdrawer import MultipleReplacer diff --git a/irctest/runner.py b/irctest/runner.py index 3b2e9a9..4692813 100644 --- a/irctest/runner.py +++ b/irctest/runner.py @@ -1,6 +1,6 @@ -import unittest -import operator import collections +import operator +import unittest class NotImplementedByController(unittest.SkipTest, NotImplementedError): diff --git a/irctest/server_tests/test_bouncer.py b/irctest/server_tests/test_bouncer.py index 2087647..604ee77 100644 --- a/irctest/server_tests/test_bouncer.py +++ b/irctest/server_tests/test_bouncer.py @@ -1,8 +1,6 @@ from irctest import cases from irctest.irc_utils.sasl import sasl_plain_blob - -from irctest.numerics import RPL_WELCOME -from irctest.numerics import ERR_NICKNAMEINUSE +from irctest.numerics import ERR_NICKNAMEINUSE, RPL_WELCOME class Bouncer(cases.BaseServerTestCase): diff --git a/irctest/server_tests/test_channel_operations.py b/irctest/server_tests/test_channel_operations.py index c48f6f8..17d3198 100644 --- a/irctest/server_tests/test_channel_operations.py +++ b/irctest/server_tests/test_channel_operations.py @@ -3,27 +3,23 @@ Section 3.2 of RFC 2812 """ -from irctest import cases -from irctest import client_mock -from irctest import runner +from irctest import cases, client_mock, runner from irctest.irc_utils import ambiguities 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_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 = [ diff --git a/irctest/server_tests/test_chathistory.py b/irctest/server_tests/test_chathistory.py index 61b7599..ed978c7 100644 --- a/irctest/server_tests/test_chathistory.py +++ b/irctest/server_tests/test_chathistory.py @@ -2,7 +2,7 @@ import secrets import time 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" EVENT_PLAYBACK_CAP = "draft/event-playback" diff --git a/irctest/server_tests/test_confusables.py b/irctest/server_tests/test_confusables.py index 0f25bf6..f60fcaa 100644 --- a/irctest/server_tests/test_confusables.py +++ b/irctest/server_tests/test_confusables.py @@ -1,5 +1,5 @@ from irctest import cases -from irctest.numerics import RPL_WELCOME, ERR_NICKNAMEINUSE +from irctest.numerics import ERR_NICKNAMEINUSE, RPL_WELCOME class ConfusablesTestCase(cases.BaseServerTestCase): diff --git a/irctest/server_tests/test_lusers.py b/irctest/server_tests/test_lusers.py index 806718f..5fb5ad4 100644 --- a/irctest/server_tests/test_lusers.py +++ b/irctest/server_tests/test_lusers.py @@ -1,16 +1,25 @@ +from dataclasses import dataclass import re import time -from dataclasses import dataclass from irctest import cases - -from irctest.numerics import RPL_LUSERCLIENT, RPL_LUSEROP, RPL_LUSERUNKNOWN, RPL_LUSERCHANNELS, RPL_LUSERME, RPL_LOCALUSERS, RPL_GLOBALUSERS, ERR_NOTREGISTERED -from irctest.numerics import RPL_YOUREOPER +from irctest.numerics import ( + ERR_NOTREGISTERED, + RPL_GLOBALUSERS, + RPL_LOCALUSERS, + RPL_LUSERCHANNELS, + RPL_LUSERCLIENT, + RPL_LUSERME, + RPL_LUSEROP, + RPL_LUSERUNKNOWN, + RPL_YOUREOPER, +) # 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 -LUSERME_REGEX = re.compile(r'^.*( [-0-9]* ).*( [-0-9]* ).*$') +LUSERME_REGEX = re.compile(r"^.*( [-0-9]* ).*( [-0-9]* ).*$") + @dataclass class LusersResult: @@ -25,10 +34,10 @@ class LusersResult: GlobalTotal: int = None GlobalMax: int = None -class LusersTestCase(cases.BaseServerTestCase): +class LusersTestCase(cases.BaseServerTestCase): def getLusers(self, client): - self.sendLine(client, 'LUSERS') + self.sendLine(client, "LUSERS") messages = self.getMessages(client) by_numeric = dict((msg.command, msg) for msg in messages) @@ -38,7 +47,7 @@ class LusersTestCase(cases.BaseServerTestCase): for message in messages: self.assertEqual(client, message.params[0]) - luserclient = by_numeric[RPL_LUSERCLIENT] # 251 + luserclient = by_numeric[RPL_LUSERCLIENT] # 251 self.assertEqual(len(luserclient.params), 2) luserclient_param = luserclient.params[1] try: @@ -77,12 +86,12 @@ class LusersTestCase(cases.BaseServerTestCase): return result -class BasicLusersTest(LusersTestCase): - @cases.SpecificationSelector.requiredBySpecification('RFC2812') +class BasicLusersTest(LusersTestCase): + @cases.SpecificationSelector.requiredBySpecification("RFC2812") def testLusers(self): - self.connectClient('bar', name='bar') - lusers = self.getLusers('bar') + self.connectClient("bar", name="bar") + lusers = self.getLusers("bar") self.assertIn(lusers.Unregistered, (0, None)) self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) @@ -92,8 +101,8 @@ class BasicLusersTest(LusersTestCase): self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalMax, 1) - self.connectClient('qux', name='qux') - lusers = self.getLusers('qux') + self.connectClient("qux", name="qux") + lusers = self.getLusers("qux") self.assertIn(lusers.Unregistered, (0, None)) self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) @@ -103,9 +112,9 @@ class BasicLusersTest(LusersTestCase): self.assertEqual(lusers.LocalTotal, 2) self.assertEqual(lusers.LocalMax, 2) - self.sendLine('qux', 'QUIT') - self.assertDisconnected('qux') - lusers = self.getLusers('bar') + self.sendLine("qux", "QUIT") + self.assertDisconnected("qux") + lusers = self.getLusers("bar") self.assertIn(lusers.Unregistered, (0, None)) self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 2) @@ -117,28 +126,27 @@ class BasicLusersTest(LusersTestCase): class LusersUnregisteredTestCase(LusersTestCase): - - @cases.SpecificationSelector.requiredBySpecification('RFC2812') + @cases.SpecificationSelector.requiredBySpecification("RFC2812") def testLusers(self): self.doLusersTest() def _synchronize(self, client_name): """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): msg = self.getRegistrationMessage(client_name) - if msg.command in (ERR_NOTREGISTERED, 'PONG'): + if msg.command in (ERR_NOTREGISTERED, "PONG"): break time.sleep(0.01) else: assert False, ( - 'Sent a PING before registration, ' - 'got neither PONG or ERR_NOTREGISTERED' + "Sent a PING before registration, " + "got neither PONG or ERR_NOTREGISTERED" ) def doLusersTest(self): - self.connectClient('bar', name='bar') - lusers = self.getLusers('bar') + self.connectClient("bar", name="bar") + lusers = self.getLusers("bar") self.assertIn(lusers.Unregistered, (0, None)) self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) @@ -148,10 +156,10 @@ class LusersUnregisteredTestCase(LusersTestCase): self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalMax, 1) - self.addClient('qux') - self.sendLine('qux', 'NICK qux') - self._synchronize('qux') - lusers = self.getLusers('bar') + self.addClient("qux") + self.sendLine("qux", "NICK qux") + self._synchronize("qux") + lusers = self.getLusers("bar") self.assertEqual(lusers.Unregistered, 1) self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) @@ -161,10 +169,10 @@ class LusersUnregisteredTestCase(LusersTestCase): self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalMax, 1) - self.addClient('bat') - self.sendLine('bat', 'NICK bat') - self._synchronize('bat') - lusers = self.getLusers('bar') + self.addClient("bat") + self.sendLine("bat", "NICK bat") + self._synchronize("bat") + lusers = self.getLusers("bar") self.assertEqual(lusers.Unregistered, 2) self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) @@ -175,9 +183,9 @@ class LusersUnregisteredTestCase(LusersTestCase): self.assertEqual(lusers.LocalMax, 1) # complete registration on one client - self.sendLine('qux', 'USER u s e r') - self.getMessages('qux') - lusers = self.getLusers('bar') + self.sendLine("qux", "USER u s e r") + self.getMessages("qux") + lusers = self.getLusers("bar") self.assertEqual(lusers.Unregistered, 1) self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) @@ -188,9 +196,9 @@ class LusersUnregisteredTestCase(LusersTestCase): self.assertEqual(lusers.LocalMax, 2) # QUIT the other without registering - self.sendLine('bat', 'QUIT') - self.assertDisconnected('bat') - lusers = self.getLusers('bar') + self.sendLine("bat", "QUIT") + self.assertDisconnected("bat") + lusers = self.getLusers("bar") self.assertIn(lusers.Unregistered, (0, None)) self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) @@ -203,18 +211,19 @@ class LusersUnregisteredTestCase(LusersTestCase): class LusersUnregisteredDefaultInvisibleTest(LusersUnregisteredTestCase): """Same as above but with +i as the default.""" + @staticmethod def config(): return { - "oragono_config": lambda config: config['accounts'].update( - {'default-user-modes': '+i'} + "oragono_config": lambda config: config["accounts"].update( + {"default-user-modes": "+i"} ) } - @cases.SpecificationSelector.requiredBySpecification('Oragono') + @cases.SpecificationSelector.requiredBySpecification("Oragono") def testLusers(self): self.doLusersTest() - lusers = self.getLusers('bar') + lusers = self.getLusers("bar") self.assertEqual(lusers.Unregistered, 0) self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) @@ -225,11 +234,10 @@ class LusersUnregisteredDefaultInvisibleTest(LusersUnregisteredTestCase): class LuserOpersTest(LusersTestCase): - - @cases.SpecificationSelector.requiredBySpecification('Oragono') + @cases.SpecificationSelector.requiredBySpecification("Oragono") def testLuserOpers(self): - self.connectClient('bar', name='bar') - lusers = self.getLusers('bar') + self.connectClient("bar", name="bar") + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) self.assertGreaterEqual(lusers.GlobalInvisible, 0) @@ -240,10 +248,10 @@ class LuserOpersTest(LusersTestCase): self.assertIn(lusers.Opers, (0, None)) # add 1 oper - self.sendLine('bar', 'OPER root frenchfries') - msgs = self.getMessages('bar') + self.sendLine("bar", "OPER root frenchfries") + msgs = self.getMessages("bar") 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.GlobalMax, 1) self.assertGreaterEqual(lusers.GlobalInvisible, 0) @@ -254,10 +262,10 @@ class LuserOpersTest(LusersTestCase): self.assertEqual(lusers.Opers, 1) # now 2 opers - self.connectClient('qux', name='qux') - self.sendLine('qux', 'OPER root frenchfries') - self.getMessages('qux') - lusers = self.getLusers('bar') + self.connectClient("qux", name="qux") + self.sendLine("qux", "OPER root frenchfries") + self.getMessages("qux") + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) self.assertGreaterEqual(lusers.GlobalInvisible, 0) @@ -268,10 +276,10 @@ class LuserOpersTest(LusersTestCase): self.assertEqual(lusers.Opers, 2) # remove oper with MODE - self.sendLine('bar', 'MODE bar -o') - msgs = self.getMessages('bar') - self.assertIn('MODE', {msg.command for msg in msgs}) - lusers = self.getLusers('bar') + self.sendLine("bar", "MODE bar -o") + msgs = self.getMessages("bar") + self.assertIn("MODE", {msg.command for msg in msgs}) + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) self.assertGreaterEqual(lusers.GlobalInvisible, 0) @@ -282,9 +290,9 @@ class LuserOpersTest(LusersTestCase): self.assertEqual(lusers.Opers, 1) # remove oper by quit - self.sendLine('qux', 'QUIT') - self.assertDisconnected('qux') - lusers = self.getLusers('bar') + self.sendLine("qux", "QUIT") + self.assertDisconnected("qux") + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 2) self.assertGreaterEqual(lusers.GlobalInvisible, 0) @@ -299,15 +307,15 @@ class OragonoInvisibleDefaultTest(LusersTestCase): @staticmethod def config(): return { - "oragono_config": lambda config: config['accounts'].update( - {'default-user-modes': '+i'} + "oragono_config": lambda config: config["accounts"].update( + {"default-user-modes": "+i"} ) } - @cases.SpecificationSelector.requiredBySpecification('Oragono') + @cases.SpecificationSelector.requiredBySpecification("Oragono") def testLusers(self): - self.connectClient('bar', name='bar') - lusers = self.getLusers('bar') + self.connectClient("bar", name="bar") + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 1) self.assertEqual(lusers.GlobalInvisible, 1) @@ -315,8 +323,8 @@ class OragonoInvisibleDefaultTest(LusersTestCase): self.assertEqual(lusers.LocalTotal, 1) self.assertEqual(lusers.LocalMax, 1) - self.connectClient('qux', name='qux') - lusers = self.getLusers('qux') + self.connectClient("qux", name="qux") + lusers = self.getLusers("qux") self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalInvisible, 2) @@ -325,10 +333,10 @@ class OragonoInvisibleDefaultTest(LusersTestCase): self.assertEqual(lusers.LocalMax, 2) # remove +i with MODE - self.sendLine('bar', 'MODE bar -i') - msgs = self.getMessages('bar') - lusers = self.getLusers('bar') - self.assertIn('MODE', {msg.command for msg in msgs}) + self.sendLine("bar", "MODE bar -i") + msgs = self.getMessages("bar") + lusers = self.getLusers("bar") + self.assertIn("MODE", {msg.command for msg in msgs}) self.assertEqual(lusers.GlobalTotal, 2) self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalInvisible, 1) @@ -337,9 +345,9 @@ class OragonoInvisibleDefaultTest(LusersTestCase): self.assertEqual(lusers.LocalMax, 2) # disconnect invisible user - self.sendLine('qux', 'QUIT') - self.assertDisconnected('qux') - lusers = self.getLusers('bar') + self.sendLine("qux", "QUIT") + self.assertDisconnected("qux") + lusers = self.getLusers("bar") self.assertEqual(lusers.GlobalTotal, 1) self.assertEqual(lusers.GlobalMax, 2) self.assertEqual(lusers.GlobalInvisible, 0) diff --git a/irctest/server_tests/test_monitor.py b/irctest/server_tests/test_monitor.py index 9cd9927..3dc057c 100644 --- a/irctest/server_tests/test_monitor.py +++ b/irctest/server_tests/test_monitor.py @@ -3,13 +3,13 @@ """ from irctest import cases -from irctest.client_mock import NoMessageException from irctest.basecontrollers import NotImplementedByController +from irctest.client_mock import NoMessageException from irctest.numerics import ( - RPL_MONLIST, RPL_ENDOFMONLIST, - RPL_MONONLINE, + RPL_MONLIST, RPL_MONOFFLINE, + RPL_MONONLINE, ) diff --git a/irctest/server_tests/test_readq.py b/irctest/server_tests/test_readq.py index e5abf31..2799e2a 100644 --- a/irctest/server_tests/test_readq.py +++ b/irctest/server_tests/test_readq.py @@ -4,16 +4,16 @@ from irctest import cases class ReadqTestCase(cases.BaseServerTestCase): """Test responses to DoS attacks using long lines.""" - @cases.SpecificationSelector.requiredBySpecification('Oragono') + @cases.SpecificationSelector.requiredBySpecification("Oragono") def testReadqTags(self): - self.connectClient('mallory', name='mallory', capabilities=['message-tags']) - self.joinChannel('mallory', '#test') - self.sendLine('mallory', 'PRIVMSG #test ' + 'a' * 16384) - self.assertDisconnected('mallory') + self.connectClient("mallory", name="mallory", capabilities=["message-tags"]) + self.joinChannel("mallory", "#test") + self.sendLine("mallory", "PRIVMSG #test " + "a" * 16384) + self.assertDisconnected("mallory") - @cases.SpecificationSelector.requiredBySpecification('Oragono') + @cases.SpecificationSelector.requiredBySpecification("Oragono") def testReadqNoTags(self): - self.connectClient('mallory', name='mallory') - self.joinChannel('mallory', '#test') - self.sendLine('mallory', 'PRIVMSG #test ' + 'a' * 16384) - self.assertDisconnected('mallory') + self.connectClient("mallory", name="mallory") + self.joinChannel("mallory", "#test") + self.sendLine("mallory", "PRIVMSG #test " + "a" * 16384) + self.assertDisconnected("mallory") diff --git a/irctest/server_tests/test_regressions.py b/irctest/server_tests/test_regressions.py index bfd5c2a..03d9909 100644 --- a/irctest/server_tests/test_regressions.py +++ b/irctest/server_tests/test_regressions.py @@ -3,7 +3,6 @@ Regression tests for bugs in oragono. """ from irctest import cases - from irctest.numerics import ERR_ERRONEUSNICKNAME, ERR_NICKNAMEINUSE, RPL_WELCOME diff --git a/irctest/server_tests/test_relaymsg.py b/irctest/server_tests/test_relaymsg.py index bdfbee6..1374e3d 100644 --- a/irctest/server_tests/test_relaymsg.py +++ b/irctest/server_tests/test_relaymsg.py @@ -2,7 +2,6 @@ from irctest import cases from irctest.irc_utils.junkdrawer import random_name from irctest.server_tests.test_chathistory import CHATHISTORY_CAP, EVENT_PLAYBACK_CAP - RELAYMSG_CAP = "draft/relaymsg" RELAYMSG_TAG_NAME = "draft/relaymsg" diff --git a/irctest/server_tests/test_resume.py b/irctest/server_tests/test_resume.py index aa3bfb9..96017b0 100644 --- a/irctest/server_tests/test_resume.py +++ b/irctest/server_tests/test_resume.py @@ -5,7 +5,6 @@ import secrets from irctest import cases - from irctest.numerics import RPL_AWAY ANCIENT_TIMESTAMP = "2006-01-02T15:04:05.999Z" diff --git a/irctest/server_tests/test_roleplay.py b/irctest/server_tests/test_roleplay.py index 1689a94..297fa4a 100644 --- a/irctest/server_tests/test_roleplay.py +++ b/irctest/server_tests/test_roleplay.py @@ -1,6 +1,6 @@ from irctest import cases -from irctest.numerics import ERR_CANNOTSENDRP from irctest.irc_utils.junkdrawer import random_name +from irctest.numerics import ERR_CANNOTSENDRP class RoleplayTestCase(cases.BaseServerTestCase): diff --git a/irctest/server_tests/test_user_commands.py b/irctest/server_tests/test_user_commands.py index e3fbede..1eb7184 100644 --- a/irctest/server_tests/test_user_commands.py +++ b/irctest/server_tests/test_user_commands.py @@ -5,11 +5,11 @@ User commands as specified in Section 3.6 of RFC 2812: from irctest import cases from irctest.numerics import ( - RPL_WHOISUSER, - RPL_WHOISCHANNELS, RPL_AWAY, RPL_NOWAWAY, RPL_UNAWAY, + RPL_WHOISCHANNELS, + RPL_WHOISUSER, ) diff --git a/irctest/server_tests/test_znc_playback.py b/irctest/server_tests/test_znc_playback.py index a8bb277..aa430df 100644 --- a/irctest/server_tests/test_znc_playback.py +++ b/irctest/server_tests/test_znc_playback.py @@ -1,9 +1,11 @@ import time from irctest import cases -from irctest.irc_utils.junkdrawer import ircv3_timestamp_to_unixtime -from irctest.irc_utils.junkdrawer import to_history_message -from irctest.irc_utils.junkdrawer import random_name +from irctest.irc_utils.junkdrawer import ( + ircv3_timestamp_to_unixtime, + random_name, + to_history_message, +) def extract_playback_privmsgs(messages): diff --git a/pyproject.toml b/pyproject.toml index b5413f6..69b8f4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,11 @@ [tool.black] 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