예제 #1
0
def update_class(cls):
    """
    Update the info for a class

    Returns:
        None
    """
    parsed = Parsed(cls)
    parsed.parse()

    if not parsed.requires_update:
        return

    filename = inspect.getfile(cls)

    with open(filename, 'r+') as location:
        lines = location.readlines()

    first_line, last_line = get_source_lines(lines, cls)

    with open(filename, 'r+') as location:
        for index, line in enumerate(location.readlines()[first_line:last_line]):
            if config['requirement_info'] in line:
                test_info_index = index + first_line
                break

    append_json_info(filename, test_info_index, create_json_info())
예제 #2
0
def update_func(function):
    """
    Update the info for a function

    Args:
        f (function): The function to update

    Returns:
        dict: function information
            test_id: id of the function encountered
    """
    parsed = Parsed(function)
    parsed.parse()

    info_dict = parsed.test_info
    if not parsed.requires_update:
        return info_dict

    filename = inspect.getfile(function)
    with open(filename, 'r+') as location:
        for index, line in enumerate(location.readlines()):
            # We have not reached the function yet
            if index < function.__code__.co_firstlineno:
                continue

            if 'TEST INFO' in line:
                test_info_index = index
                break

    new_json = create_json_info()
    append_json_info(filename, test_info_index, new_json)

    return new_json