Skip to content

Commit 814eefd

Browse files
authored
Test ib3.Bot and ib3.connection.SSL (#8)
Add unit tests for basic behaviors of ib3.Bot and ib3.connection.SSL
1 parent 1edbbc8 commit 814eefd

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

ib3/tests/test_bot.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is part of IRC Bot Behavior Bundle (IB3)
4+
# Copyright (C) 2017 Bryan Davis and contributors
5+
#
6+
# This program is free software: you can redistribute it and/or modify it
7+
# under the terms of the GNU General Public License as published by the Free
8+
# Software Foundation, either version 3 of the License, or (at your option)
9+
# any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
# more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along with
17+
# this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
# Dummy test file that really tests nothing other than that imports succeed
20+
21+
import irc.client
22+
import jaraco.stream
23+
24+
import ib3
25+
26+
27+
def test_construct_sets_lenient_decoding():
28+
bot = ib3.Bot(
29+
server_list=[('localhost', '9999')],
30+
realname='ib3test',
31+
nickname='ib3test',
32+
)
33+
assert len(bot.server_list) == 1
34+
assert jaraco.stream.buffer.LenientDecodingLineBuffer.errors == 'replace'
35+
assert irc.client.ServerConnection.buffer_class == \
36+
jaraco.stream.buffer.LenientDecodingLineBuffer

ib3/tests/test_connection.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is part of IRC Bot Behavior Bundle (IB3)
4+
# Copyright (C) 2017 Bryan Davis and contributors
5+
#
6+
# This program is free software: you can redistribute it and/or modify it
7+
# under the terms of the GNU General Public License as published by the Free
8+
# Software Foundation, either version 3 of the License, or (at your option)
9+
# any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
# more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along with
17+
# this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
try:
20+
from unittest import mock
21+
except ImportError:
22+
import mock
23+
24+
import ssl
25+
26+
import ib3
27+
import ib3.connection
28+
29+
30+
class SSLBot(ib3.connection.SSL, ib3.Bot):
31+
pass
32+
33+
34+
@mock.patch('irc.bot.SingleServerIRCBot.__init__')
35+
@mock.patch('irc.connection.Factory')
36+
def test_ssl(conn_factory, mock_init):
37+
bot = SSLBot(
38+
server_list=[('localhost', '9999')],
39+
realname='ib3test',
40+
nickname='ib3test',
41+
)
42+
assert isinstance(bot, ib3.connection.SSL)
43+
assert isinstance(bot, ib3.Bot)
44+
conn_factory.assert_called_once_with(wrapper=ssl.wrap_socket)
45+
args, kwargs = mock_init.call_args
46+
assert kwargs['connect_factory'] is conn_factory.return_value

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
tests_require = [
1414
'coverage',
15+
"mock; python_version<'3.3'",
1516
'nose>=1.0',
1617
]
1718

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ deps=
88
-r{toxinidir}/requirements.txt
99
coverage
1010
nose
11+
py27: mock
1112
setenv=
1213
PYTHONDONTWRITEBYTECODE=true
1314
commands=

0 commit comments

Comments
 (0)