예제 #1
0
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = (
            lambda *args: 'The ApplyPatchAction cannot be applied'
        )

        self.section.append(Setting(
            'default_actions',
            'NoBear: ApplyPatchAction, YBear: ApplyPatchAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    self.log_printer)
        self.assertEqual(ret, self.results)
        capture.check(
            ('root', 'WARNING', 'YBear: The ApplyPatchAction cannot be applied')
        )

        ApplyPatchAction.is_applicable = old_is_applicable

        self.section.append(Setting(
            'no_autoapply_warn', True))
        with LogCapture() as capture:
            autoapply_actions(self.results,
                              {},
                              {},
                              self.section,
                              self.log_printer)
        capture.check()
예제 #2
0
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = (
            lambda *args: 'The ApplyPatchAction cannot be applied'
        )

        self.section.append(Setting(
            'default_actions',
            'NoBear: ApplyPatchAction, YBear: ApplyPatchAction'))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(self.log_queue.get().message,
                         'YBear: The ApplyPatchAction cannot be applied')
        self.assertTrue(self.log_queue.empty())

        ApplyPatchAction.is_applicable = old_is_applicable

        self.section.append(Setting(
            'no_autoapply_warn', True))
        autoapply_actions(self.results,
                          {},
                          {},
                          self.section,
                          self.log_printer)
        self.assertTrue(self.log_queue.empty())
예제 #3
0
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = (
            lambda *args: 'The ApplyPatchAction cannot be applied'
        )

        self.section.append(Setting(
            'default_actions',
            'NoBear: ApplyPatchAction, YBear: ApplyPatchAction'))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(self.log_queue.get().message,
                         'YBear: The ApplyPatchAction cannot be applied')
        self.assertTrue(self.log_queue.empty())

        ApplyPatchAction.is_applicable = old_is_applicable

        self.section.append(Setting(
            'no_autoapply_warn', True))
        autoapply_actions(self.results,
                          {},
                          {},
                          self.section,
                          self.log_printer)
        self.assertTrue(self.log_queue.empty())
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = (
            lambda *args: 'The ApplyPatchAction cannot be applied'
        )

        self.section.append(Setting(
            'default_actions',
            'NoBear: ApplyPatchAction, YBear: ApplyPatchAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    self.log_printer)
        self.assertEqual(ret, self.results)
        capture.check(
            ('root', 'WARNING', 'YBear: The ApplyPatchAction cannot be applied')
        )

        ApplyPatchAction.is_applicable = old_is_applicable

        self.section.append(Setting(
            'no_autoapply_warn', True))
        with LogCapture() as capture:
            autoapply_actions(self.results,
                              {},
                              {},
                              self.section,
                              self.log_printer)
        capture.check()
예제 #5
0
    def test_failing_action(self):
        class FailingTestAction(ResultAction):

            def apply(self, *args, **kwargs):
                raise RuntimeError("YEAH THAT'S A FAILING BEAR")

        ACTIONS.append(FailingTestAction)

        self.section.append(Setting("default_actions",
                                    "YBear: FailingTestAction"))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(self.log_queue.get().message,
                         "Failed to execute action 'FailingTestAction'"
                         " with error: YEAH THAT'S A FAILING BEAR.")
        self.assertIn("YEAH THAT'S A FAILING BEAR",
                      self.log_queue.get().message)
        self.assertEqual(self.log_queue.get().message,
                         "-> for result " + repr(self.resultY) + ".")
        self.assertTrue(self.log_queue.empty())

        ACTIONS.pop()
예제 #6
0
    def test_failing_action(self):
        class FailingTestAction(ResultAction):

            def apply(self, *args, **kwargs):
                raise RuntimeError("YEAH THAT'S A FAILING BEAR")

        ACTIONS.append(FailingTestAction)

        self.section.append(Setting('default_actions',
                                    'YBear: FailingTestAction'))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(self.log_queue.get().message,
                         "Failed to execute action 'FailingTestAction'"
                         " with error: YEAH THAT'S A FAILING BEAR.")
        self.assertIn("YEAH THAT'S A FAILING BEAR",
                      self.log_queue.get().message)
        self.assertEqual(self.log_queue.get().message,
                         '-> for result ' + repr(self.resultY) + '.')
        self.assertTrue(self.log_queue.empty())

        ACTIONS.pop()
예제 #7
0
    def test_applicable_action(self):
        # Use a result whose action can be successfully applied.
        log_printer = self.log_printer

        class TestAction(ResultAction):

            def apply(self, *args, **kwargs):
                log_printer.debug('ACTION APPLIED SUCCESSFULLY.')

        ACTIONS.append(TestAction)

        self.section.append(Setting('default_actions', 'Z*: TestAction'))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                log_printer)
        self.assertEqual(ret, [self.resultY])
        self.assertEqual(self.log_queue.get().message,
                         'ACTION APPLIED SUCCESSFULLY.')
        self.assertEqual(self.log_queue.get().message,
                         "Applied 'TestAction' "
                         "on the whole project from 'ZBear'.")
        self.assertTrue(self.log_queue.empty())

        ACTIONS.pop()
    def test_applicable_action(self):
        # Use a result whose action can be successfully applied.
        log_printer = self.log_printer

        class TestAction(ResultAction):

            def apply(self, *args, **kwargs):
                logging.debug('ACTION APPLIED SUCCESSFULLY.')

        ACTIONS.append(TestAction)

        self.section.append(Setting('default_actions', 'Z*: TestAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    log_printer)
        self.assertEqual(ret, [self.resultY])
        capture.check(
            ('root', 'DEBUG', 'ACTION APPLIED SUCCESSFULLY.'),
            ('root', 'INFO', "Applied 'TestAction' on the whole project from "
                             "'ZBear'.")
        )
        ACTIONS.pop()
    def test_failing_action(self):
        class FailingTestAction(ResultAction):

            def apply(self, *args, **kwargs):
                raise RuntimeError("YEAH THAT'S A FAILING BEAR")

        ACTIONS.append(FailingTestAction)

        self.section.append(Setting('default_actions',
                                    'YBear: FailingTestAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    self.log_printer)
        self.assertEqual(ret, self.results)
        capture.check(
            ('root', 'ERROR', "Failed to execute action 'FailingTestAction' "
             "with error: YEAH THAT'S A FAILING BEAR."),
            ('root', 'INFO', StringComparison(
                r"(?s).*YEAH THAT'S A FAILING BEAR.*")),
            ('root', 'DEBUG', '-> for result ' + repr(self.resultY) + '.')
        )
        ACTIONS.pop()
예제 #10
0
    def test_applicable_action(self):
        # Use a result whose action can be successfully applied.
        log_printer = self.log_printer

        class TestAction(ResultAction):

            def apply(self, *args, **kwargs):
                log_printer.debug("ACTION APPLIED SUCCESSFULLY.")

        ACTIONS.append(TestAction)

        self.section.append(Setting("default_actions", "Z*: TestAction"))
        ret = autoapply_actions(self.results,
                                {},
                                {},
                                self.section,
                                log_printer)
        self.assertEqual(ret, [self.resultY])
        self.assertEqual(self.log_queue.get().message,
                         "ACTION APPLIED SUCCESSFULLY.")
        self.assertEqual(self.log_queue.get().message,
                         "Applied 'TestAction' "
                         "on the whole project from 'ZBear'.")
        self.assertTrue(self.log_queue.empty())

        ACTIONS.pop()
예제 #11
0
    def test_failing_action(self):
        class FailingTestAction(ResultAction):

            def apply(self, *args, **kwargs):
                raise RuntimeError("YEAH THAT'S A FAILING BEAR")

        ACTIONS.append(FailingTestAction)

        self.section.append(Setting('default_actions',
                                    'YBear: FailingTestAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    self.log_printer)
        self.assertEqual(ret, self.results)
        capture.check(
            ('root', 'ERROR', "Failed to execute action 'FailingTestAction' "
             "with error: YEAH THAT'S A FAILING BEAR."),
            ('root', 'INFO', StringComparison(
                r"(?s).*YEAH THAT'S A FAILING BEAR.*")),
            ('root', 'DEBUG', '-> for result ' + repr(self.resultY) + '.')
        )
        ACTIONS.pop()
예제 #12
0
    def test_applicable_action(self):
        # Use a result whose action can be successfully applied.
        log_printer = self.log_printer

        class TestAction(ResultAction):

            def apply(self, *args, **kwargs):
                logging.debug('ACTION APPLIED SUCCESSFULLY.')

        ACTIONS.append(TestAction)

        self.section.append(Setting('default_actions', 'Z*: TestAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results,
                                    {},
                                    {},
                                    self.section,
                                    log_printer)
        self.assertEqual(ret, [self.resultY])
        capture.check(
            ('root', 'DEBUG', 'ACTION APPLIED SUCCESSFULLY.'),
            ('root', 'INFO', "Applied 'TestAction' on the whole project from "
                             "'ZBear'.")
        )
        ACTIONS.pop()
예제 #13
0
 def test_no_default_actions(self):
     ret = autoapply_actions(self.results,
                             {},
                             {},
                             self.section,
                             self.log_printer)
     self.assertEqual(ret, self.results)
     self.assertTrue(self.log_queue.empty())
예제 #14
0
 def test_no_default_actions(self):
     ret = autoapply_actions(self.results,
                             {},
                             {},
                             self.section,
                             self.log_printer)
     self.assertEqual(ret, self.results)
     self.assertTrue(self.log_queue.empty())
예제 #15
0
 def test_with_invalid_action(self):
     self.section.append(Setting("default_actions", "XBear: nonSENSE_action"))
     ret = autoapply_actions(self.results, {}, {}, self.section, self.log_printer)
     self.assertEqual(ret, self.results)
     self.assertEqual(
         self.log_queue.get().message,
         "Selected default action 'nonSENSE_action' for bear " "'XBear' does not exist. Ignoring action.",
     )
     self.assertTrue(self.log_queue.empty())
 def test_no_default_actions(self):
     with LogCapture() as capture:
         ret = autoapply_actions(self.results,
                                 {},
                                 {},
                                 self.section,
                                 self.log_printer)
     self.assertEqual(ret, self.results)
     capture.check()
예제 #17
0
 def test_no_default_actions(self):
     with LogCapture() as capture:
         ret = autoapply_actions(self.results,
                                 {},
                                 {},
                                 self.section,
                                 self.log_printer)
     self.assertEqual(ret, self.results)
     capture.check()
예제 #18
0
    def test_wrong_bear_origin(self):
        MyBearAction.is_applicable = staticmethod(lambda *args: True)
        log_printer = self.log_printer

        self.section.append(Setting('default_actions', 'Y*: MyBearAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results, {}, {}, self.section,
                                    log_printer)
        self.assertEqual(ret, self.results)
        capture.check()
예제 #19
0
 def test_with_invalid_action(self):
     self.section.append(
         Setting("default_actions", "XBear: nonSENSE_action"))
     ret = autoapply_actions(self.results, {}, {}, self.section,
                             self.log_printer)
     self.assertEqual(ret, self.results)
     self.assertEqual(
         self.log_queue.get().message,
         "Selected default action 'nonSENSE_action' for bear "
         "'XBear' does not exist. Ignoring action.")
     self.assertTrue(self.log_queue.empty())
예제 #20
0
 def test_with_invalid_action(self):
     self.section.append(
         Setting('default_actions', 'XBear: nonSENSE_action'))
     with LogCapture() as capture:
         ret = autoapply_actions(self.results, {}, {}, self.section,
                                 self.log_printer)
     self.assertEqual(ret, self.results)
     capture.check(
         ('root', 'WARNING', "Selected default action 'nonSENSE_action' for"
          " bear 'XBear' does not exist. Ignoring "
          'action.'))
예제 #21
0
    def test_bear_action_unapplicable(self):
        MyBearAction.is_applicable = staticmethod(
            lambda *args: 'The MyBearAction cannot be applied')
        log_printer = self.log_printer

        self.section.append(Setting('default_actions', 'X*: MyBearAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results, {}, {}, self.section,
                                    log_printer)
        self.assertEqual(ret, self.results)
        capture.check(
            ('root', 'WARNING', 'XBear: The MyBearAction cannot be applied'))
예제 #22
0
    def test_bear_action_applicable(self):
        MyBearAction.is_applicable = staticmethod(lambda *args: True)
        log_printer = self.log_printer

        self.section.append(Setting('default_actions', 'X*: MyBearAction'))
        with LogCapture() as capture:
            ret = autoapply_actions(self.results, {}, {}, self.section,
                                    log_printer)
        self.assertEqual(ret, [self.resultY, self.resultZ])
        capture.check(('root', 'DEBUG', 'ACTION APPLIED SUCCESSFULLY.'),
                      ('root', 'INFO',
                       "Applied 'MyBearAction' on the whole project from "
                       "'XBear'."))
예제 #23
0
 def test_with_invalid_action(self):
     self.section.append(Setting('default_actions',
                                 'XBear: nonSENSE_action'))
     with LogCapture() as capture:
         ret = autoapply_actions(self.results,
                                 {},
                                 {},
                                 self.section,
                                 self.log_printer)
     self.assertEqual(ret, self.results)
     capture.check(
         ('root', 'WARNING', "Selected default action 'nonSENSE_action' for"
                             " bear 'XBear' does not exist. Ignoring "
                             'action.')
     )
예제 #24
0
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = lambda *args: False

        self.section.append(Setting("default_actions", "NoBear: ApplyPatchAction, YBear: ApplyPatchAction"))
        ret = autoapply_actions(self.results, {}, {}, self.section, self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(
            self.log_queue.get().message,
            "Selected default action 'ApplyPatchAction' for bear " "'YBear' is not applicable. Action not applied.",
        )
        self.assertTrue(self.log_queue.empty())

        ApplyPatchAction.is_applicable = old_is_applicable
예제 #25
0
    def test_without_default_action_and_unapplicable(self):
        # Use a result where no default action is supplied for and another one
        # where the action is not applicable.
        old_is_applicable = ApplyPatchAction.is_applicable
        ApplyPatchAction.is_applicable = lambda *args: False

        self.section.append(
            Setting("default_actions",
                    "NoBear: ApplyPatchAction, YBear: ApplyPatchAction"))
        ret = autoapply_actions(self.results, {}, {}, self.section,
                                self.log_printer)
        self.assertEqual(ret, self.results)
        self.assertEqual(
            self.log_queue.get().message,
            "Selected default action 'ApplyPatchAction' for bear "
            "'YBear' is not applicable. Action not applied.")
        self.assertTrue(self.log_queue.empty())

        ApplyPatchAction.is_applicable = old_is_applicable