From 23d99dd3262ea67c8572569156951fdedcbf89b9 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Sun, 25 Aug 2013 14:32:42 -0700 Subject: [PATCH] improve tests and test coverage --- modules/test/test_hs.py | 27 +++++++++++++++++---------- modules/test/test_imdb.py | 15 ++++++++++++--- modules/test/test_mylife.py | 4 ++++ modules/test/test_nsfw.py | 9 +++++++-- modules/test/test_short.py | 7 ++++++- modules/test/test_slogan.py | 13 +++++++++---- 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/modules/test/test_hs.py b/modules/test/test_hs.py index e15631e..7214ebd 100644 --- a/modules/test/test_hs.py +++ b/modules/test/test_hs.py @@ -17,25 +17,32 @@ class TestHs(unittest.TestCase): data = search('john') assert len(data) >= 1 - assert 'uid' in data[0] - assert 'cn' in data[0] + self.assertIn('uid', data[0]) + self.assertIn('cn', data[0]) def test_single(self): input = Mock(group=lambda x: 'marchany') hs(self.phenny, input) - out = self.phenny.reply.call_args[0][0] - m = re.match( + pattern = re.compile( '^.* - http://search\.vt\.edu/search/person\.html\?person=\d+$', - out, flags=re.UNICODE) - self.assertTrue(m) + flags=re.UNICODE) + out = self.phenny.reply.call_args[0][0] + self.assertRegex(out, pattern) def test_multi(self): input = Mock(group=lambda x: 'john') hs(self.phenny, input) - out = self.phenny.reply.call_args[0][0] - m = re.match( + pattern = re.compile( '^Multiple results found; try http://search\.vt\.edu/search/people\.html\?q=.*$', - out, flags=re.UNICODE) - self.assertTrue(m) + flags=re.UNICODE) + out = self.phenny.reply.call_args[0][0] + self.assertRegex(out, pattern) + + def test_none(self): + input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY') + hs(self.phenny, input) + + out = self.phenny.reply.call_args[0][0] + self.phenny.reply.assert_called_once_with("No results found") diff --git a/modules/test/test_imdb.py b/modules/test/test_imdb.py index f1a1ff3..234f1e0 100644 --- a/modules/test/test_imdb.py +++ b/modules/test/test_imdb.py @@ -25,6 +25,15 @@ class TestImdb(unittest.TestCase): input = Mock(group=lambda x: 'Antitrust') imdb(self.phenny, input) - out = self.phenny.reply.call_args[0][0] - m = re.match('^.* \(.*\): .* http://imdb.com/title/[a-z\d]+$', out, flags=re.UNICODE) - self.assertTrue(m) + out = self.phenny.say.call_args[0][0] + pattern = re.compile( + r'^.* \(.*\): .* http://imdb.com/title/[a-z\d]+$', + flags=re.UNICODE) + self.assertRegex(out, pattern) + + def test_imdb_none(self): + input = Mock(group=lambda x: None) + imdb(self.phenny, input) + + self.phenny.say.assert_called_once_with( + ".imdb what?") diff --git a/modules/test/test_mylife.py b/modules/test/test_mylife.py index 3c2bad0..b0aef79 100644 --- a/modules/test/test_mylife.py +++ b/modules/test/test_mylife.py @@ -24,6 +24,10 @@ class TestMylife(unittest.TestCase): mylife.mlib(self.phenny, None) assert self.phenny.say.called is True + def test_mlig(self): + mylife.mlib(self.phenny, None) + assert self.phenny.say.called is True + def test_mlih(self): mylife.mlih(self.phenny, None) assert self.phenny.say.called is True diff --git a/modules/test/test_nsfw.py b/modules/test/test_nsfw.py index a561c77..ed6bff7 100644 --- a/modules/test/test_nsfw.py +++ b/modules/test/test_nsfw.py @@ -16,6 +16,11 @@ class TestNsfw(unittest.TestCase): def test_nsfw(self): input = Mock(group=lambda x: "test") nsfw(self.phenny, input) - self.phenny.say.assert_called_once_with( - "!!NSFW!! -> test <- !!NSFW!!") + "!!NSFW!! -> test <- !!NSFW!!") + + def test_nsfw_none(self): + input = Mock(group=lambda x: None) + nsfw(self.phenny, input) + self.phenny.say.assert_called_once_with( + ".nsfw - for when a link isn't safe for work") diff --git a/modules/test/test_short.py b/modules/test/test_short.py index b899d5f..9e5e324 100644 --- a/modules/test/test_short.py +++ b/modules/test/test_short.py @@ -15,5 +15,10 @@ class TestShort(unittest.TestCase): def test_short(self): input = Mock(group=lambda x: 'http://vtluug.org/') short(self.phenny, input) - self.phenny.reply.assert_called_once_with('http://vtlu.ug/bLQYAy') + + def test_short_none(self): + input = Mock(group=lambda x: None) + short(self.phenny, input) + self.phenny.reply.assert_called_once_with( + "No URL provided. CAN I HAS?") diff --git a/modules/test/test_slogan.py b/modules/test/test_slogan.py index 6ec92ef..fa5b446 100644 --- a/modules/test/test_slogan.py +++ b/modules/test/test_slogan.py @@ -14,12 +14,17 @@ class TestSlogan(unittest.TestCase): def test_sloganize(self): out = sloganize('slogan') - - assert len(out) > 0 + self.assertRegex(out, ".*slogan.*") def test_slogan(self): input = Mock(group=lambda x: 'slogan') slogan(self.phenny, input) - out = self.phenny.say.call_args[0][0] - self.assertNotEqual(out, "Looks like an issue with sloganizer.net") + out = self.phenny.say.call_args[0][0] + self.assertRegex(out, ".*slogan.*") + + def test_slogan_none(self): + input = Mock(group=lambda x: None) + slogan(self.phenny, input) + self.phenny.say.assert_called_once_with( + "You need to specify a word; try .slogan Granola")