示例#1
0
 def test_message_template_can_be_empty(self):
     """Ensure the error report representation can be empty."""
     message = 'Discard me.'
     error = EmptyDescriptionError(
         self.function_description, message,
     )
     filename = '/Some/File/Discarded.py'
     message_template = ''
     error_report = ErrorReport(
         errors=[error],
         filename=filename,
         message_template=message_template,
     )
     self.assertEqual(
         str(error_report), ''
     )
示例#2
0
 def test_format_can_include_string_constants(self):
     """Ensure that string constants can be in message."""
     message = 'The Message!'
     error = EmptyDescriptionError(
         self.function_description, message,
     )
     filename = './some_filename.py'
     message_template = '({msg}) :)'
     error_report = ErrorReport(
         errors=[error],
         filename=filename,
         message_template=message_template
     )
     self.assertEqual(
         str(error_report),
         '(Empty description: e The Message!) :)'
     )
示例#3
0
 def test_format_string_only_msg_id(self):
     """Ensure that message template can have one item."""
     message = 'This message is missing a description.'
     error = EmptyDescriptionError(
         self.function_description, message,
     )
     filename = '/Users/ronald_vermillion/great_donuts.ijs'
     message_template = '{msg_id}'
     error_report = ErrorReport(
         errors=[error],
         filename=filename,
         message_template=message_template
     )
     self.assertEqual(
         str(error_report),
         EmptyDescriptionError.error_code
     )
示例#4
0
 def test_message_template_is_none_uses_default(self):
     message = 'My Message'
     error = EmptyDescriptionError(
         self.function_description, message,
     )
     filename = './data/datum.py'
     error_report = ErrorReport(
         errors=[error],
         filename=filename,
         message_template=None,
     )
     error_repr = str(error_report)
     self.assertTrue(
         all([
             message in error_repr,
             filename in error_repr,
             EmptyDescriptionError.error_code in error_repr,
         ])
     )
示例#5
0
文件: driver.py 项目: mathPi/darglint
def get_error_report(filename,
                     verbosity,
                     raise_errors_for_syntax,
                     message_template=None,
                     ):
    # type: (str, int, bool, str) -> str
    """Get the error report for the given file.

    Args:
        filename: The name of the module to check.
        verbosity: The level of verbosity, in the range [1, 3].
        raise_errors_for_syntax: True if we want parser errors
            to propagate up (crashing darglint.)  This is useful
            if we are developing on darglint -- we can get the stack
            trace and know exactly where darglint failed.
        message_template: A python format string for specifying
            how the message should appear to the user.

    Returns:
        An error report for the file.

    """
    program = read_program(filename)
    try:
        tree = ast.parse(program)
        functions = get_function_descriptions(tree)
        checker = IntegrityChecker(
            raise_errors=raise_errors_for_syntax,
        )
        for function in functions:
            checker.schedule(function)
        return checker.get_error_report_string(
            verbosity,
            filename,
            message_template=message_template,
        )
    except SyntaxError as e:
        error = darglint.errors.PythonSyntaxError(e)
        report = ErrorReport([error], filename, verbosity, message_template)
        return str(report)
示例#6
0
    def test_all_attributes(self):
        """Test against all possible attributes."""
        message = 'The Message!'
        error = EmptyDescriptionError(
            self.function_description, message,
        )
        filename = './some_filename.py'
        message_template = ' '.join([
            '{msg}',
            '{msg_id}',
            '{line}',
            '{path}',
            '{obj}',
        ])
        error_report = ErrorReport(
            errors=[error],
            filename=filename,
            message_template=message_template,
        )

        # This will raise an error if the template
        # parameters are incorrect.
        str(error_report)