diff options
author | 2022-05-10 20:06:35 +0100 | |
---|---|---|
committer | 2022-05-10 20:06:35 +0100 | |
commit | 45b809167849ba950f271f9466463042560535c7 (patch) | |
tree | be12399b66c47d70c857900305bc23bfef20d815 /tests | |
parent | Remove trailing whitespace from docstring (diff) |
Convert tests from pytest style to unittest style
Diffstat (limited to 'tests')
-rw-r--r-- | tests/botcore/utils/test_regex.py | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/tests/botcore/utils/test_regex.py b/tests/botcore/utils/test_regex.py index 70d4252f..2ffd0e46 100644 --- a/tests/botcore/utils/test_regex.py +++ b/tests/botcore/utils/test_regex.py @@ -1,3 +1,4 @@ +import unittest from typing import Optional from botcore.utils.regex import DISCORD_INVITE @@ -13,36 +14,37 @@ def use_regex(s: str) -> Optional[str]: return result if result is None else result.group("invite") -def test_discord_invite_positives(): - """Test the DISCORD_INVITE regex on a set of strings we would expect to capture.""" - - assert use_regex("discord.gg/python") == "python" - assert use_regex("https://discord.gg/python") == "python" - assert use_regex("discord.com/invite/python") == "python" - assert use_regex("discordapp.com/invite/python") == "python" - assert use_regex("discord.me/python") == "python" - assert use_regex("discord.li/python") == "python" - assert use_regex("discord.io/python") == "python" - assert use_regex(".gg/python") == "python" - - assert use_regex("discord.gg/python/but/extra") == "python/but/extra" - assert use_regex("discord.me/this/isnt/python") == "this/isnt/python" - assert use_regex(".gg/a/a/a/a/a/a/a/a/a/a/a") == "a/a/a/a/a/a/a/a/a/a/a" - assert use_regex("discordapp.com/invite/python/snakescord") == "python/snakescord" - assert use_regex("http://discord.gg/python/%20/notpython") == "python/%20/notpython" - assert use_regex("discord.gg/python?=ts/notpython") == "python?=ts/notpython" - assert use_regex("https://discord.gg/python#fragment/notpython") == "python#fragment/notpython" - assert use_regex("https://discord.gg/python/~/notpython") == "python/~/notpython" - - assert use_regex("https://discord.gg/python with whitespace") == "python" - assert use_regex(" https://discord.gg/python ") == "python" - - -def test_discord_invite_negatives(): - """Test the DISCORD_INVITE regex on a set of strings we would expect to not capture.""" - - assert use_regex("another string") is None - assert use_regex("https://pythondiscord.com") is None - assert use_regex("https://discord.com") is None - assert use_regex("https://discord.gg") is None - assert use_regex("https://discord.gg/ python") is None +class UtilsRegexTests(unittest.TestCase): + + def test_discord_invite_positives(self): + """Test the DISCORD_INVITE regex on a set of strings we would expect to capture.""" + + self.assertEqual(use_regex("discord.gg/python"), "python") + self.assertEqual(use_regex("https://discord.gg/python"), "python") + self.assertEqual(use_regex("discord.com/invite/python"), "python") + self.assertEqual(use_regex("discordapp.com/invite/python"), "python") + self.assertEqual(use_regex("discord.me/python"), "python") + self.assertEqual(use_regex("discord.li/python"), "python") + self.assertEqual(use_regex("discord.io/python"), "python") + self.assertEqual(use_regex(".gg/python"), "python") + + self.assertEqual(use_regex("discord.gg/python/but/extra"), "python/but/extra") + self.assertEqual(use_regex("discord.me/this/isnt/python"), "this/isnt/python") + self.assertEqual(use_regex(".gg/a/a/a/a/a/a/a/a/a/a/a"), "a/a/a/a/a/a/a/a/a/a/a") + self.assertEqual(use_regex("discordapp.com/invite/python/snakescord"), "python/snakescord") + self.assertEqual(use_regex("http://discord.gg/python/%20/notpython"), "python/%20/notpython") + self.assertEqual(use_regex("discord.gg/python?=ts/notpython"), "python?=ts/notpython") + self.assertEqual(use_regex("https://discord.gg/python#fragment/notpython"), "python#fragment/notpython") + self.assertEqual(use_regex("https://discord.gg/python/~/notpython"), "python/~/notpython") + + self.assertEqual(use_regex("https://discord.gg/python with whitespace"), "python") + self.assertEqual(use_regex(" https://discord.gg/python "), "python") + + def test_discord_invite_negatives(self): + """Test the DISCORD_INVITE regex on a set of strings we would expect to not capture.""" + + self.assertEqual(use_regex("another string"), None) + self.assertEqual(use_regex("https://pythondiscord.com"), None) + self.assertEqual(use_regex("https://discord.com"), None) + self.assertEqual(use_regex("https://discord.gg"), None) + self.assertEqual(use_regex("https://discord.gg/ python"), None) |