<commit_before>" autoload/nose.vim
" Author: <NAME> (<EMAIL>)


if !has('python')
    echo "Error: Required vim compiled with +python"
    finish
endif

function! nose#pre_command()
    let old_path = $PATH
    if has('win32')
        let $PATH=nose#get_virtual_env_path().";".$PATH
    else
        let $PATH=nose#get_virtual_env_path().":".$PATH
    endif
    return old_path
endfunction

function! nose#post_command(old_path)
    let $PATH = a:old_path
endfunction

function! nose#get_virtual_env_path()
    " TODO: Check for prensence of $VIRTUAL_ENV env var
    " TODO: Get VirtualEnv folder from Git configuration if .venv file is not
    " used.
    return nose#read_virtualenv_config_from_file()
endfunction

function! nose#read_virtualenv_config_from_file()
    let venv_config = findfile(".venv", "./;")
    if !filereadable(venv_config)
        return
    endif
python << EOF
import vim
import os

venv_config = vim.eval("venv_config")
path = ""
with open(venv_config) as vc:
    lines = [line for line in vc.readlines() if line]
    path = lines[0].strip()
    path = os.path.normpath(os.path.join(os.path.dirname(venv_config), path))
    if os.name == 'nt':
        path = os.path.join(path, "scripts")
    else:
        path = os.path.join(path, "bin")
    path = path.replace("\\", "/")
    vim.command("let l:path=\"%s\"" % path)
EOF
return l:path
endfunction

function! nose#read_virtualenv_config_from_git()
endfunction

function! nose#read_virtualenv_config_from_env_var()
endfunction

function! nose#get_current_test()
python << EOF
import code_analyzer
import vim
position = vim.current.window.cursor
filename  = vim.current.buffer.name
try:
    test_function = code_analyzer.get_complete_function_name_at(filename, position)
except:
    # No function found because there is an error in the parsed file. Let nose
    # found the error too and show it in the quickfix window.
    test_function = ""
test = filename
if test_function:
    test = test + ":" + test_function
# Always use Posix path (even on Windows)
test = test.replace("\\", "/")
vim.command("let l:test=\"%s\"" % test)
EOF
    return l:test
endfunction

function! nose#run() abort
    let old_path = nose#pre_command()
    let cmd = "make "
    if exists(":Make")
        let l:cmd = ":Make "
    endif
    let args = nose#get_current_test()
    try
        exec l:cmd.l:args
    finally
        call nose#post_command(old_path)
    endtry
endfunction

function! nose#run_all() abort
    let old_path = nose#pre_command()
    echo "Not implemented!"
    call nose#post_command(old_path)
endfunction

function! nose#debug() abort
    let old_path = nose#pre_command()
    let cmd = ":!"
    if exists(":Start")
        let cmd = ":Start "
    elseif has('win32')
        let cmd = ":!start "
    endif
    let args = nose#get_current_test()
    try
        exec l:cmd."nosetests -s ".l:args
    finally
        call nose#post_command(old_path)
    endtry
endfunction
<commit_msg>Added  command to run all tests under the current git root<commit_after>" autoload/nose.vim
" Author: <NAME> (<EMAIL>)


if !has('python')
    echo "Error: Required vim compiled with +python"
    finish
endif

function! nose#pre_command()
    let old_path = $PATH
    if has('win32')
        let $PATH=nose#get_virtual_env_path().";".$PATH
    else
        let $PATH=nose#get_virtual_env_path().":".$PATH
    endif
    return old_path
endfunction

function! nose#post_command(old_path)
    let $PATH = a:old_path
endfunction

function! nose#get_virtual_env_path()
    " TODO: Check for prensence of $VIRTUAL_ENV env var
    " TODO: Get VirtualEnv folder from Git configuration if .venv file is not
    " used.
    return nose#read_virtualenv_config_from_file()
endfunction

function! nose#read_virtualenv_config_from_file()
    let venv_config = findfile(".venv", "./;")
    if !filereadable(venv_config)
        return
    endif
python << EOF
import vim
import os

venv_config = vim.eval("venv_config")
path = ""
with open(venv_config) as vc:
    lines = [line for line in vc.readlines() if line]
    path = lines[0].strip()
    path = os.path.normpath(os.path.join(os.path.dirname(venv_config), path))
    if os.name == 'nt':
        path = os.path.join(path, "scripts")
    else:
        path = os.path.join(path, "bin")
    path = path.replace("\\", "/")
    vim.command("let l:path=\"%s\"" % path)
EOF
return l:path
endfunction

function! nose#read_virtualenv_config_from_git()
endfunction

function! nose#read_virtualenv_config_from_env_var()
endfunction

function! nose#git_repository_root()
    let root =  system('git rev-parse --show-toplevel')
    if v:shell_error
        throw "Git not available for project root discovery!"
    endif
    return l:root
endfunction

function! nose#get_current_test()
python << EOF
import code_analyzer
import vim
position = vim.current.window.cursor
filename  = vim.current.buffer.name
try:
    test_function = code_analyzer.get_complete_function_name_at(filename, position)
except:
    # No function found because there is an error in the parsed file. Let nose
    # found the error too and show it in the quickfix window.
    test_function = ""
test = filename
if test_function:
    test = test + ":" + test_function
# Always use Posix path (even on Windows)
test = test.replace("\\", "/")
vim.command("let l:test=\"%s\"" % test)
EOF
    return l:test
endfunction

function! nose#run(...) abort
    let old_path = nose#pre_command()
    let cmd = "make "
    if exists(":Make")
        let l:cmd = ":Make "
    endif
    try
        exec l:cmd.join(a:000)
    finally
        call nose#post_command(old_path)
    endtry
endfunction

function! nose#run_test() abort
    call nose#run(nose#get_current_test())
endfunction

function! nose#run_all() abort
    try
        call nose#run(nose#git_repository_root())
    catch /^Git/
        echo "Cannot run all tests: ".v:exception
    endtry
endfunction

function! nose#debug(...) abort
    let old_path = nose#pre_command()
    let cmd = ":!"
    if exists(":Start")
        let cmd = ":Start "
    elseif has('win32')
        let cmd = ":!start "
    endif
    try
        exec l:cmd."nosetests -s ".join(a:000)
    finally
        call nose#post_command(old_path)
    endtry
endfunction

function! nose#debug_test() abort
    call nose#debug(nose#get_current_test())
endfunction

function! nose#debug_all() abort
    try
        call nose#debug(nose#git_repository_root())
    catch /^Git/
        echo "Cannot debug all tests: ".v:exception
    endtry
endfunction

{'fraction_non_alphanumeric': 0.11616858237547893, 'fraction_numerical': 0.0024521072796934865, 'mean_word_length': 3.4094594594594594, 'pattern_counts': {'":': 16, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3661944', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2155, 'n_words': 579}