Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 006e28f

Browse files
committed
Merge pull request #43 from jammons/master
Adding initial test for rtmbot and coveralls
2 parents 282ac04 + 1a4b965 commit 006e28f

File tree

7 files changed

+55
-5
lines changed

7 files changed

+55
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ env
88
*.un~
99
0/
1010
tests/.cache
11+
.coverage
12+
.cache

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ python-rtmbot
22
=============
33

44
[![Build Status](https://travis-ci.org/slackhq/python-rtmbot.png)](https://travis-ci.org/slackhq/python-rtmbot)
5+
[![Coverage Status](https://coveralls.io/repos/github/slackhq/python-rtmbot/badge.svg?branch=master)](https://coveralls.io/github/slackhq/python-rtmbot?branch=master)
56

67
A Slack bot written in python that connects via the RTM API.
78

requirements-dev.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
coveralls==1.1
2+
ipdb==0.9.3
3+
ipython==4.1.2
4+
pdbpp==0.8.3
15
pytest>=2.8.2
6+
pytest-cov==2.2.1
27
pytest-pythonpath>=0.3
3-
tox>=1.8.0
8+
testfixtures==4.9.1
9+
tox>=1.8.0

rtmbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from core import *
1+
from .core import *

rtmbot/core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
class RtmBot(object):
1414
def __init__(self, config):
15+
'''
16+
Params:
17+
- config (dict):
18+
- SLACK_TOKEN: your authentication token from Slack
19+
- BASE_PATH (optional: defaults to execution directory) RtmBot will
20+
look in this directory for plugins.
21+
- LOGFILE (optional: defaults to rtmbot.log) The filename for logs, will
22+
be stored inside the BASE_PATH directory
23+
- DEBUG (optional: defaults to False) with debug enabled, RtmBot will
24+
break on errors
25+
'''
1526
# set the config object
1627
self.config = config
1728

@@ -30,7 +41,7 @@ def __init__(self, config):
3041
logging.basicConfig(filename=log_file,
3142
level=logging.INFO,
3243
format='%(asctime)s %(message)s')
33-
logging.info(self.directory)
44+
logging.info('Initialized in: {}'.format(self.directory))
3445
self.debug = self.config.get('DEBUG', False)
3546

3647
# initialize stateful fields

tests/test_rtmbot_core.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from testfixtures import LogCapture
2+
from rtmbot.core import RtmBot
3+
4+
5+
def test_init():
6+
with LogCapture() as l:
7+
rtmbot = RtmBot({
8+
'SLACK_TOKEN': 'test-12345',
9+
'BASE_PATH': '/tmp/',
10+
'LOGFILE': '/tmp/rtmbot.log',
11+
'DEBUG': True
12+
})
13+
14+
assert rtmbot.token == 'test-12345'
15+
assert rtmbot.directory == '/tmp/'
16+
assert rtmbot.debug == True
17+
18+
l.check(
19+
('root', 'INFO', 'Initialized in: /tmp/')
20+
)

tox.ini

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ max-line-length= 100
99
exclude= tests/*
1010

1111
[testenv]
12-
commands=py.test {posargs:tests}
12+
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
13+
commands =
14+
py.test --cov-report= --cov=rtmbot {posargs:tests}
15+
coveralls
16+
1317
deps =
1418
-r{toxinidir}/requirements-dev.txt
19+
-r{toxinidir}/requirements.txt
1520
basepython =
1621
py27: python2.7
1722
py34: python3.4
@@ -20,4 +25,9 @@ basepython =
2025
[testenv:flake8]
2126
basepython=python
2227
deps=flake8
23-
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/rtmbot/core.py {toxinidir}/setup.py {toxinidir}/doc/example-plugins
28+
commands=
29+
flake8 \
30+
{toxinidir}/rtmbot.py \
31+
{toxinidir}/rtmbot/core.py \
32+
{toxinidir}/setup.py \
33+
{toxinidir}/doc/example-plugins

0 commit comments

Comments
 (0)