def test_string_lines_start_end_index(self, data): """ Test line_number_to_line. """ lines = StringLines(data['string']) self.assertEqual(lines.line_number_to_line(data['line_number']), data['line'])
def test_string_lines_start_end_index(self, data): """ Test StringLines index_to_line_start_index and index_to_line_end_index. """ lines = StringLines(data['string']) self.assertEqual(lines.index_to_line_start_index(data['index']), data['line_start_index']) self.assertEqual(lines.index_to_line_end_index(data['index']), data['line_end_index'])
def __init__(self, file_contents, results): """ Init method. Arguments: file_contents: The contents of the Python file. results: A file results objects to which violations will be added. """ super(BaseVisitor, self).__init__() self.file_contents = file_contents self.lines = StringLines(self.file_contents) self.results = results
def prepare_results(self, file_string, line_comment_delim=None): """ Prepares the results for output for this file. Arguments: file_string: The string of content for this file. line_comment_delim: A string representing the start of a line comment. For example "##" for Mako and "//" for JavaScript. """ string_lines = StringLines(file_string) for violation in self.violations: violation.prepare_results(self.full_path, string_lines) if line_comment_delim is not None: self._filter_commented_code(line_comment_delim)
def __init__(self, ruleset, results, *args, **kwargs): super(HtmlInterpolateExpression, self).__init__(*args, **kwargs) self.string_lines = StringLines(kwargs['template']) self.ruleset = ruleset self.results = results self.validated = False self.interpolated_string_var = None trans_expr = self.expression_inner # extracting interpolated variable string name expr_list = trans_expr.split(' ') if len(expr_list) < 2: _add_violations(self.results, self.ruleset.django_html_interpolation_invalid_tag, self) return self.interpolated_string_var = expr_list[1]
def test_string_lines_line_numbers(self, data): """ Test line_number_to_line. """ lines = StringLines(data['string']) assert lines.line_number_to_line(data['line_number']) == data['line']
def __init__(self, ruleset, results, *args, **kwargs): super(BlockTransExpression, self).__init__(*args, **kwargs) self.string_lines = StringLines(kwargs['template']) self.ruleset = ruleset self.results = results