当前位置: 首页>>代码示例>>Python>>正文


Python SessionState.update_desired_job_list方法代码示例

本文整理汇总了Python中plainbox.impl.session.SessionState.update_desired_job_list方法的典型用法代码示例。如果您正苦于以下问题:Python SessionState.update_desired_job_list方法的具体用法?Python SessionState.update_desired_job_list怎么用?Python SessionState.update_desired_job_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plainbox.impl.session.SessionState的用法示例。


在下文中一共展示了SessionState.update_desired_job_list方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_realistic_test_session

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def make_realistic_test_session(self):
     # Create a more realistic session with two jobs but with richer set
     # of data in the actual jobs and results.
     job_a = JobDefinition({
         'plugin': 'shell',
         'name': 'job_a',
         'command': 'echo testing && true',
         'requires': 'job_b.ready == "yes"'
     })
     job_b = JobDefinition({
         'plugin': 'resource',
         'name': 'job_b',
         'command': 'echo ready: yes'
     })
     session = SessionState([job_a, job_b])
     session.update_desired_job_list([job_a, job_b])
     result_a = JobResult({
         'job': job_a,
         'outcome': 'pass',
         'return_code': 0,
         'io_log': (
             IOLogRecord(0, 'stdout', 'testing\n'),
         )
     })
     result_b = JobResult({
         'job': job_b,
         'outcome': 'pass',
         'return_code': 0,
         'io_log': (
             IOLogRecord(0, 'stdout', 'ready: yes\n'),
         )
     })
     session.update_job_result(job_a, result_a)
     session.update_job_result(job_b, result_b)
     return session
开发者ID:yphus,项目名称:checkbox,代码行数:37,代码来源:test_init.py

示例2: make_realistic_test_session

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def make_realistic_test_session(self, session_dir):
     # Create a more realistic session with two jobs but with richer set
     # of data in the actual jobs and results.
     job_a = JobDefinition({
         'plugin': 'shell',
         'name': 'job_a',
         'command': 'echo testing && true',
         'requires': 'job_b.ready == "yes"'
     })
     job_b = JobDefinition({
         'plugin': 'resource',
         'name': 'job_b',
         'command': 'echo ready: yes'
     })
     session = SessionState([job_a, job_b])
     session.update_desired_job_list([job_a, job_b])
     result_a = MemoryJobResult({
         'outcome': IJobResult.OUTCOME_PASS,
         'return_code': 0,
         'io_log': [(0, 'stdout', b'testing\n')],
     })
     result_b = MemoryJobResult({
         'outcome': IJobResult.OUTCOME_PASS,
         'return_code': 0,
         'comments': 'foo',
         'io_log': [(0, 'stdout', b'ready: yes\n')],
     })
     session.update_job_result(job_a, result_a)
     session.update_job_result(job_b, result_b)
     return session
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:32,代码来源:test_init.py

示例3: test_get_estimated_duration_manual_unknown

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def test_get_estimated_duration_manual_unknown(self):
     four_seconds = make_job("four_seconds", plugin="shell",
                             command="fibble",
                             estimated_duration=4.0)
     no_estimated_duration = make_job("no_estimated_duration",
                                      plugin="user-verify",
                                      command="bibble")
     session = SessionState([four_seconds, no_estimated_duration])
     session.update_desired_job_list([four_seconds, no_estimated_duration])
     self.assertEqual(session.get_estimated_duration(), (4.0, None))
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:12,代码来源:test_state.py

示例4: test_get_estimated_duration_automated_unknown

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def test_get_estimated_duration_automated_unknown(self):
     three_seconds = make_job("three_seconds", plugin="shell",
                              command="frob",
                              estimated_duration=3.0)
     no_estimated_duration = make_job("no_estimated_duration",
                                      plugin="shell",
                                      command="borf")
     session = SessionState([three_seconds, no_estimated_duration])
     session.update_desired_job_list([three_seconds, no_estimated_duration])
     self.assertEqual(session.get_estimated_duration(), (None, 0.0))
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:12,代码来源:test_state.py

示例5: test_get_estimated_duration_manual

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def test_get_estimated_duration_manual(self):
     two_seconds = make_job("two_seconds", plugin="manual",
                            command="farboo",
                            estimated_duration=2.0)
     shell_job = make_job("shell_job", plugin="shell",
                          command="boofar",
                          estimated_duration=0.6)
     session = SessionState([two_seconds, shell_job])
     session.update_desired_job_list([two_seconds, shell_job])
     self.assertEqual(session.get_estimated_duration(), (0.6, 32.0))
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:12,代码来源:test_state.py

