def test_every_line_longer_than_limit(self): # sanity check lines = [('line %d' % i) * _MAX_ERROR_LINE_LENGTH for i in range(_MAX_ERROR_LINES+2)] result = cut_long_message('\n'.join(lines)).splitlines() assert_true(_ERROR_CUT_EXPLN in result) assert_equal(result[0], lines[0]) assert_equal(result[-1], lines[-1]) assert_true(sum(_count_line_lengths(result)) <= _MAX_ERROR_LINES+1)
def test_boundary(self): b = _MAX_ERROR_LINE_LENGTH lengths = [ b - 1, b, b + 1, 2 * b - 1, 2 * b, 2 * b + 1, 7 * b - 1, 7 * b, 7 * b + 1 ] lines = ['e' * length for length in lengths] assert_equal(_count_line_lengths(lines), [1, 1, 2, 2, 2, 3, 7, 7, 8])
def test_correct_number_of_lines(self): assert_equal(sum(_count_line_lengths(self.result)), _MAX_ERROR_LINES+1)
def test_boundary(self): b = _MAX_ERROR_LINE_LENGTH lengths = [b-1, b, b+1, 2*b-1, 2*b, 2*b+1, 7*b-1, 7*b, 7*b+1] lines = [ 'e'*length for length in lengths ] assert_equal(_count_line_lengths(lines), [1, 1, 2, 2, 2, 3, 7, 7, 8])
def test_longer_than_max_lines(self): lines = [ '1' * i * (_MAX_ERROR_LINE_LENGTH+3) for i in range(4) ] assert_equal(_count_line_lengths(lines), [1,2,3,4])
def test_shorter_than_max_lines(self): lines = ['', '1', 'foo', 'barz and fooz', '', 'a bit longer line', '', 'This is a somewhat longer (but not long enough) error message'] assert_equal(_count_line_lengths(lines), [1] * len(lines))
def test_empty_line(self): assert_equal(_count_line_lengths(['']), [1])
def test_no_lines(self): assert_equal(_count_line_lengths([]), [])
def _assert_basics(self, result, input=None): assert_equal(sum(_count_line_lengths(result)), _MAX_ERROR_LINES+1) assert_true(_ERROR_CUT_EXPLN in result) if input: assert_equal(result[0], input[0]) assert_equal(result[-1], input[-1])
def test_correct_number_of_lines(self): assert_equal(sum(_count_line_lengths(self.result)), MAX_ERROR_LINES + 1)
def test_longer_than_max_lines(self): lines = ['1' * i * (_MAX_ERROR_LINE_LENGTH + 3) for i in range(4)] assert_equal(_count_line_lengths(lines), [1, 2, 3, 4])
def test_shorter_than_max_lines(self): lines = [ '', '1', 'foo', 'barz and fooz', '', 'a bit longer line', '', 'This is a somewhat longer (but not long enough) error message' ] assert_equal(_count_line_lengths(lines), [1] * len(lines))
def _assert_basics(self, result, input=None): assert_equal(sum(_count_line_lengths(result)), MAX_ERROR_LINES + 1) assert_true(_ERROR_CUT_EXPLN in result) if input: assert_equal(result[0], input[0]) assert_equal(result[-1], input[-1])