Пример #1
0
    def test_stacktrace_html(self):
        """Stack traces can be caught and rendered as html
        """

        # This is about general exception handling, so ok to use catch-all
        # pylint: disable=W0703
        try:
            bbox_intersection('aoeu', 'oaeu', [])
        except Exception, e:
            # Display message and traceback

            myMessage = get_error_message(e)
            #print myMessage
            myMessage = myMessage.to_text()
            self.assertIn(str(e), myMessage)
            self.assertIn('line', myMessage)
            self.assertIn('file', myMessage)

            myMessage = get_error_message(e)
            myMessage = myMessage.to_html()
            assert str(e) in myMessage

            myMessage = myMessage.decode('string_escape')
            myExpectedResult = open(
                TEST_FILES_DIR + '/test-stacktrace-html.txt',
                'r').read().replace('\n', '')
            self.assertIn(myExpectedResult, myMessage)
Пример #2
0
    def test_stacktrace_html(self):
        """Stack traces can be caught and rendered as html
        """

        # This is about general exception handling, so ok to use catch-all
        # pylint: disable=W0703
        try:
            bbox_intersection('aoeu', 'oaeu', [])
        except Exception, e:
            # Display message and traceback

            myMessage = get_error_message(e)
            #print myMessage
            myMessage = myMessage.to_text()
            self.assertIn(str(e), myMessage)
            self.assertIn('line', myMessage)
            self.assertIn('file', myMessage)

            myMessage = get_error_message(e)
            myMessage = myMessage.to_html()
            assert str(e) in myMessage

            myMessage = myMessage.decode('string_escape')
            myExpectedResult = open(
                TEST_FILES_DIR +
                '/test-stacktrace-html.txt', 'r').read().replace('\n', '')
            self.assertIn(myExpectedResult, myMessage)
Пример #3
0
    def accept(self):
        """Automatic slot executed when the ok button is pressed.

        It will write out the keywords for the layer that is active.
        """
        self.apply_changes()
        keywords = self.get_keywords()

        # If it's postprocessing layer, we need to check if age ratio is valid
        if self.radPostprocessing.isChecked():
            valid_age_ratio, sum_age_ratios = self.age_ratios_are_valid(
                keywords)
            if not valid_age_ratio:
                message = self.tr(
                    'The sum of age ratios is %s which exceeds 1. Please '
                    'adjust  the age ration defaults so that their cumulative '
                    'value is not greater than 1.' % sum_age_ratios)
                if not self.test:
                    # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
                    QtGui.QMessageBox.warning(
                        self, self.tr('InaSAFE'), message)
                return

        try:
            self.keyword_io.write_keywords(layer=self.layer, keywords=keywords)
        except InaSAFEError, e:
            error_message = get_error_message(e)
            message = self.tr(
                'An error was encountered when saving the keywords:\n'
                '%s' % error_message.to_html())
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(self, self.tr('InaSAFE'), message)
Пример #4
0
    def accept(self):
        """Automatic slot executed when the ok button is pressed.

        It will write out the keywords for the layer that is active.
        """
        self.apply_changes()
        keywords = self.get_keywords()

        # If it's postprocessing layer, we need to check if age ratio is valid
        if self.radPostprocessing.isChecked():
            valid_age_ratio, sum_age_ratios = self.age_ratios_are_valid(
                keywords)
            if not valid_age_ratio:
                message = self.tr(
                    'The sum of age ratios is %s which exceeds 1. Please '
                    'adjust  the age ration defaults so that their cumulative '
                    'value is not greater than 1.' % sum_age_ratios)
                if not self.test:
                    # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
                    QtGui.QMessageBox.warning(self, self.tr('InaSAFE'),
                                              message)
                return

        try:
            self.keyword_io.write_keywords(layer=self.layer, keywords=keywords)
        except InaSAFEError, e:
            error_message = get_error_message(e)
            message = self.tr(
                'An error was encountered when saving the keywords:\n'
                '%s' % error_message.to_html())
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(self, self.tr('InaSAFE'), message)
Пример #5
0
 def test_issue157(self):
     """Verify that we get the error class name back - issue #157
        .. seealso:: https://github.com/AIFDR/inasafe/issues/121
     """
     try:
         bbox_intersection('aoeu', 'oaeu', [])
     except BoundingBoxError, e:
         myMessage = get_error_message(e)
         myString = 'BoundingBoxError'
         assert myString in myMessage.to_text(), myMessage
         myString = 'Western boundary'
         assert myString in myMessage.to_text(), myMessage
Пример #6
0
 def fake_error(self):
     """Make a fake error (helper for other tests)
     :returns: Contents of the message viewer as string and with newlines
         stripped off.
     :rtype : str
     """
     e = Exception()
     context = 'Something went wrong'
     message = get_error_message(e, context=context)
     self.message_viewer.error_message_event(None, message)
     text = self.message_viewer.page_to_text().replace('\n', '')
     return text
Пример #7
0
    def accept(self):
        """Automatic slot executed when the ok button is pressed.

        It will write out the keywords for the layer that is active.
        """
        self.apply_changes()
        keywords = self.get_keywords()
        try:
            self.keyword_io.write_keywords(layer=self.layer, keywords=keywords)
        except InaSAFEError, e:
            error_message = get_error_message(e)
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(self, self.tr('InaSAFE'), ((self.tr(
                'An error was encountered when saving the keywords:\n'
                '%s' % error_message.to_html()))))
Пример #8
0
    def accept(self):
        """Automatic slot executed when the ok button is pressed.

        It will write out the keywords for the layer that is active.
        """
        self.apply_changes()
        myKeywords = self.get_keywords()
        try:
            self.keywordIO.write_keywords(layer=self.layer, keywords=myKeywords)
        except InaSAFEError, e:
            myErrorMessage = get_error_message(e)
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(
                self,
                self.tr("InaSAFE"),
                ((self.tr("An error was encountered when saving the keywords:\n" "%s" % myErrorMessage.to_html()))),
            )