fix Wadsworth's Constant edge case and add test

master
mutantmonkey 2013-05-12 18:16:57 -04:00
parent 29269c7c51
commit a0597ba7a6
2 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,21 @@
"""
test_nsfw.py - some things just aren't safe for work, the test cases
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
import re
import unittest
from mock import MagicMock, Mock
from modules.wadsworth import wadsworth
class TestWadsworth(unittest.TestCase):
def setUp(self):
self.phenny = MagicMock()
def test_wadsworth(self):
input = Mock(group=lambda x: "Apply Wadsworth's Constant to a string")
wadsworth(self.phenny, input)
self.phenny.say.assert_called_once_with(
"Constant to a string")

View File

@ -1,13 +1,16 @@
#!/usr/bin/python3
"""
wadsworth.py - Use Wadsworth's Constant on a string.
wadsworth.py - Apply Wadsworth's Constant to some text.
https://gist.github.com/1257195
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
def wadsworth(phenny, input):
""".wadsworth - Use Wadsworth's Constant on a string."""
""".wadsworth - Apply Wadsworth's Constant to some text."""
text = input.group(2)
if not text:
return phenny.say(".wadsworth <text> - apply Wadsworth's Constant")
text = text[text.find(' ', int(round(0.3 * len(text)))) + 1:]
phenny.say(text)
wadsworth.commands = ['wadsworth']