Created
May 21, 2021 10:33
-
-
Save konstruktoid/f405a04d6eb3a73917050d742f90f1e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TESTFILE="$1" | |
ASSERTRESULT="0" | |
if [[ -z "${TESTFILE}" ]]; then | |
echo "Please specify a testfile." | |
exit 1 | |
fi | |
if ! file "${TESTFILE}" | grep -q "Python script text"; then | |
echo "${TESTFILE} doesn't seem to be a Python file." | |
exit 1 | |
fi | |
if ! grep -qo ".*\ = '''" "${TESTFILE}" || ! grep -qo "(AnsibleLintRule)" "${TESTFILE}"; then | |
echo "${TESTFILE} doesn't seem to contain any tests." | |
exit 1 | |
fi | |
RULENAME="$(grep -o '\s.*(AnsibleLintRule)' "${TESTFILE}" | sed -e 's/(AnsibleLintRule)//g' -e 's/ //g' )" | |
grep -o ".*\ = '''" "${TESTFILE}" | sed 's/ =.*//g' | while read -r testinfo; do | |
if echo "${testinfo}" | grep -q '^FAIL'; then | |
ASSERTRESULT=1 | |
fi | |
echo " | |
@pytest.mark.parametrize( | |
'rule_runner', (${RULENAME},), indirect=['rule_runner'] | |
) | |
def test_${testinfo,,}(rule_runner: Any) -> None: | |
\"\"\"This Docstring should be updated.\"\"\" | |
results = rule_runner.run_playbook(${testinfo}) | |
assert len(results) == ${ASSERTRESULT}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment