Adding initial test for rtmbot and hopefully coveralls
This commit is contained in:
parent
60b7b2ebad
commit
ef76bd58d2
6 changed files with 53 additions and 5 deletions
|
@ -2,6 +2,7 @@ python-rtmbot
|
|||
=============
|
||||
|
||||
[](https://travis-ci.org/slackhq/python-rtmbot)
|
||||
[](https://coveralls.io/github/slackhq/python-rtmbot?branch=master)
|
||||
|
||||
A Slack bot written in python that connects via the RTM API.
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
coveralls==1.1
|
||||
ipdb==0.9.3
|
||||
ipython==4.1.2
|
||||
pdbpp==0.8.3
|
||||
pytest>=2.8.2
|
||||
pytest-cov==2.2.1
|
||||
pytest-pythonpath>=0.3
|
||||
tox>=1.8.0
|
||||
testfixtures==4.9.1
|
||||
tox>=1.8.0
|
||||
|
|
|
@ -1 +1 @@
|
|||
from core import *
|
||||
from .core import *
|
||||
|
|
|
@ -12,6 +12,17 @@ sys.dont_write_bytecode = True
|
|||
|
||||
class RtmBot(object):
|
||||
def __init__(self, config):
|
||||
'''
|
||||
Params:
|
||||
- config (dict):
|
||||
- SLACK_TOKEN: your authentication token from Slack
|
||||
- BASE_PATH (optional: defaults to execution directory) RtmBot will
|
||||
look in this directory for plugins.
|
||||
- LOGFILE (optional: defaults to rtmbot.log) The filename for logs, will
|
||||
be stored inside the BASE_PATH directory
|
||||
- DEBUG (optional: defaults to False) with debug enabled, RtmBot will
|
||||
break on errors
|
||||
'''
|
||||
# set the config object
|
||||
self.config = config
|
||||
|
||||
|
@ -30,7 +41,7 @@ class RtmBot(object):
|
|||
logging.basicConfig(filename=log_file,
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(message)s')
|
||||
logging.info(self.directory)
|
||||
logging.info('Initialized in: {}'.format(self.directory))
|
||||
self.debug = self.config.get('DEBUG', False)
|
||||
|
||||
# initialize stateful fields
|
||||
|
|
20
tests/test_rtmbot_core.py
Normal file
20
tests/test_rtmbot_core.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from testfixtures import LogCapture
|
||||
from rtmbot.core import RtmBot
|
||||
|
||||
|
||||
def test_init():
|
||||
with LogCapture() as l:
|
||||
rtmbot = RtmBot({
|
||||
'SLACK_TOKEN': 'test-12345',
|
||||
'BASE_PATH': '/tmp/',
|
||||
'LOGFILE': '/tmp/rtmbot.log',
|
||||
'DEBUG': True
|
||||
})
|
||||
|
||||
assert rtmbot.token == 'test-12345'
|
||||
assert rtmbot.directory == '/tmp/'
|
||||
assert rtmbot.debug == True
|
||||
|
||||
l.check(
|
||||
('root', 'INFO', 'Initialized in: /tmp/')
|
||||
)
|
14
tox.ini
14
tox.ini
|
@ -9,9 +9,14 @@ max-line-length= 100
|
|||
exclude= tests/*
|
||||
|
||||
[testenv]
|
||||
commands=py.test {posargs:tests}
|
||||
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
|
||||
commands =
|
||||
py.test --cov-report= --cov=rtmbot {posargs:tests}
|
||||
coveralls
|
||||
|
||||
deps =
|
||||
-r{toxinidir}/requirements-dev.txt
|
||||
-r{toxinidir}/requirements.txt
|
||||
basepython =
|
||||
py27: python2.7
|
||||
py34: python3.4
|
||||
|
@ -20,4 +25,9 @@ basepython =
|
|||
[testenv:flake8]
|
||||
basepython=python
|
||||
deps=flake8
|
||||
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/rtmbot/core.py {toxinidir}/setup.py {toxinidir}/doc/example-plugins
|
||||
commands=
|
||||
flake8 \
|
||||
{toxinidir}/rtmbot.py \
|
||||
{toxinidir}/rtmbot/core.py \
|
||||
{toxinidir}/setup.py \
|
||||
{toxinidir}/doc/example-plugins
|
Loading…
Add table
Add a link
Reference in a new issue