-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate_python_unittests.sh
executable file
·79 lines (65 loc) · 1.58 KB
/
generate_python_unittests.sh
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
#!/bin/bash
#
# Finds Python project modules and creates an
# empty unittest skeleton pytest oriented.
#
# Author: luismartingil
# Year: 2015
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pname=myproject
sources_dir=../$pname/
tests_dir=../test
# Leave when anything goes wrong
set -e
qquit_msg ()
{
echo 'Error. '$1
exit 1
}
create_unittest_file() {
test=$1
package_name=$2
package_prefix=$3
package=$3.$2
echo 'Creating new unittest file "'$1'".'
cat > $1 <<EOF
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: Tests for \`$package\`.
.. moduleauthor:: Zaleos <developers@zaleos.net>
"""
import pytest
import $package
@pytest.mark.parametrize(
"input,expected", [
('TODO', 'TODO'),
]
)
def test_$package_name(input, expected):
"""Testing $module
"""
assert input != expected
EOF
echo 'Done.'
}
my_main ()
{
find $sources_dir -type f -name '*.py' -not -name '__init__.py' -printf '%P\0' |
while read -d $'\0' i; do
package_dirname=$(dirname $i | sed 's/'$pname'\///g' | sed 's/\//./g') ;
package_name_complete=$(basename $i)
package_name=${package_name_complete%.*}
package_prefix=$pname.$package_dirname
test_name='test_'$(echo $package_prefix | sed 's/\./_/g')'_'$package_name_complete
test=$tests_dir/$test_name
if [ -f "$test" ]; then
echo 'File "'$test_name'" exists. Not creating.';
else
echo 'File "'$test_name'" doesnt exist. Creating.';
# create_unittest_file $test $package_name $package_prefix
fi
done
cd $DIR
}
my_main