示例6: test_get_estimated_duration_auto

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def test_get_estimated_duration_auto(self):
     # Define jobs with an estimated duration
     one_second = make_job("one_second", plugin="shell",
                           command="foobar",
                           estimated_duration=1.0)
     half_second = make_job("half_second", plugin="shell",
                            command="barfoo",
                            estimated_duration=0.5)
     session = SessionState([one_second, half_second])
     session.update_desired_job_list([one_second, half_second])
     self.assertEqual(session.get_estimated_duration(), (1.5, 0.0))
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:13,代码来源:test_state.py

示例7: make_test_session

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def make_test_session(self):
     # Create a small session with two jobs and two results
     job_a = make_job('job_a')
     job_b = make_job('job_b')
     session = SessionState([job_a, job_b])
     session.update_desired_job_list([job_a, job_b])
     result_a = make_job_result(job_a, 'pass')
     result_b = make_job_result(job_b, 'fail')
     session.update_job_result(job_a, result_a)
     session.update_job_result(job_b, result_b)
     return session
开发者ID:yphus,项目名称:checkbox,代码行数:13,代码来源:test_init.py

示例8: make_test_session

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def make_test_session(self):
     # Create a small session with two jobs and two results
     job_a = make_job('job_a')
     job_b = make_job('job_b')
     session = SessionState([job_a, job_b])
     session.update_desired_job_list([job_a, job_b])
     result_a = make_job_result(outcome=IJobResult.OUTCOME_PASS)
     result_b = make_job_result(outcome=IJobResult.OUTCOME_FAIL)
     session.update_job_result(job_a, result_a)
     session.update_job_result(job_b, result_b)
     return session
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:13,代码来源:test_init.py

示例9: test_crash_in_update_desired_job_list

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
 def test_crash_in_update_desired_job_list(self):
     # This checks if a DependencyError can cause crash
     # update_desired_job_list() with a ValueError, in certain conditions.
     A = make_job('A', depends='X')
     L = make_job('L', plugin='local')
     session = SessionState([A, L])
     problems = session.update_desired_job_list([A, L])
     # We should get exactly one DependencyMissingError related to job A and
     # the undefined job X (that is presumably defined by the local job L)
     self.assertEqual(len(problems), 1)
     self.assertIsInstance(problems[0], DependencyMissingError)
     self.assertIs(problems[0].affected_job, A)
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:14,代码来源:test_state.py

