本文整理汇总了Python中schedule.Schedule.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Schedule.delete方法的具体用法?Python Schedule.delete怎么用?Python Schedule.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schedule.Schedule
的用法示例。
在下文中一共展示了Schedule.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestScheduleClass
# 需要导入模块: from schedule import Schedule [as 别名]
# 或者: from schedule.Schedule import delete [as 别名]
class TestScheduleClass(unittest.TestCase):
def setUp(self):
self.schedule = Schedule()
self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && reboot",
"schedule": "0 0 * * *",
"executer": True
})
# self.reboot = Reboot(connection=Mockup())
def tearDown(self):
self.schedule = None
cron = CronTab(user=True)
cron.remove_all()
cron.write()
def test_insert(self):
'''Insert a job, It should insert a job and return it with id'''
result = self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True
})
self.assertDictEqual({
"id": 2,
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True,
"comment": "sanji_schedule_2"
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment("sanji_schedule_2"):
jobs.append(job)
self.assertEqual(len(jobs), 1)
def test_update(self):
'''Update a job, It should update a job and return it'''
added = self.schedule.get()[0]
result = self.schedule.update({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True
})
self.assertNotEqual(result, None)
self.assertDictEqual({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True,
"comment": added["comment"]
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment(result["comment"]):
jobs.append(job)
self.assertEqual(job.slices, result["schedule"])
self.assertEqual(job.command, result["command"])
self.assertEqual(len(jobs), 1)
def test_delete(self):
'''Delete a job,
It should delete a job by id and return effected count'''
added = self.schedule.get()[0]
result = self.schedule.delete(added["id"])
self.assertEqual(result, 1)
result = self.schedule.get()
self.assertEqual(len(result), 0)
def test_get_all(self):
'''Get all jobs,
It should return all jobs'''
self.schedule.insert({
"enable": 1,
"alias": "1",
"command": "uptime && test_get_all",
"schedule": "0 0 * * *",
"executer": True
})
self.schedule.insert({
"enable": 1,
"alias": "1",
#.........这里部分代码省略.........