Пример #1
0
def check_get_line_col():
    print(("=== " + sys._getframe().f_code.co_name))
    content = """01 02 03 04 05 06 07 08 09
11 12 13 14 15 16 17 18 19
21 22 23 24 25 26 27 28 29
31 32 33 34 35 36 37 38 39
"""
    result_file = create_results(content)

    value = 1
    result = ct.get_line_col(result_file)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 3
    result = ct.get_line_col(result_file, skip_col=2)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 11
    result = ct.get_line_col(result_file, 1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 16
    result = ct.get_line_col(result_file, 1, 5)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 9
    result = ct.get_line_col(result_file, skip_col=-1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 17
    result = ct.get_line_col(result_file, 1, -3)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 31
    result = ct.get_line_col(result_file, -1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 14
    result = ct.get_line_col(result_file, -3, -6)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 3
    result = ct.get_line_col(result_file, seek=6)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 23
    result = ct.get_line_col(result_file, skip_line=1, skip_col=2, seek=30)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))
    value = 31
    result = ct.get_line_col(result_file, skip_line=-1, seek=-100)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))

    # ct.debug = True
    value = 21
    just_before_line_ret = 80
    sys.stderr.write('char at pos ' + str(just_before_line_ret) + ':->' +
                     content[just_before_line_ret] + '<-\n')
    result = ct.get_line_col(result_file,
                             skip_line=-1,
                             seek=-just_before_line_ret)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))

    value = 21
    just_after_line_ret = just_before_line_ret + 1
    sys.stderr.write('char at pos ' + str(just_after_line_ret) + ':->' +
                     content[just_after_line_ret] + '<-\n')
    result = ct.get_line_col(result_file,
                             skip_line=-2,
                             seek=-just_after_line_ret)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))

    try:
        result = ct.get_line_col(result_file, skip_line=4)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    try:
        result = ct.get_line_col(result_file, skip_line=-5)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    os.remove(result_file)

    # test with a last empty line
    content = """01 02 03 04 05 06 07 08 09
11 12 13 14 15 16 17 18 19

"""
    result_file = create_results(content)

    value = 19
    result = ct.get_line_col(result_file, skip_line=-2, skip_col=-1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))

    value = 1
    result = ct.get_line_col(result_file, skip_line=-3)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' + str(value))

    try:
        result = ct.get_line_col(result_file, skip_line=-1)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    os.remove(result_file)

    print("ok")
Пример #2
0
def check_get_line_col():
    print(("=== " + sys._getframe().f_code.co_name))
    content = """01 02 03 04 05 06 07 08 09
11 12 13 14 15 16 17 18 19
21 22 23 24 25 26 27 28 29
31 32 33 34 35 36 37 38 39
"""
    result_file = create_results(content)

    value = 1
    result = coupling_tools.get_line_col(result_file)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 3
    result = coupling_tools.get_line_col(result_file, skip_col=2)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 11
    result = coupling_tools.get_line_col(result_file, 1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 16
    result = coupling_tools.get_line_col(result_file, 1, 5)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 9
    result = coupling_tools.get_line_col(result_file, skip_col=-1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 17
    result = coupling_tools.get_line_col(result_file, 1, -3)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 31
    result = coupling_tools.get_line_col(result_file, -1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 14
    result = coupling_tools.get_line_col(result_file, -3, -6)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 3
    result = coupling_tools.get_line_col(result_file, seek=6)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 23
    result = coupling_tools.get_line_col(
        result_file, skip_line=1, skip_col=2, seek=30)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))
    value = 31
    result = coupling_tools.get_line_col(result_file, skip_line=-1, seek=-100)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))

    #coupling_tools.debug = True
    value = 21
    just_before_line_ret = 80
    sys.stderr.write('char at pos ' + str(just_before_line_ret) + ':->' +
                     content[just_before_line_ret] + '<-\n')
    result = coupling_tools.get_line_col(result_file, skip_line=-1,
                                         seek=-just_before_line_ret)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))

    value = 21
    just_after_line_ret = just_before_line_ret + 1
    sys.stderr.write('char at pos ' + str(just_after_line_ret) + ':->' +
                     content[just_after_line_ret] + '<-\n')
    result = coupling_tools.get_line_col(result_file, skip_line=-2,
                                         seek=-just_after_line_ret)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))

    try:
        result = coupling_tools.get_line_col(result_file, skip_line=4)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    try:
        result = coupling_tools.get_line_col(result_file, skip_line=-5)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    os.remove(result_file)

    # test with a last empty line
    content = """01 02 03 04 05 06 07 08 09
11 12 13 14 15 16 17 18 19

"""
    result_file = create_results(content)

    value = 19
    result = coupling_tools.get_line_col(
        result_file, skip_line=-2, skip_col=-1)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))

    value = 1
    result = coupling_tools.get_line_col(result_file, skip_line=-3)
    if value != result:
        raise Exception("! got " + str(result) + ' instead of ' +
                        str(value))

    try:
        result = coupling_tools.get_line_col(result_file, skip_line=-1)
    except:
        pass
    else:
        raise Exception("! should have fail !")

    os.remove(result_file)

    print("ok")