示例10: SessionStateReactionToJobResultTests

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
class SessionStateReactionToJobResultTests(TestCase):
    # This test checks how a simple session with a few typical job reacts to
    # job results of various kinds. It checks most of the resource presentation
    # error conditions that I could think of.

    def setUp(self):
        # All of the tests below are using one session. The session has four
        # jobs, clustered into two independent groups. Job A depends on a
        # resource provided by job R which has no dependencies at all. Job X
        # depends on job Y which in turn has no dependencies at all.
        #
        # A -(resource dependency)-> R
        #
        # X -(direct dependency) -> Y
        self.job_A = make_job("A", requires="R.attr == 'value'")
        self.job_A_expr = self.job_A.get_resource_program().expression_list[0]
        self.job_R = make_job("R", plugin="resource")
        self.job_X = make_job("X", depends='Y')
        self.job_Y = make_job("Y")
        self.job_L = make_job("L", plugin="local")
        self.job_list = [
            self.job_A, self.job_R, self.job_X, self.job_Y, self.job_L]
        self.session = SessionState(self.job_list)

    def job_state(self, name):
        # A helper function to avoid overly long expressions
        return self.session.job_state_map[name]

    def job_inhibitor(self, name, index):
        # Another helper that shortens deep object nesting
        return self.job_state(name).readiness_inhibitor_list[index]

    def test_assumptions(self):
        # This function checks the assumptions of SessionState initial state.
        # The job list is what we set when constructing the session.
        #
        self.assertEqual(self.session.job_list, self.job_list)
        # The run_list is still empty because the desired_job_list is equally
        # empty.
        self.assertEqual(self.session.run_list, [])
        self.assertEqual(self.session.desired_job_list, [])
        # All jobs have state objects that indicate they cannot run (because
        # they have the UNDESIRED inhibitor set for them by default).
        self.assertFalse(self.job_state('A').can_start())
        self.assertFalse(self.job_state('R').can_start())
        self.assertFalse(self.job_state('X').can_start())
        self.assertFalse(self.job_state('Y').can_start())
        self.assertEqual(self.job_inhibitor('A', 0).cause,
                         JobReadinessInhibitor.UNDESIRED)
        self.assertEqual(self.job_inhibitor('R', 0).cause,
                         JobReadinessInhibitor.UNDESIRED)
        self.assertEqual(self.job_inhibitor('X', 0).cause,
                         JobReadinessInhibitor.UNDESIRED)
        self.assertEqual(self.job_inhibitor('Y', 0).cause,
                         JobReadinessInhibitor.UNDESIRED)

    def test_desire_job_A_updates_state_map(self):
        # This function checks what happens when the job A becomes desired via
        # the update_desired_job_list() call.
        self.session.update_desired_job_list([self.job_A])
        self.assertEqual(self.session.desired_job_list, [self.job_A])
        # This should topologically sort the job list, according to the
        # relationship created by the resource requirement. This is not really
        # testing the dependency solver (it has separate tests), just that this
        # basic property is established and that the run_list properly shows
        # that R must run before A can run.
        self.assertEqual(self.session.run_list, [self.job_R, self.job_A])
        # This also recomputes job readiness state so that job R is no longer
        # undesired, has no other inhibitor and thus can start
        self.assertEqual(self.job_state('R').readiness_inhibitor_list, [])
        self.assertTrue(self.job_state('R').can_start())
        # While the A job still cannot run it now has a different inhibitor,
        # one with the PENDING_RESOURCE cause. The inhibitor also properly
        # pinpoints the related job and related expression.
        self.assertNotEqual(self.job_state('A').readiness_inhibitor_list, [])
        self.assertEqual(self.job_inhibitor('A', 0).cause,
                         JobReadinessInhibitor.PENDING_RESOURCE)
        self.assertEqual(self.job_inhibitor('A', 0).related_job, self.job_R)
        self.assertEqual(self.job_inhibitor('A', 0).related_expression,
                         self.job_A_expr)
        self.assertFalse(self.job_state('A').can_start())

    def test_resource_job_result_updates_resource_and_job_states(self):
        # This function checks what happens when a JobResult for job R (which
        # is a resource job via the resource plugin) is presented to the
        # session.
        result_R = MemoryJobResult({
            'io_log': [(0, 'stdout', b"attr: value\n")],
        })
        self.session.update_job_result(self.job_R, result_R)
        # The most obvious thing that can happen, is that the result is simply
        # stored in the associated job state object.
        self.assertIs(self.job_state('R').result, result_R)
        # Initially the _resource_map was empty. SessionState parses the io_log
        # of results of resource jobs and creates appropriate resource objects.
        self.assertIn("R", self.session._resource_map)
        expected = {'R': [Resource({'attr': 'value'})]}
        self.assertEqual(self.session._resource_map, expected)
        # As job results are presented to the session the readiness of other
        # jobs is changed. Since A depends on R via a resource expression and
#.........这里部分代码省略.........
开发者ID:jds2001,项目名称:ocp-checkbox,代码行数:103,代码来源:test_state.py

