mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Fix broken test import paths
This commit is contained in:
parent
3444414638
commit
853b708ece
10 changed files with 0 additions and 0 deletions
0
tests/test_data/__init__.py
Normal file
0
tests/test_data/__init__.py
Normal file
0
tests/test_data/test_embeds/__init__.py
Normal file
0
tests/test_data/test_embeds/__init__.py
Normal file
45
tests/test_data/test_embeds/test_urban_dictionary.py
Normal file
45
tests/test_data/test_embeds/test_urban_dictionary.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from data.embeds.urban_dictionary import Definition
|
||||
import unittest
|
||||
|
||||
|
||||
class TestUD(unittest.TestCase):
|
||||
def test_clean_string(self):
|
||||
self.assertEqual(
|
||||
Definition.clean_string("A definition [with links] to other [definitions]"),
|
||||
"A definition with links to other definitions"
|
||||
)
|
||||
|
||||
no_processing = "A string that needs no processing."
|
||||
self.assertEqual(Definition.clean_string(no_processing), no_processing)
|
||||
|
||||
long_string = "A very long string that hopefully exceeds the 1024 character limit for embed field values, " \
|
||||
"in order to test if the truncation part of this specific function works as expected. " \
|
||||
"The issue is that coming up with a string that exceeds the 1024 embed field value character " \
|
||||
"limit is quite tedious, so I have no idea how I plan on ever finishing this." \
|
||||
"As of the writing of this sentence, I'm only a third of the way there." \
|
||||
"Crazy. I could probably just toss some lorem ipsum in there, but that would be no fun." \
|
||||
"Or would it? Hey GitHub, Didier here." \
|
||||
"Instead I would like to take this opportunity to out my frustrations on the abomination of a " \
|
||||
"\"language\" that is Haskell. You see, Haskell is just terrible and useless. " \
|
||||
"It truly does pose the bane of my existence, and I deeply hope that I will never have to use it " \
|
||||
"ever again in my life. Good thing I somehow managed to pass that class, otherwise I would've " \
|
||||
"probably collapsed mentally on the spot. As it turns out, though, this sentence is already in the " \
|
||||
"900 character range, so I don't have much of a reason to continue writing about the worst " \
|
||||
"invention humanity has ever come up with."
|
||||
|
||||
self.assertGreater(len(long_string), 1024)
|
||||
self.assertEqual(len(Definition.clean_string(long_string)), 1024)
|
||||
self.assertEqual(Definition.clean_string(long_string)[-3:], "...")
|
||||
|
||||
def test_ratio(self):
|
||||
dic = {
|
||||
"thumbs_up": 5,
|
||||
"thumbs_down": 0
|
||||
}
|
||||
self.assertEqual(Definition.ratio(dic), 100.0)
|
||||
|
||||
dic["thumbs_down"] = 5
|
||||
self.assertEqual(Definition.ratio(dic), 50.0)
|
||||
|
||||
dic["thumbs_up"] = 0
|
||||
self.assertEqual(Definition.ratio(dic), 0)
|
||||
32
tests/test_data/test_regexes.py
Normal file
32
tests/test_data/test_regexes.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from data import regexes
|
||||
import re
|
||||
import unittest
|
||||
|
||||
|
||||
class TestRegexes(unittest.TestCase):
|
||||
def test_contains(self):
|
||||
pattern = {"pattern": "ABC123"}
|
||||
|
||||
self.assertTrue(regexes.contains("ABC123TESTSTRING", pattern)) # Beginning
|
||||
self.assertTrue(regexes.contains("TESTABC123STRING", pattern)) # Middle
|
||||
self.assertTrue(regexes.contains("TESTSTRINGABC123", pattern)) # End
|
||||
self.assertTrue(regexes.contains("ABC123", pattern)) # Entire string
|
||||
|
||||
self.assertFalse(regexes.contains("aBC123TESTSTRING", pattern)) # Wrong casing
|
||||
self.assertFalse(regexes.contains("SOMETHING ELSE", pattern)) # No match
|
||||
|
||||
# Add case insensitive flag
|
||||
pattern["flags"] = re.IGNORECASE
|
||||
self.assertTrue(regexes.contains("aBC123TESTSTRING", pattern)) # Incorrect casing should now pass
|
||||
|
||||
def test_steam_codes(self):
|
||||
self.assertTrue(regexes.contains("AAAAA-BBBBB-CCCCC", regexes.STEAM_CODE)) # Only letters
|
||||
self.assertTrue(regexes.contains("11111-22222-33333", regexes.STEAM_CODE)) # Only numbers
|
||||
self.assertTrue(regexes.contains("ABC12-34DEF-GHI56", regexes.STEAM_CODE)) # Both
|
||||
self.assertTrue(regexes.contains("abcde-fghij-lmnop", regexes.STEAM_CODE)) # Case insensitive flag
|
||||
self.assertTrue(regexes.contains("AAAAAA-BBBBB-CCCCC", regexes.STEAM_CODE)) # Extra characters can be in front
|
||||
|
||||
self.assertFalse(regexes.contains("A-BBBBB-CCCCC", regexes.STEAM_CODE)) # First group is too small
|
||||
self.assertFalse(regexes.contains("AAAAA-BBBBBB-CCCCC", regexes.STEAM_CODE)) # Second group is too big
|
||||
self.assertFalse(regexes.contains("AA??A-#ù$B6-!ÈCMa", regexes.STEAM_CODE)) # Invalid characters
|
||||
self.assertFalse(regexes.contains("Something something communism", regexes.STEAM_CODE)) # Random string
|
||||
93
tests/test_data/test_schedule.py
Normal file
93
tests/test_data/test_schedule.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
from data import schedule
|
||||
from datetime import datetime
|
||||
from enums.platform import Platform
|
||||
import pytz
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class TestSchedule(TestCase):
|
||||
def test_holiday_has_passed(self):
|
||||
tz = pytz.timezone("Europe/Brussels")
|
||||
before = datetime(2020, 8, 8, tzinfo=tz)
|
||||
during = datetime(2021, 6, 2, tzinfo=tz)
|
||||
after = datetime(2021, 8, 8, tzinfo=tz)
|
||||
|
||||
holiday = schedule.Holiday([1, 6, 2021], [2, 7, 2021])
|
||||
|
||||
self.assertFalse(holiday.has_passed(before))
|
||||
self.assertFalse(holiday.has_passed(during))
|
||||
self.assertTrue(holiday.has_passed(after))
|
||||
|
||||
def test_timeslot_link(self):
|
||||
slot = schedule.Timeslot(schedule.Course("a"), 1234, 5678)
|
||||
self.assertEqual(None, slot.get_link_str())
|
||||
|
||||
slot = schedule.Timeslot(schedule.Course("a"), 1234, 5678, online_link="link", online_platform=Platform.Zoom)
|
||||
self.assertEqual("[Zoom](link)", slot.get_link_str())
|
||||
|
||||
@patch("data.schedule.Schedule.check_holidays")
|
||||
@patch("data.schedule.Schedule.load_schedule_file")
|
||||
def test_schedule_semester_over(self, mock_load, mock_check_holidays):
|
||||
mock_load.return_value = {"semester_start": [1, 2, 2020], "semester_end": [4, 5, 2021]}
|
||||
dt = datetime(2021, 8, 8, tzinfo=pytz.timezone("Europe/Brussels"))
|
||||
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertTrue(s.semester_over)
|
||||
|
||||
# Check that the code stopped running in case the semester is over
|
||||
mock_check_holidays.assert_not_called()
|
||||
|
||||
@patch("data.schedule.Schedule.load_schedule_file")
|
||||
def test_schedule_holidays(self, mock_load):
|
||||
mock_load.return_value = {
|
||||
"semester_start": [6, 7, 2021], "semester_end": [20, 8, 2021],
|
||||
"holidays": [
|
||||
{"start_date": [1, 8, 2021], "end_date": [10, 8, 2021]}
|
||||
]
|
||||
}
|
||||
|
||||
# During holiday
|
||||
dt = datetime(2021, 8, 8, tzinfo=pytz.timezone("Europe/Brussels"))
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertNotEqual(None, s.current_holiday)
|
||||
|
||||
# Not during holiday
|
||||
dt = datetime(2021, 8, 15, tzinfo=pytz.timezone("Europe/Brussels"))
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertEqual(None, s.current_holiday)
|
||||
|
||||
@patch("data.schedule.Schedule.load_schedule_file")
|
||||
def test_schedule_holiday_offset(self, mock_load):
|
||||
# Week 1, no holidays
|
||||
mock_load.return_value = {
|
||||
"semester_start": [2, 8, 2021], "semester_end": [20, 8, 2021]
|
||||
}
|
||||
|
||||
dt = datetime(2021, 8, 6, tzinfo=pytz.timezone("Europe/Brussels"))
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertEqual(1, s.get_week())
|
||||
|
||||
# Week 1, one off-day doesn't change the week
|
||||
mock_load.return_value = {
|
||||
"semester_start": [2, 8, 2021], "semester_end": [20, 8, 2021],
|
||||
"holidays": [
|
||||
{"start_date": [5, 8, 2021], "end_date": [5, 8, 2021]}
|
||||
]
|
||||
}
|
||||
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertEqual(1, s.get_week())
|
||||
|
||||
# Week 3, with a one-week holiday in between
|
||||
mock_load.return_value = {
|
||||
"semester_start": [2, 8, 2021], "semester_end": [20, 8, 2021],
|
||||
"holidays": [
|
||||
{"start_date": [5, 8, 2021], "end_date": [5, 8, 2021]},
|
||||
{"start_date": [9, 8, 2021], "end_date": [15, 8, 2021]}
|
||||
]
|
||||
}
|
||||
|
||||
dt = datetime(2021, 8, 19, tzinfo=pytz.timezone("Europe/Brussels"))
|
||||
s = schedule.Schedule(dt, 3, 1)
|
||||
self.assertEqual(2, s.get_week())
|
||||
27
tests/test_data/test_snipe.py
Normal file
27
tests/test_data/test_snipe.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from data.snipe import should_snipe
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
class TestSnipe(unittest.TestCase):
|
||||
def test_should_snipe(self):
|
||||
mock_message = Mock()
|
||||
mock_guild = Mock()
|
||||
mock_author = Mock()
|
||||
|
||||
# Guild is None
|
||||
mock_message.guild = None
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
mock_message.guild = mock_guild
|
||||
|
||||
# Author is a bot
|
||||
mock_message.author = mock_author
|
||||
mock_author.bot = True
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
mock_author.bot = False
|
||||
|
||||
mock_message.content = "Some string that contains A123B-CE68S-Z6B34 a Steam code"
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
|
||||
mock_message.content = "Some string that does NOT contain a Steam code"
|
||||
self.assertTrue(should_snipe(mock_message))
|
||||
Loading…
Add table
Add a link
Reference in a new issue