本文整理汇总了Python中plainbox.impl.session.SessionState.trim_job_list方法的典型用法代码示例。如果您正苦于以下问题:Python SessionState.trim_job_list方法的具体用法?Python SessionState.trim_job_list怎么用?Python SessionState.trim_job_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plainbox.impl.session.SessionState
的用法示例。
在下文中一共展示了SessionState.trim_job_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SessionStateTrimTests
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import trim_job_list [as 别名]
class SessionStateTrimTests(TestCase):
"""
Tests for SessionState.trim_job_list()
"""
def setUp(self):
self.job_a = make_job("a")
self.job_b = make_job("b")
self.session = SessionState([self.job_a, self.job_b])
def test_trim_does_remove_jobs(self):
"""
verify that trim_job_list() removes jobs as requested
"""
self.session.trim_job_list(JobIdQualifier("a"))
self.assertEqual(self.session.job_list, [self.job_b])
def test_trim_does_remove_job_state(self):
"""
verify that trim_job_list() removes job state for removed jobs
"""
self.assertIn("a", self.session.job_state_map)
self.session.trim_job_list(JobIdQualifier("a"))
self.assertNotIn("a", self.session.job_state_map)
def test_trim_does_remove_resources(self):
"""
verify that trim_job_list() removes resources for removed jobs
"""
self.session.set_resource_list("a", [Resource({'attr': 'value'})])
self.assertIn("a", self.session.resource_map)
self.session.trim_job_list(JobIdQualifier("a"))
self.assertNotIn("a", self.session.resource_map)
def test_trim_fires_on_job_removed(self):
"""
verify that trim_job_list() fires on_job_removed() signal
"""
signal_fired = False
def on_job_removed(job):
self.assertIs(job, self.job_a)
nonlocal signal_fired
signal_fired = True
self.session.on_job_removed.connect(on_job_removed)
self.session.trim_job_list(JobIdQualifier("a"))
self.assertTrue(signal_fired)
def test_trim_fires_on_job_state_map_changed(self):
"""
verify that trim_job_list() fires on_job_state_map_changed() signal
"""
signal_fired = False
def on_job_state_map_changed():
nonlocal signal_fired
signal_fired = True
self.session.on_job_state_map_changed.connect(on_job_state_map_changed)
self.session.trim_job_list(JobIdQualifier("a"))
self.assertTrue(signal_fired)
def test_trim_fires_on_job_state_map_changed_only_when_needed(self):
"""
verify that trim_job_list() does not fires on_job_state_map_changed()
signal needlessly, when no jobs is actually being removed.
"""
signal_fired = False
def on_job_state_map_changed():
nonlocal signal_fired
signal_fired = True
self.session.on_job_state_map_changed.connect(on_job_state_map_changed)
self.session.trim_job_list(JobIdQualifier("x"))
self.assertFalse(signal_fired)
def test_trim_raises_ValueError_for_jobs_on_run_list(self):
"""
verify that trim_job_list() raises ValueError when any of the jobs
marked for removal is in the run_list.
"""
self.session.update_desired_job_list([self.job_a])
with self.assertRaises(ValueError) as boom:
self.session.trim_job_list(JobIdQualifier("a"))
self.assertEqual(
str(boom.exception),
"cannot remove jobs that are on the run list: a")