def _assert_line_range(self, violation_lines, expected_ranges): """ Assert that the snippets loaded using `violation_lines` have the correct ranges of lines. `violation_lines` is a list of line numbers containing violations (which should get included in snippets). `expected_ranges` is a list of `(start, end)` tuples representing the starting and ending lines expected in a snippet. Line numbers start at 1. """ # Load snippets from the source file snippet_list = Snippet.load_snippets( self._src_path, violation_lines ) # Check that we got the right number of snippets self.assertEqual(len(snippet_list), len(expected_ranges)) # Check that the snippets have the desired ranges for snippet, line_range in zip(snippet_list, expected_ranges): # Expect that the line range is correct self.assertEqual(snippet.line_range(), line_range) # Expect that the source contents are correct start, end = line_range self.assertEqual(snippet.text(), self._src_lines(start, end))