示例11: __init__

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
class _SRUInvocation:
    """
    Helper class instantiated to perform a particular invocation of the sru
    command. Unlike the SRU command itself, this class is instantiated each
    time.
    """

    def __init__(self, ns, config):
        self.ns = ns
        self.checkbox = CheckBox()
        self.config = config
        self.whitelist = WhiteList.from_file(os.path.join(
            self.checkbox.whitelists_dir, "sru.whitelist"))
        self.job_list = self.checkbox.get_builtin_jobs()
        # XXX: maybe allow specifying system_id from command line?
        self.exporter = XMLSessionStateExporter(system_id=None)
        self.session = None
        self.runner = None

    def run(self):
        # Compute the run list, this can give us notification about problems in
        # the selected jobs. Currently we just display each problem
        # Create a session that handles most of the stuff needed to run jobs
        try:
            self.session = SessionState(self.job_list)
        except DependencyDuplicateError as exc:
            # Handle possible DependencyDuplicateError that can happen if
            # someone is using plainbox for job development.
            print("The job database you are currently using is broken")
            print("At least two jobs contend for the name {0}".format(
                exc.job.name))
            print("First job defined in: {0}".format(exc.job.origin))
            print("Second job defined in: {0}".format(
                exc.duplicate_job.origin))
            raise SystemExit(exc)
        with self.session.open():
            self._set_job_selection()
            self.runner = JobRunner(
                self.session.session_dir,
                self.session.jobs_io_log_dir,
                command_io_delegate=self,
                outcome_callback=None,  # SRU runs are never interactive
                dry_run=self.ns.dry_run
            )
            self._run_all_jobs()
            if self.config.fallback_file is not Unset:
                self._save_results()
            self._submit_results()
        # FIXME: sensible return value
        return 0

    def _set_job_selection(self):
        desired_job_list = get_matching_job_list(self.job_list, self.whitelist)
        problem_list = self.session.update_desired_job_list(desired_job_list)
        if problem_list:
            logger.warning("There were some problems with the selected jobs")
            for problem in problem_list:
                logger.warning("- %s", problem)
            logger.warning("Problematic jobs will not be considered")

    def _save_results(self):
        print("Saving results to {0}".format(self.config.fallback_file))
        data = self.exporter.get_session_data_subset(self.session)
        with open(self.config.fallback_file, "wt", encoding="UTF-8") as stream:
            translating_stream = ByteStringStreamTranslator(stream, "UTF-8")
            self.exporter.dump(data, translating_stream)

    def _submit_results(self):
        print("Submitting results to {0} for secure_id {1}".format(
              self.config.c3_url, self.config.secure_id))
        options_string = "secure_id={0}".format(self.config.secure_id)
        # Create the transport object
        try:
            transport = CertificationTransport(
                self.config.c3_url, options_string, self.config)
        except InvalidSecureIDError as exc:
            print(exc)
            return False
        # Prepare the data for submission
        data = self.exporter.get_session_data_subset(self.session)
        with tempfile.NamedTemporaryFile(mode='w+b') as stream:
            # Dump the data to the temporary file
            self.exporter.dump(data, stream)
            # Flush and rewind
            stream.flush()
            stream.seek(0)
            try:
                # Send the data, reading from the temporary file
                result = transport.send(stream)
                if 'url' in result:
                    print("Successfully sent, submission status at {0}".format(
                          result['url']))
                else:
                    print("Successfully sent, server response: {0}".format(
                          result))

            except InvalidSchema as exc:
                print("Invalid destination URL: {0}".format(exc))
            except ConnectionError as exc:
                print("Unable to connect to destination URL: {0}".format(exc))
#.........这里部分代码省略.........
开发者ID:bladernr,项目名称:checkbox,代码行数:103,代码来源:sru.py

示例12: AnalyzeInvocation

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
class AnalyzeInvocation(CheckBoxInvocationMixIn):

    def __init__(self, provider_list, config, ns):
        super().__init__(provider_list, config)
        self.ns = ns
        self.job_list = self.get_job_list(ns)
        self.desired_job_list = self._get_matching_job_list(ns, self.job_list)
        self.session = SessionState(self.job_list)
        self.problem_list = self.session.update_desired_job_list(
            self.desired_job_list)

    def run(self):
        if self.ns.run_local:
            if self.ns.print_desired_job_list:
                self._print_desired_job_list()
            if self.ns.print_run_list:
                self._print_run_list()
            self._run_local_jobs()
        if self.ns.print_stats:
            self._print_general_stats()
        if self.ns.print_dependency_report:
            self._print_dependency_report()
        if self.ns.print_interactivity_report:
            self._print_interactivity_report()
        if self.ns.print_estimated_duration_report:
            self._print_estimated_duration_report()
        if self.ns.print_validation_report:
            self._print_validation_report(self.ns.only_errors)
        if self.ns.print_requirement_report:
            self._print_requirement_report()
        if self.ns.print_desired_job_list:
            self._print_desired_job_list()
        if self.ns.print_run_list:
            self._print_run_list()

    def _print_desired_job_list(self):
        print(_("[Desired Job List]").center(80, '='))
        for job in self.session.desired_job_list:
            print("{}".format(job.id))

    def _print_run_list(self):
        print(_("[Run List]").center(80, '='))
        for job in self.session.run_list:
            print("{}".format(job.id))

    def _run_local_jobs(self):
        print(_("[Running Local Jobs]").center(80, '='))
        manager = SessionManager.create_with_state(self.session)
        try:
            manager.state.metadata.title = "plainbox dev analyze session"
            manager.state.metadata.flags = [SessionMetaData.FLAG_INCOMPLETE]
            manager.checkpoint()
            runner = JobRunner(
                manager.storage.location, self.provider_list,
                os.path.join(manager.storage.location, 'io-logs'),
                command_io_delegate=self)
            again = True
            while again:
                for job in self.session.run_list:
                    if job.plugin == 'local':
                        if self.session.job_state_map[job.id].result.outcome is None:
                            self._run_local_job(manager, runner, job)
                            break
                else:
                    again = False
            manager.state.metadata.flags = []
            manager.checkpoint()
        finally:
            manager.destroy()

    def _run_local_job(self, manager, runner, job):
        print("{job}".format(job=job.id))
        manager.state.metadata.running_job_name = job.id
        manager.checkpoint()
        result = runner.run_job(job, self.config)
        self.session.update_job_result(job, result)
        new_desired_job_list = self._get_matching_job_list(
            self.ns, self.session.job_list)
        new_problem_list = self.session.update_desired_job_list(
            new_desired_job_list)
        if new_problem_list:
            print(_("Problem list"), new_problem_list)
            self.problem_list.extend(new_problem_list)

    def _print_general_stats(self):
        print(_("[General Statistics]").center(80, '='))
        print(_("Known jobs: {}").format(len(self.job_list)))
        print(_("Selected jobs: {}").format(len(self.desired_job_list)))

    def _print_dependency_report(self):
        print(_("[Dependency Report]").center(80, '='))
        if self.problem_list:
            for problem in self.problem_list:
                print(" * {}".format(problem))
        else:
            print(_("Selected jobs have no dependency problems"))

    def _print_interactivity_report(self):
        print(_("[Interactivity Report]").center(80, '='))
        if not self.session.run_list:
