Exemplo n.º 1
0
def _save_data(raw_data: str, enriched_data: str, meta_data: MetadataType,
               name: str):
    """."""
    file_write(os.path.join(BASE_PATH, f'{name}.raw'), raw_data)
    if enriched_data:
        file_write(os.path.join(BASE_PATH, f'{name}.enriched'), enriched_data)
    json_write(os.path.join(BASE_PATH, f'{name}.meta'), meta_data)
    message = f'Done with {name}!'
    print(message)
Exemplo n.º 2
0
def _update_test(file_path: str, function_name: str,
                 new_assertion_value: Any) -> bool:
    """Update the test with the given function_name in the file at the given file_path with the new_assertion_value."""
    from python_data import python_function_blocks

    test_file_content = file_read(file_path)
    original_function_block = function_block = [
        i for i in python_function_blocks(test_file_content)
        if function_name in i
    ][0]
    function_block = function_block.replace(
        FILL_OUTPUT_SIGNAL_IN_CONTEXT, f'== {new_assertion_value.__repr__()}',
        1)
    test_file_content = test_file_content.replace(original_function_block,
                                                  function_block, 1)
    return file_write(file_path, test_file_content)
Exemplo n.º 3
0
def _update_test_with_error(file_path: str, function_name: str,
                            error_type: str, erroneous_assertion: str) -> bool:
    """Update the test with the given function_name in the file at the given file_path with the new_assertion_value."""
    from python_data import python_function_blocks

    test_file_content = file_read(file_path)
    original_function_block = function_block = [
        i for i in python_function_blocks(test_file_content)
        if function_name in i
    ][0]
    # TODO: currently, the indentation of the new assertion is hard coded; eventually, I would like to get the indentation from the original assertion
    new_assertion = f'with pytest.raises({error_type}):\n        {erroneous_assertion}'
    full_erroneous_assertion = f'assert {erroneous_assertion} == \'{RAISES_OUTPUT_SIGNAL}\''
    function_block = function_block.replace(full_erroneous_assertion,
                                            new_assertion, 1)
    test_file_content = test_file_content.replace(original_function_block,
                                                  function_block, 1)
    return file_write(file_path, test_file_content)
Exemplo n.º 4
0
def _replace_task(task_data, replacement: str):
    """."""
    task_file_data = file_read(base_task_file)
    task_text = _task_to_text(task_data)
    task_file_data = task_file_data.replace(task_text, replacement)
    file_write(base_task_file, task_file_data)
Exemplo n.º 5
0
        return None


def add(task_name: str):
    """."""
    if not task_name.strip():
        message = 'You cannot create a task with an empty name.'
        print(message)
        return

    matching_task = task_with_name(task_name)
    if matching_task:
        message = f'There is already a task with the name "{task_name}" and no two tasks can have the same name.'
        print(message)
        return

    task_data = {"date_added": _datestamp(), "metadata": {}, "name": task_name}

    _write_task(task_data)
    return task_data


if __name__ == '__main__':
    if not directory_exists(base_directory):
        directory_create(base_directory)

    if not file_exists(base_task_file):
        file_write(base_task_file, '')
    else:
        file_copy(base_task_file, base_backup_task_file)