diff --git a/README.md b/README.md index f26338d..19e1aa3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ python-rtmbot ============= [![Build Status](https://travis-ci.org/slackhq/python-rtmbot.png)](https://travis-ci.org/slackhq/python-rtmbot) +[![Coverage Status](https://coveralls.io/repos/github/slackhq/python-rtmbot/badge.svg?branch=master)](https://coveralls.io/github/slackhq/python-rtmbot?branch=master) A Slack bot written in python that connects via the RTM API. diff --git a/requirements-dev.txt b/requirements-dev.txt index c6513a4..8e69fc4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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 \ No newline at end of file +testfixtures==4.9.1 +tox>=1.8.0 diff --git a/rtmbot/__init__.py b/rtmbot/__init__.py index 5af2406..bb67a43 100644 --- a/rtmbot/__init__.py +++ b/rtmbot/__init__.py @@ -1 +1 @@ -from core import * +from .core import * diff --git a/rtmbot/core.py b/rtmbot/core.py index bf64782..049bb77 100755 --- a/rtmbot/core.py +++ b/rtmbot/core.py @@ -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 diff --git a/tests/test_rtmbot_core.py b/tests/test_rtmbot_core.py new file mode 100644 index 0000000..0353147 --- /dev/null +++ b/tests/test_rtmbot_core.py @@ -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/') + ) diff --git a/tox.ini b/tox.ini index a4b8a3d..63b4d9b 100644 --- a/tox.ini +++ b/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 \ No newline at end of file