1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
# bash completion for pytest(1) -*- shell-script -*-
_comp_cmd_pytest__option_choice_args()
{
local modes=$("$1" "$2=bash-completion-nonexistent" 2>&1 |
command sed -e 's/[^[:space:][:alnum:]_-]\{1,\}//g' \
-ne 's/.*choose from //p')
_comp_compgen -a -- -W '$modes'
}
_comp_cmd_pytest()
{
local cur prev words cword was_split comp_args
_comp_initialize -s -n : -- "$@" || return
local noargopts='!(-*|*[kmorpcWn]*)'
# shellcheck disable=SC2254
case $prev in
--help | --maxfail | --report | --junit-prefix | --doctest-glob | \
-${noargopts}[hkmorp])
return
;;
--import-mode)
_comp_compgen -- -W "prepend append importlib"
return
;;
--capture)
_comp_compgen -- -W "fd sys no tee-sys"
return
;;
--lfnf | --last-failed-no-failures)
_comp_compgen -- -W "all none"
return
;;
--tb)
_comp_compgen -- -W 'auto long short line native no'
return
;;
--show-capture)
_comp_compgen -- -W "no stdout stderr log all"
return
;;
--color)
_comp_compgen -- -W "yes no auto"
return
;;
--pastebin)
_comp_compgen -- -W "failed all"
return
;;
--junit-xml)
_comp_compgen_filedir xml
return
;;
--result-log | --log-file)
_comp_compgen_filedir log
return
;;
--ignore | -${noargopts}c)
_comp_compgen_filedir
return
;;
--confcutdir | --basetemp | --rsyncdir | --rootdir)
_comp_compgen_filedir -d
return
;;
--doctest-report)
_comp_compgen -- -W 'none cdiff ndiff udiff only_first_failure'
return
;;
--assert)
_comp_compgen -- -W "plain reinterp rewrite"
return
;;
--genscript)
_comp_compgen_filedir py
return
;;
--pythonwarnings | -${noargopts}W)
_comp_compgen -x python warning_actions
return
;;
--numprocesses | -${noargopts}n)
local REPLY
_comp_get_ncpus
_comp_compgen -- -W "{1..$REPLY} auto"
return
;;
--dist | --vcr-record?(-mode))
_comp_cmd_pytest__option_choice_args "$1" "$prev"
return
;;
esac
[[ $was_split ]] && return
if [[ $cur == -* ]]; then
_comp_compgen_help
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
if [[ $cur == *.py::*:* ]]; then
local file=${cur/.py:*/.py}
local class=${cur#*.py::} in_class=""
local line
class=${class%%:*}
while IFS= read -r line; do
if [[ $line =~ ^class[[:space:]]+${class}[[:space:]:\(] ]]; then
in_class=set
elif [[ $line =~ ^class[[:space:]] ]]; then
in_class=""
fi
if [[ $in_class && $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
COMPREPLY+=("${BASH_REMATCH[2]}")
fi
done 2>/dev/null <"$file"
((!${#COMPREPLY[@]})) ||
_comp_compgen -c "${cur##*:?(:)}" -- -P "$file::$class::" \
-W '"${COMPREPLY[@]}"'
_comp_ltrim_colon_completions "$cur"
return
elif [[ $cur == *.py:* ]]; then
local file="${cur/.py:*/.py}" line
while IFS= read -r line; do
if [[ $line =~ ^class[[:space:]]+(Test[A-Za-z0-9_]+) ]]; then
COMPREPLY+=("${BASH_REMATCH[1]}")
elif [[ $line =~ ^(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
COMPREPLY+=("${BASH_REMATCH[2]}")
fi
done 2>/dev/null <"$file"
((!${#COMPREPLY[@]})) ||
_comp_compgen -c "${cur##*.py:?(:)}" -- -P "$file::" \
-W '"${COMPREPLY[@]}"'
_comp_ltrim_colon_completions "$cur"
return
fi
_comp_compgen_filedir py
} &&
complete -F _comp_cmd_pytest \
pytest pytest-2 pytest-3 py.test py.test-2 py.test-3
# ex: filetype=sh
|