#.........这里部分代码省略.........
开发者ID:Roadmaster,项目名称:checkbox,代码行数:103,代码来源:analyze.py

示例13: SessionStateTrimTests

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_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")
开发者ID:Roadmaster,项目名称:checkbox,代码行数:88,代码来源:test_state.py

示例14: SessionStateLocalStorageTests

# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_desired_job_list [as 别名]
class SessionStateLocalStorageTests(TestCase):

    def setUp(self):
        # session data are kept in XDG_CACHE_HOME/plainbox/.session
        # To avoid resuming a real session, we have to select a temporary
        # location instead
        self._sandbox = tempfile.mkdtemp()
        self._env = os.environ
        os.environ['XDG_CACHE_HOME'] = self._sandbox

    def job_state(self, name):
        # A helper function to avoid overly long expressions
        return self.session.job_state_map[name]

    def test_persistent_save(self):
        self.job_A = make_job("A")
        self.job_list = [self.job_A]
        self.session = SessionState(self.job_list)
        result_A = JobResult({
            'job': self.job_A,
            'outcome': JobResult.OUTCOME_PASS,
            'comments': 'All good',
            'return_code': 0,
            'io_log': ((0, 'stdout', "Success !\n"),)
        })
        session_json_text = """{
            "_job_state_map": {
                "A": {
                    "_job": {
                        "data": {
                            "name": "A",
                            "plugin": "dummy",
                            "requires": null,
                            "depends": null
                        },
                        "_class_id": "JOB_DEFINITION"
                    },
                    "_result": {
                        "data": {
                            "job": {
                                "data": {
                                    "name": "A",
                                    "plugin": "dummy",
                                    "requires": null,
                                    "depends": null
                                },
                                "_class_id": "JOB_DEFINITION"
                            },
                            "outcome": "pass",
                            "return_code": 0,
                            "comments": "All good",
                            "io_log": [
                                [
                                    0,
                                    "stdout",
                                    "Success !\\n"
                                ]
                            ]
                        },
                        "_class_id": "JOB_RESULT"
                    },
                    "_class_id": "JOB_STATE"
                }
            },
            "_desired_job_list": [
                {
                    "data": {
                        "name": "A",
                        "plugin": "dummy",
                        "requires": null,
                        "depends": null
                    },
                    "_class_id": "JOB_DEFINITION"
                }
            ],
            "_class_id": "SESSION_STATE"
        }"""
        self.session.open()
        self.session.update_desired_job_list([self.job_A])
        self.session.update_job_result(self.job_A, result_A)
        self.session.persistent_save()
        session_file = self.session.previous_session_file()
        self.session.close()
        self.assertIsNotNone(session_file)
        with open(session_file) as f:
            raw_json = json.load(f)
            self.maxDiff = None
            self.assertEqual(raw_json, json.loads(session_json_text))

    def test_resume_session(self):
        # All of the tests below are using one session. The session has four
        # jobs, Job A depends on a resource provided by job R which has no
        # dependencies at all. Both Job X and Y depend on job A.
        #
        # A -(resource dependency)-> R
        #
        # X -(direct dependency) -> A
        #
        # Y -(direct dependency) -> A
        self.job_A = make_job("A", requires="R.attr == 'value'")
#.........这里部分代码省略.........
开发者ID:bladernr,项目名称:checkbox,代码行数:103,代码来源:test_session.py


注:本文中的plainbox.impl.session.SessionState.update_desired_job_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。