Skip to content

Instantly share code, notes, and snippets.

@Dimfred
Created April 19, 2022 12:28
Show Gist options
  • Save Dimfred/f4e34eaf990b51a5e3511b9133449688 to your computer and use it in GitHub Desktop.
Save Dimfred/f4e34eaf990b51a5e3511b9133449688 to your computer and use it in GitHub Desktop.
fzfpytest
#!/usr/bin/env sh
parse() {
code='\
import re
import sys
files = sys.argv[1:]
tests = []
for file in files:
with open(file, "r") as f:
lines = f.readlines()
lines = [
re.sub("(class |def |:|\\(.*)", "", line).rstrip()
for line in lines if "class" in line or "def" in line
]
module_ = file
tests.append(module_)
for line in lines:
# class
if line.startswith("T"):
class_ = line
tests.append(f"{module_}::{class_}")
# class function
elif line.startswith(" "):
function_ = line.strip()
tests.append(f"{module_}::{class_}::{function_}")
# module function
elif line.startswith("t"):
function_ = line
tests.append(f"{module_}::{function_}")
print(" ".join(tests))
'
python3 -c "$code" $@
}
gather() {
res=$(ls tests/ | egrep test_.*.py)
modules=""
for module in $res; do
modules+="tests/$module "
done
echo "$modules"
}
main() {
res="$(gather)"
res=$(parse $res)
res=$(echo "$res" | sed -e 's/ /\n/g' | fzf)
if [ -z "$res" ]; then
return
fi
xdotool type "pt -s $res"
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment