summaryrefslogtreecommitdiffstats
path: root/completions/pytest
diff options
context:
space:
mode:
Diffstat (limited to 'completions/pytest')
-rw-r--r--completions/pytest102
1 files changed, 56 insertions, 46 deletions
diff --git a/completions/pytest b/completions/pytest
index 7457a84..9ed2575 100644
--- a/completions/pytest
+++ b/completions/pytest
@@ -1,134 +1,144 @@
# bash completion for pytest(1) -*- shell-script -*-
-_pytest()
+_comp_cmd_pytest__option_choice_args()
{
- local cur prev words cword split
- _init_completion -s -n : || return
+ 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 | -!(-*)[hkmorp])
+ --help | --maxfail | --report | --junit-prefix | --doctest-glob | \
+ -${noargopts}[hkmorp])
return
;;
--import-mode)
- COMPREPLY=($(compgen -W "prepend append" -- "$cur"))
+ _comp_compgen -- -W "prepend append importlib"
return
;;
--capture)
- COMPREPLY=($(compgen -W "fd sys no tee-sys" -- "$cur"))
+ _comp_compgen -- -W "fd sys no tee-sys"
return
;;
--lfnf | --last-failed-no-failures)
- COMPREPLY=($(compgen -W "all none" -- "$cur"))
+ _comp_compgen -- -W "all none"
return
;;
--tb)
- COMPREPLY=($(compgen -W "auto long short line native no" \
- -- "$cur"))
+ _comp_compgen -- -W 'auto long short line native no'
return
;;
--show-capture)
- COMPREPLY=($(compgen -W "no stdout stderr log all" -- "$cur"))
+ _comp_compgen -- -W "no stdout stderr log all"
return
;;
--color)
- COMPREPLY=($(compgen -W "yes no auto" -- "$cur"))
+ _comp_compgen -- -W "yes no auto"
return
;;
--pastebin)
- COMPREPLY=($(compgen -W "failed all" -- "$cur"))
+ _comp_compgen -- -W "failed all"
return
;;
--junit-xml)
- _filedir xml
+ _comp_compgen_filedir xml
return
;;
--result-log | --log-file)
- _filedir log
+ _comp_compgen_filedir log
return
;;
- --ignore)
- _filedir
+ --ignore | -${noargopts}c)
+ _comp_compgen_filedir
return
;;
--confcutdir | --basetemp | --rsyncdir | --rootdir)
- _filedir -d
+ _comp_compgen_filedir -d
return
;;
--doctest-report)
- COMPREPLY=($(compgen -W "none cdiff ndiff udiff only_first_failure" -- "$cur"))
+ _comp_compgen -- -W 'none cdiff ndiff udiff only_first_failure'
return
;;
--assert)
- COMPREPLY=($(compgen -W "plain reinterp rewrite" -- "$cur"))
+ _comp_compgen -- -W "plain reinterp rewrite"
return
;;
--genscript)
- _filedir py
+ _comp_compgen_filedir py
return
;;
- --pythonwarnings | -!(-*)W)
- _xfunc python _python_warning_actions
+ --pythonwarnings | -${noargopts}W)
+ _comp_compgen -x python warning_actions
return
;;
- --numprocesses | -!(-*)n)
- COMPREPLY=($(compgen -W "{1..$(_ncpus)} auto" -- "$cur"))
+ --numprocesses | -${noargopts}n)
+ local REPLY
+ _comp_get_ncpus
+ _comp_compgen -- -W "{1..$REPLY} auto"
return
;;
- --dist)
- local modes=$("$1" --dist=nonexistent-distmode 2>&1 |
- command sed -e 's/[^[:space:][:alnum:]-]\{1,\}//g' \
- -ne 's/.*choose from //p')
- COMPREPLY=($(compgen -W '$modes' -- "$cur"))
+ --dist | --vcr-record?(-mode))
+ _comp_cmd_pytest__option_choice_args "$1" "$prev"
return
;;
esac
- $split && return
+ [[ $was_split ]] && return
if [[ $cur == -* ]]; then
- COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
+ _comp_compgen_help
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
if [[ $cur == *.py::*:* ]]; then
local file=${cur/.py:*/.py}
- local class=${cur#*.py::} in_class=false
+ 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=true
+ in_class=set
elif [[ $line =~ ^class[[:space:]] ]]; then
- in_class=false
+ in_class=""
fi
- if $in_class && [[ $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
- COMPREPLY+=(${BASH_REMATCH[2]})
+ 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[@]})) ||
- COMPREPLY=($(compgen -P "$file::$class::" -W '${COMPREPLY[@]}' \
- -- "${cur##*:?(:)}"))
- __ltrim_colon_completions "$cur"
+ _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]})
+ COMPREPLY+=("${BASH_REMATCH[1]}")
elif [[ $line =~ ^(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
- COMPREPLY+=(${BASH_REMATCH[2]})
+ COMPREPLY+=("${BASH_REMATCH[2]}")
fi
done 2>/dev/null <"$file"
((!${#COMPREPLY[@]})) ||
- COMPREPLY=($(compgen -P "$file::" -W '${COMPREPLY[@]}' \
- -- "${cur##*.py:?(:)}"))
- __ltrim_colon_completions "$cur"
+ _comp_compgen -c "${cur##*.py:?(:)}" -- -P "$file::" \
+ -W '"${COMPREPLY[@]}"'
+ _comp_ltrim_colon_completions "$cur"
return
fi
- _filedir py
+ _comp_compgen_filedir py
} &&
- complete -F _pytest pytest pytest-2 pytest-3 py.test py.test-2 py.test-3
+ complete -F _comp_cmd_pytest \
+ pytest pytest-2 pytest-3 py.test py.test-2 py.test-3
# ex: filetype=sh