Project setup for clean rewrite

This commit is contained in:
stijndcl 2022-06-09 01:32:13 +02:00
parent 2ce32ee8a3
commit 00481e42eb
189 changed files with 8 additions and 358340 deletions

View file

@ -1,32 +0,0 @@
import unittest
from data.courses import load_courses, find_course_from_name
class TestCourses(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.courses = load_courses()
def test_find_course(self):
self.assertIsNone(find_course_from_name("garbage", self.courses))
self.assertIsNone(find_course_from_name("garbage"))
# Find by name
webdev = find_course_from_name("Webdevelopment", self.courses)
self.assertIsNotNone(webdev)
self.assertEqual(webdev.code, "C003779")
# Find by abbreviation
infosec = find_course_from_name("infosec", self.courses)
self.assertIsNotNone(infosec)
self.assertEqual(infosec.code, "E019400")
# Case sensitive
not_found = find_course_from_name("ad3", self.courses, case_insensitive=False)
self.assertIsNone(not_found)
# Find by alt name
pcs = find_course_from_name("parallel computer systems", self.courses)
self.assertIsNotNone(pcs)
self.assertEqual(pcs.code, "E034140")

View file

@ -1,45 +0,0 @@
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)

View file

@ -1,32 +0,0 @@
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

View file

@ -1,93 +0,0 @@
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())

View file

@ -1,27 +0,0 @@
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))