-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathtest-stubgenc.sh
executable file
·45 lines (35 loc) · 1.22 KB
/
test-stubgenc.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
#!/bin/bash
set -e
set -x
cd "$(dirname "$0")/.."
# Install dependencies, demo project and mypy
python -m pip install -r test-requirements.txt
python -m pip install ./test-data/pybind11_fixtures
python -m pip install .
EXIT=0
# performs the stubgenc test
# first argument is the test result folder
# everything else is passed to stubgen as its arguments
function stubgenc_test() {
# Remove expected stubs and generate new inplace
STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_fixtures/$1
rm -rf "${STUBGEN_OUTPUT_FOLDER:?}"
stubgen -o "$STUBGEN_OUTPUT_FOLDER" "${@:2}"
# Check if generated stubs can actually be type checked by mypy
if ! mypy "$STUBGEN_OUTPUT_FOLDER";
then
echo "Stubgen test failed, because generated stubs failed to type check."
EXIT=1
fi
# Compare generated stubs to expected ones
if ! git diff --exit-code "$STUBGEN_OUTPUT_FOLDER";
then
echo "Stubgen test failed, because generated stubs differ from expected outputs."
EXIT=1
fi
}
# create stubs without docstrings
stubgenc_test expected_stubs_no_docs -p pybind11_fixtures
# create stubs with docstrings
stubgenc_test expected_stubs_with_docs -p pybind11_fixtures --include-docstrings
exit $EXIT