def test_not_line_type(): line_markers = LineMarkers(2 * [''], 1) with pytest.raises(ValueError) as excinfo: line_markers.set(1, 2) assert 'not LineType' in str(excinfo.value)
def test_none(): line_markers = LineMarkers(2, 0) line_markers[0] = LineType.func_def line_markers[1] = LineType.act # do_thing() result = line_markers.check_act_assert_spacing() assert isinstance(result, Generator) assert list(result) == []
def test_unprocessed(): """ A line can not be set as unprocessed """ line_markers = LineMarkers(2 * [''], 1) with pytest.raises(ValueError) as excinfo: line_markers.set(0, LineType.unprocessed) assert '"???"' in str(excinfo.value)
def test(): line_markers = LineMarkers(2, 1) result = line_markers.__setitem__(0, LineType.func_def) assert result is None assert line_markers == [ LineType.func_def, LineType.unprocessed, ]
def test_reassign(): """ First line of test is reassigned. (index=0) """ line_markers = LineMarkers(2 * [''], 7) line_markers.types[0] = LineType.func_def with pytest.raises(ValidationError) as excinfo: line_markers.set(0, LineType.act) assert excinfo.value.line_number == 7 assert excinfo.value.offset == 1 assert excinfo.value.text == 'AAA99 collision when marking line 7 (index=0) as ACT, was already DEF'
def test_ok(): line_markers = LineMarkers(6, 7) line_markers[0] = LineType.func_def line_markers[1] = LineType.arrange line_markers[2] = LineType.blank_line line_markers[3] = LineType.act line_markers[4] = LineType.blank_line line_markers[5] = LineType._assert result = line_markers.check_blank_lines() assert isinstance(result, typing.Generator) assert list(result) == []
def test(): line_markers = LineMarkers(6 * [''], 1) line_markers.types[2] = LineType.blank_line result = line_markers.update(1, 3, LineType.act) assert result == 2 assert line_markers.types == [ LineType.unprocessed, LineType.act, LineType.blank_line, LineType.act, LineType.unprocessed, LineType.unprocessed, ]
def test(): line_markers = LineMarkers(6, 1) line_markers[2] = LineType.blank_line result = line_markers.update((1, 3), LineType.act) assert result is None assert line_markers == [ LineType.unprocessed, LineType.act, LineType.blank_line, LineType.act, LineType.unprocessed, LineType.unprocessed, ]
def test_mark_skip(existing_type, new_type) -> None: """ +-------+-------+-------+-------+ | DEF | ACT | ARR | ASS | +-------+-------+-------+-------+-------+ | BL | SKIP | SKIP | SKIP | SKIP | | CMT | SKIP | SKIP | SKIP | SKIP | +-------+-------+-------+-------+-------+ """ line_markers = LineMarkers([''], 0) line_markers.set(0, existing_type) result = line_markers.set(0, new_type) assert result is False assert line_markers.types == [existing_type]
def test_no_arrange(): """ Tests without arrangement pass """ line_markers = LineMarkers(7 * [''], 5) line_markers.types[0] = LineType.func_def line_markers.types[1] = LineType.unprocessed # Some docstring line_markers.types[2] = LineType.unprocessed # Some docstring line_markers.types[3] = LineType.unprocessed # Some docstring line_markers.types[4] = LineType.act # result = 2 + 0 line_markers.types[5] = LineType.blank_line line_markers.types[6] = LineType._assert # assert result == 2 result = line_markers.check_arrange_act_spacing() assert isinstance(result, Generator) assert list(result) == []
def test_comment_before_assert(): """ Comment before Assert passes """ line_markers = LineMarkers(8, 5) line_markers[0] = LineType.func_def line_markers[1] = LineType.arrange # x = 1 line_markers[2] = LineType.arrange # y = 2 line_markers[3] = LineType.blank_line line_markers[4] = LineType.act # result = x + y line_markers[5] = LineType.blank_line line_markers[6] = LineType.unprocessed # Sum x and y line_markers[7] = LineType._assert # assert result == 2 result = line_markers.check_act_assert_spacing() assert isinstance(result, Generator) assert list(result) == []
def test_reassign(): line_markers = LineMarkers(2, 1) line_markers[0] = LineType.func_def with pytest.raises(ValueError) as excinfo: line_markers[0] = LineType.act assert str(excinfo.value ) == 'collision when marking this line as ACT, was already DEF'
def test_mark_qqq(new_type) -> None: """ Unprocessed lines can be set as any line type +-------+-------+-------+-------+-------+-------+ | BL | CMT | DEF | ACT | ARR | ASS | +-------+-------+-------+-------+-------+-------+-------+ | QQQ | SET | SET | SET | SET | SET | SET | +-------+-------+-------+-------+-------+-------+-------+ """ line_markers = LineMarkers(2 * [''], 1) result = line_markers.set(0, new_type) assert result is True assert line_markers.types == [ new_type, LineType.unprocessed, ]
def test_func_def(): """ Function definition has some funky call args separated by a blank line """ line_markers = LineMarkers(3, 7) line_markers[0] = LineType.func_def line_markers[1] = LineType.blank_line line_markers[2] = LineType.func_def result = line_markers.check_blank_lines() assert isinstance(result, typing.Generator) assert list(result) == [ AAAError( line_number=8, offset=0, text='AAA05 blank line in block', ), ]
def test_collision(): """ Line Markers at start of test = [ LineType.func_def, < Act LineType.unprocessed, < Act LineType.blank_line, LineType.unprocessed, ] """ line_markers = LineMarkers(4, 10) line_markers[0] = LineType.func_def line_markers[2] = LineType.blank_line with pytest.raises(ValidationError) as excinfo: line_markers.update((0, 1), LineType.act) assert excinfo.value.line_number == 10 assert excinfo.value.offset == 1 assert excinfo.value.text.startswith('AAA99 ')
def test(): result = LineMarkers(5, 7) assert result == [ LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, ] assert result.fn_offset == 7
def test(): result = LineMarkers(5 * [''], 7) assert result.types == [ LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, LineType.unprocessed, ] assert result.lines == ['', '', '', '', ''] assert result.fn_offset == 7
def test_arrange(): line_markers = LineMarkers(8, 7) line_markers[0] = LineType.func_def line_markers[1] = LineType.arrange line_markers[2] = LineType.blank_line line_markers[3] = LineType.arrange line_markers[4] = LineType.blank_line line_markers[5] = LineType.act line_markers[6] = LineType.blank_line line_markers[7] = LineType._assert result = line_markers.check_blank_lines() assert isinstance(result, typing.Generator) assert list(result) == [ AAAError( line_number=9, offset=0, text='AAA05 blank line in block', ), ]
def test_no_gap(): """ No gap raises - error points at act block because no spaces """ line_markers = LineMarkers(6, 5) line_markers[0] = LineType.func_def line_markers[1] = LineType.arrange # x = 1 line_markers[2] = LineType.blank_line line_markers[3] = LineType.act # result = x + 3 line_markers[4] = LineType.unprocessed # Sum do stuff line_markers[5] = LineType._assert # assert result == 4 result = line_markers.check_act_assert_spacing() assert isinstance(result, Generator) assert list(result) == [ AAAError( line_number=9, offset=0, text='AAA04 expected 1 blank line before Assert block, found none', ), ]
def test_too_big_gap(): """ Multiple BL raises. First extra line is pointed to """ line_markers = LineMarkers(8, 5) line_markers[0] = LineType.func_def line_markers[1] = LineType.arrange # x = 1 line_markers[2] = LineType.blank_line line_markers[3] = LineType.unprocessed # Sum do stuff line_markers[4] = LineType.act # result = x + 3 line_markers[5] = LineType.blank_line line_markers[6] = LineType.blank_line line_markers[7] = LineType._assert # assert result == 4 result = line_markers.check_act_assert_spacing() assert isinstance(result, Generator) assert list(result) == [ AAAError( line_number=11, offset=0, text='AAA04 expected 1 blank line before Assert block, found 2', ), ]
def test_no_gap(): """ No gap raises - error points at act block """ line_markers = LineMarkers(6 * [''], 5) line_markers.types[0] = LineType.func_def line_markers.types[1] = LineType.arrange # x = 1 line_markers.types[2] = LineType.unprocessed # Sum do stuff line_markers.types[3] = LineType.act # result = x + 3 line_markers.types[4] = LineType.blank_line line_markers.types[5] = LineType._assert # assert result == 4 result = line_markers.check_arrange_act_spacing() assert isinstance(result, Generator) result_list = list(result) assert len(result_list) == 1 assert result_list[0] == AAAError( line_number=8, offset=0, text='AAA03 expected 1 blank line before Act block, found none', )
def mark_bl_cmt_on_bl_cmt(existing_type, new_type) -> None: """ +-------+-------+ | BL | CMT | +-------+-------+-------+ | BL | RAISE | RAISE | | CMT | RAISE | RAISE | +-------+-------+-------+ """ line_markers = LineMarkers([''], 0) line_markers.set(0, existing_type) with pytest.raises(ValidationError): line_markers.set(0, new_type) assert line_markers.types == [existing_type]
def test_blocks_not_overwritten(existing_type, new_type) -> None: """ +-------+-------+-------+-------+-------+-------+ | BL | CMT | DEF | ACT | ARR | ASS | +-------+-------+-------+-------+-------+-------+-------+ | DEF | RAISE | RAISE | RAISE | RAISE | RAISE | RAISE | | ACT | RAISE | RAISE | RAISE | RAISE | RAISE | RAISE | | ARR | RAISE | RAISE | RAISE | RAISE | RAISE | RAISE | | ASS | RAISE | RAISE | RAISE | RAISE | RAISE | RAISE | +-------+-------+-------+-------+-------+-------+-------+ """ line_markers = LineMarkers([''], 0) line_markers.set(0, existing_type) with pytest.raises(ValidationError): line_markers.set(0, new_type) assert line_markers.types == [existing_type]
def test_out_of_range(): line_markers = LineMarkers(2 * [''], 1) with pytest.raises(IndexError): line_markers.set(10, LineType.func_def)
def test_not_slice(): line_markers = LineMarkers(2, 1) with pytest.raises(NotImplementedError): line_markers[:] = LineType.act
def test_comment_after(): line_markers = LineMarkers(7 * [''], 11) line_markers.types[0] = LineType.func_def line_markers.types[1] = LineType.arrange line_markers.types[2] = LineType.blank_line line_markers.types[3] = LineType.act line_markers.types[4] = LineType.comment line_markers.lines[4] = ' # Action done' line_markers.types[5] = LineType.blank_line line_markers.types[6] = LineType._assert result = line_markers.check_comment_in_act() assert isinstance(result, typing.Generator) assert list(result) == [ AAAError( line_number=15, offset=4, text='AAA06 comment in Act block', ), ]
def test_comment_end_of_test(): line_markers = LineMarkers(7 * [''], 11) line_markers.types[0] = LineType.func_def line_markers.types[1] = LineType.arrange line_markers.types[2] = LineType.blank_line line_markers.types[3] = LineType.act line_markers.types[4] = LineType.blank_line line_markers.types[5] = LineType._assert line_markers.types[6] = LineType.comment line_markers.lines[6] = ' # TODO check this other thing' result = line_markers.check_comment_in_act() assert isinstance(result, typing.Generator) assert list(result) == []
def test_out_of_range(): line_markers = LineMarkers(2, 1) with pytest.raises(IndexError): line_markers[10] = LineType.func_def
def test_too_big_gap(): """ Multiple BL raises. Act block is pointed to. """ line_markers = LineMarkers(8 * [''], 5) line_markers.types[0] = LineType.func_def line_markers.types[1] = LineType.arrange # x = 1 line_markers.types[2] = LineType.blank_line line_markers.types[3] = LineType.blank_line line_markers.types[4] = LineType.unprocessed # Sum do stuff line_markers.types[5] = LineType.act # result = x + 3 line_markers.types[6] = LineType.blank_line line_markers.types[7] = LineType._assert # assert result == 4 result = line_markers.check_arrange_act_spacing() assert isinstance(result, Generator) result_list = list(result) assert len(result_list) == 1 assert result_list[0] == AAAError( line_number=10, offset=0, text='AAA03 expected 1 blank line before Act block, found 2', )