Praxis_Bot/tests/test_twitch_script_class.py
dtookey 3e24942d54 Let PEP8 do it's thing and reformat all the files.
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

Let PEP8 do it's thing and reformat all the files.
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
2020-09-20 11:48:15 -04:00

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()