Skip to content

Commit bcd3ada

Browse files
Add linting & testing scripts
1 parent 2f00565 commit bcd3ada

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

scripts/lint

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
4+
#
5+
# NAVIGATE TO CORRECT DIRECTORY
6+
#
7+
8+
# start by going to script dir so all movements
9+
# from here are relative
10+
SCRIPT_DIR=`dirname $(realpath "$0")`
11+
cd $SCRIPT_DIR
12+
13+
# go to app dir
14+
cd ..
15+
16+
# enable app virtual environment
17+
eval "$(direnv export bash)"
18+
19+
#
20+
# RUN LINTERS
21+
#
22+
23+
function lint {
24+
echo ""
25+
echo "PYLINT"
26+
pylint db_wrapper/*
27+
lint_result=$?
28+
echo ""
29+
}
30+
31+
function code {
32+
echo ""
33+
echo "PYCODESTYLE"
34+
pycodestyle db_wrapper/*
35+
code_result=$?
36+
echo ""
37+
}
38+
39+
function doc {
40+
echo ""
41+
echo "PYDOCSTYLE"
42+
pydocstyle db_wrapper/*
43+
doc_result=$?
44+
echo ""
45+
}
46+
47+
lint
48+
if [ $lint_result != 0 ]; then
49+
echo "Error in pylint, see above."
50+
exit $lint_result
51+
fi
52+
53+
code
54+
if [ $code_result != 0 ]; then
55+
echo "Error in codestyle, see above."
56+
exit $code_result
57+
fi
58+
59+
doc
60+
if [ $doc_result != 0 ]; then
61+
echo "Error in docstyle, see above."
62+
exit $doc_result
63+
fi

scripts/test

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
4+
#
5+
# NAVIGATE TO CORRECT DIRECTORY
6+
#
7+
8+
# start by going to script dir so all movements
9+
# from here are relative
10+
SCRIPT_DIR=`dirname $(realpath "$0")`
11+
cd $SCRIPT_DIR
12+
13+
14+
#
15+
# RUN TESTS
16+
#
17+
18+
function unit {
19+
cd ..
20+
# enable app virtual environment
21+
eval "$(direnv export bash)"
22+
if [ !$PYTHONPATH ]; then
23+
export PYTHONPATH=$PWD
24+
fi
25+
echo ""
26+
27+
echo ""
28+
echo "Starting unit tests..."
29+
echo ""
30+
31+
# run unit tests & save exit code
32+
cd tests
33+
python -m unittest -b $@
34+
# save exit code from tests
35+
unit_result=$?
36+
37+
# return to scripts directory
38+
cd $SCRIPT_DIR
39+
echo ""
40+
}
41+
42+
function e2e {
43+
echo ""
44+
echo "Integration tests not implemented."
45+
echo ""
46+
e2e_result=0
47+
48+
# echo ""
49+
# echo "Starting integration tests..."
50+
# echo ""
51+
# # go to test app dir
52+
# cd ../integration_tests
53+
54+
# # enable app virtual environment
55+
# eval "$(direnv export bash)"
56+
# if [ !$PYTHONPATH ]; then
57+
# export PYTHONPATH=$PWD
58+
# fi
59+
# echo ""
60+
61+
# # run integration tests & save exit code
62+
# cd tests
63+
# python -m unittest -b $@
64+
# # save exit code from tests
65+
# e2e_result=$?
66+
67+
# # return to scripts directory
68+
# cd $SCRIPT_DIR
69+
# echo ""
70+
}
71+
72+
# Run unit tests or integration tests if one is specified
73+
# by passing unit, e2e, or integration as first argument to
74+
# this script, otherwise run both unit tests & integration
75+
# tests.
76+
# Additionally, arguments can be passed to pytest command
77+
# after specifying unit or integration, but no arguments can
78+
# be passed if unit or integration isn't specified.
79+
if [ $# -eq 0 ]; then
80+
unit
81+
e2e
82+
83+
if [[ $unit_result != 0 && $e2e_result != 0 ]]; then
84+
echo "Errors found in both unit & integration tests. See output above."
85+
exit $unit_result
86+
elif [[ $unit_result != 0 && $e2e_result == 0 ]]; then
87+
echo "Errors found in unit. See output above."
88+
exit $unit_result
89+
elif [[ $unit_result == 0 && $e2e_result != 0 ]]; then
90+
echo "Errors found in integration tests. See output above."
91+
exit $e2e_result
92+
else
93+
exit 0
94+
fi
95+
96+
elif [ $1 == 'unit' ]; then
97+
unit ${@:2}
98+
exit $unit_result
99+
elif [[ $1 == 'e2e' || $1 == 'integration' ]]; then
100+
e2e ${@:2}
101+
exit $e2e_result
102+
else
103+
echo "Bad argument given, either specify \`unit\` or \`integration\` tests by giving either word as your first argument to this script, or run both by giving no arguments."
104+
exit 1
105+
fi

0 commit comments

Comments
 (0)