<commit_before>from __future__ import unicode_literals

from unittest import TestCase
from dateutil.relativedelta import relativedelta
from frappe.core.doctype.scheduled_job_type.scheduled_job_type import sync_jobs
from frappe.utils.background_jobs import enqueue, get_jobs
from frappe.utils.scheduler import enqueue_events, is_dormant, schedule_jobs_based_on_activity
from frappe.utils import add_days, get_datetime

import frappe
import time

def test_timeout():
	time.sleep(100)

def test_timeout_10():
	time.sleep(10)

def test_method():
	pass

class TestScheduler(TestCase):
	def setUp(self):
		if not frappe.get_all('Scheduled Job Type', limit=1):
			sync_jobs()

	def test_enqueue_jobs(self):
		frappe.db.sql('update `tabScheduled Job Type` set last_execution = "2010-01-01 00:00:00"')

		frappe.flags.execute_job = True
		enqueue_events(site = frappe.local.site)
		frappe.flags.execute_job = False

		self.assertTrue('frappe.email.queue.clear_outbox', frappe.flags.enqueued_jobs)
		self.assertTrue('frappe.utils.change_log.check_for_update', frappe.flags.enqueued_jobs)
		self.assertTrue('frappe.email.doctype.auto_email_report.auto_email_report.send_monthly', frappe.flags.enqueued_jobs)

	def test_queue_peeking(self):
		job = get_test_job()

		self.assertTrue(job.enqueue())
		job.db_set('last_execution', '2010-01-01 00:00:00')
		frappe.db.commit()

		# 1 job in queue
		self.assertTrue(job.enqueue())
		job.db_set('last_execution', '2010-01-01 00:00:00')
		frappe.db.commit()

		# 2nd job not loaded
		self.assertFalse(job.enqueue())
		job.delete()

	def test_is_dormant(self):
		self.assertTrue(is_dormant(check_time= get_datetime('2100-01-01 00:00:00')))
		self.assertTrue(is_dormant(check_time = add_days(frappe.db.get_last_created('Activity Log'), 5)))
		self.assertFalse(is_dormant(check_time = frappe.db.get_last_created('Activity Log')))

	def test_once_a_day_for_dormant(self):<commit_msg>fix(minor): postgres compatibility<commit_after>from __future__ import unicode_literals

from unittest import TestCase
from dateutil.relativedelta import relativedelta
from frappe.core.doctype.scheduled_job_type.scheduled_job_type import sync_jobs
from frappe.utils.background_jobs import enqueue, get_jobs
from frappe.utils.scheduler import enqueue_events, is_dormant, schedule_jobs_based_on_activity
from frappe.utils import add_days, get_datetime

import frappe
import time

def test_timeout():
	time.sleep(100)

def test_timeout_10():
	time.sleep(10)

def test_method():
	pass

class TestScheduler(TestCase):
	def setUp(self):
		if not frappe.get_all('Scheduled Job Type', limit=1):
			sync_jobs()

	def test_enqueue_jobs(self):
		frappe.db.sql("update `tabScheduled Job Type` set last_execution = '2010-01-01 00:00:00'")

		frappe.flags.execute_job = True
		enqueue_events(site = frappe.local.site)
		frappe.flags.execute_job = False

		self.assertTrue('frappe.email.queue.clear_outbox', frappe.flags.enqueued_jobs)
		self.assertTrue('frappe.utils.change_log.check_for_update', frappe.flags.enqueued_jobs)
		self.assertTrue('frappe.email.doctype.auto_email_report.auto_email_report.send_monthly', frappe.flags.enqueued_jobs)

	def test_queue_peeking(self):
		job = get_test_job()

		self.assertTrue(job.enqueue())
		job.db_set('last_execution', '2010-01-01 00:00:00')
		frappe.db.commit()

		# 1 job in queue
		self.assertTrue(job.enqueue())
		job.db_set('last_execution', '2010-01-01 00:00:00')
		frappe.db.commit()

		# 2nd job not loaded
		self.assertFalse(job.enqueue())
		job.delete()

	def test_is_dormant(self):
		self.assertTrue(is_dormant(check_time= get_datetime('2100-01-01 00:00:00')))
		self.assertTrue(is_dormant(check_time = add_days(frappe.db.get_last_created('Activity Log'), 5)))
		self.assertFalse(is_dormant(check_time = frappe.db.get_last_created('Activity Log')))

	def test_once_a_day_for_dormant(self):
{'fraction_non_alphanumeric': 0.11533454829471491, 'fraction_numerical': 0.03488674824264514, 'mean_word_length': 6.262759924385633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4798546', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1430, 'n_words': 233}