Removed bots.py and slurs.py and moved them into config.py. twitch_script_class.py has been updated to handle this added a test harness for twitch_script_class.py contains_url and contains_slur are both validated refactored contains_url to use a simple(ish) regex instead of an if cascade
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import unittest
|
|
import twitch_script_class
|
|
import twitch
|
|
|
|
|
|
testValidUrls = ['https://shady.ru', 'http://stolencards.zn', 'https://i.imgur.com/FL6slHd.jpg']
|
|
testInvalidUrls = ['this is just a sentence. With a period', 'gotta have some other stuff', 'bad punctuation produces false positives']
|
|
|
|
|
|
class TwitchBotTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.bot = twitch_script_class.Twitch_Module()
|
|
|
|
def test_find_url(self):
|
|
bot = self.bot
|
|
for link in testInvalidUrls:
|
|
msg = twitch.chat.Message("", "", link)
|
|
t = bot.contains_url(msg)
|
|
assert not t
|
|
|
|
for link in testValidUrls:
|
|
msg = twitch.chat.Message("", "", link)
|
|
t = bot.contains_url(msg)
|
|
assert t
|
|
|
|
def test_find_slur(self):
|
|
nonSlurMessage = twitch.chat.Message("", "", "hey look, a normal sentence")
|
|
slurMessage = twitch.chat.Message("", "", "fag is a hateful word that shouldn't be used anymore")
|
|
assert not self.bot.contains_slur(nonSlurMessage)
|
|
assert self.bot.contains_slur(slurMessage)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
|