FMN_bot/test.py

31 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-07-16 13:05:18 +00:00
import unittest
import datetime
import time_machine
from src import sheduler
class TestDate(unittest.TestCase):
def test_date_tue(self):
"""
test near tue
2024-07-16 14:05:22 +00:00
тестирует корректность расчета даты на след. вторник
условия: расчет начат от воскресенья или понедельника (случайно)
2024-07-16 13:05:18 +00:00
"""
import calendar
import random
for month in range(1, 13):
sundays = [i for i in calendar.Calendar().itermonthdays4(year=2024, month=month) if i[3] == 6]
for sunday in sundays:
2024-07-16 14:05:22 +00:00
fake_date = datetime.datetime(year=sunday[0], month=sunday[1], day=sunday[2], hour=random.randint(21, 23)) + datetime.timedelta(days=random.randint(0, 1))
2024-07-16 13:05:18 +00:00
with time_machine.travel(fake_date):
try:
result = sheduler.check_stop_thread_scan(fake_date)
print("current fake date: " + fake_date.strftime("%Y.%m.%d %H:%M") + f" near tue: {result}")
2024-07-16 14:05:22 +00:00
except Exception as E:
print("fail fake date: " + fake_date.strftime("%Y.%m.%d %H:%M") + f", err: {E}")
2024-07-16 13:05:18 +00:00
if __name__ == '__main__':
unittest.main()