Basic architecture.

This commit is contained in:
Valentin Lorentz 2015-12-19 01:11:57 +01:00
parent 3a5371760f
commit 7568e0d5d3
10 changed files with 222 additions and 0 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
# Text editors
*~
*.swp
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

0
irctest/__init__.py Normal file
View File

38
irctest/__main__.py Normal file
View File

@ -0,0 +1,38 @@
import sys
import unittest
import argparse
import unittest
import functools
import importlib
from .cases import _IrcTestCase
from .basecontrollers import BaseClientController, BaseServerController
def main(args):
try:
module = importlib.import_module(args.module)
except ImportError:
print('Cannot import module {}'.format(args.module), file=sys.stderr)
exit(1)
controller_class = module.get_irctest_controller_class()
if issubclass(controller_class, BaseClientController):
module = 'irctest.clienttests'
elif issubclass(controller_class, BaseClientController):
module = 'irctest.servertests'
else:
print('{}.Controller should be a subclass of '
'irctest.basecontroller.Base{Client,Server}Controller'
.format(args.module),
file=sys.stderr)
exit(1)
_IrcTestCase.controllerClass = controller_class
unittest.main(module=module, argv=[sys.argv[0], 'discover'])
parser = argparse.ArgumentParser(
description='A script to test interoperability of IRC software.')
parser.add_argument('module', type=str,
help='The module used to run the tested program.')
args = parser.parse_args()
main(args)

View File

@ -0,0 +1,9 @@
class _BaseController:
pass
class BaseClientController(_BaseController):
def run(self, hostname, port, authentication):
raise NotImplementedError()
class BaseServerController(_BaseController):
pass

28
irctest/cases.py Normal file
View File

@ -0,0 +1,28 @@
import socket
import unittest
class _IrcTestCase(unittest.TestCase):
controllerClass = None # Will be set by __main__.py
class ClientTestCase(_IrcTestCase):
def setUp(self):
self.controller = self.controllerClass()
self._setUpServer()
def tearDown(self):
del self.controller
self.conn_file.close()
self.conn.close()
self.server.close()
def _setUpServer(self):
"""Creates the server and make it listen."""
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server.bind(('', 0)) # Bind any free port
self.server.listen(1)
def acceptClient(self):
"""Make the server accept a client connection. Blocking."""
(self.conn, addr) = self.server.accept()
self.conn_file = self.conn.makefile()
def getLine(self):
return self.conn_file.readline().strip()

View File

@ -0,0 +1,8 @@
import os
import unittest
def discover():
ts = unittest.TestSuite()
ts.addTests(unittest.defaultTestLoader.discover(os.path.dirname(__file__)))
return ts

View File

@ -0,0 +1,12 @@
from irctest.cases import ClientTestCase
class CapTestCase(ClientTestCase):
def testSendCap(self):
(hostname, port) = self.server.getsockname()
self.controller.run(
hostname=hostname,
port=port,
authentication=None,
)
self.acceptClient()
print(self.getLine())

View File

View File

@ -0,0 +1,43 @@
import os
import tempfile
import subprocess
from irctest.basecontrollers import BaseClientController
TEMPLATE_CONFIG = """
supybot.networks: testnet
supybot.networks.testnet.servers: {hostname}:{port}
"""
class LimnoriaController(BaseClientController):
def __init__(self):
super().__init__()
self.directory = None
self.proc = None
def __del__(self):
if self.proc:
self.proc.kill()
if self.directory:
self.directory.cleanup()
def open_file(self, name):
assert self.directory
return open(os.path.join(self.directory.name, name), 'a')
def create_config(self):
self.directory = tempfile.TemporaryDirectory()
with self.open_file('bot.conf'):
pass
def run(self, hostname, port, authentication):
# Runs a client with the config given as arguments
self.create_config()
with self.open_file('bot.conf') as fd:
fd.write(TEMPLATE_CONFIG.format(
hostname=hostname,
port=port,
))
self.proc = subprocess.Popen(['supybot',
os.path.join(self.directory.name, 'bot.conf')])
def get_irctest_controller_class():
return LimnoriaController

80
setup.py Normal file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2009, James McCoy
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import os
import sys
from distutils.core import setup
if sys.version_info < (3, 2, 0):
sys.stderr.write("This script requires Python 3.2 or newer.")
sys.stderr.write(os.linesep)
sys.exit(-1)
setup(
name='irctest',
version='0.1',
author='Valentin Lorentz',
url='https://github.com/ProgVal/irctest/',
author_email='progval+irctest@progval.net',
description='A script to test interoperability of IRC software.',
platforms=['linux', 'linux2'],
long_description="""This script aims at testing interoperability of
software using the IRC protocol, by running them against test suites
and making different software communicate with each other..""",
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3 :: Only'
'Topic :: Communications :: Chat :: Internet Relay Chat',
'Topic :: Software Development :: Testing',
],
# Installation data
packages=[
'irctest',
],
package_dir={
'irctest': 'irctest',
},
)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: