From a0597ba7a65d97b0804672397c3333d65a4ec738 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Sun, 12 May 2013 18:16:57 -0400 Subject: [PATCH] fix Wadsworth's Constant edge case and add test --- modules/test/test_wadsworth.py | 21 +++++++++++++++++++++ modules/wadsworth.py | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 modules/test/test_wadsworth.py diff --git a/modules/test/test_wadsworth.py b/modules/test/test_wadsworth.py new file mode 100644 index 0000000..d9c82d6 --- /dev/null +++ b/modules/test/test_wadsworth.py @@ -0,0 +1,21 @@ +""" +test_nsfw.py - some things just aren't safe for work, the test cases +author: mutantmonkey +""" + +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") diff --git a/modules/wadsworth.py b/modules/wadsworth.py index 36b5319..53a4f3a 100644 --- a/modules/wadsworth.py +++ b/modules/wadsworth.py @@ -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 """ 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 - apply Wadsworth's Constant") + text = text[text.find(' ', int(round(0.3 * len(text)))) + 1:] phenny.say(text) wadsworth.commands = ['wadsworth']