Debian Codegraph @

tests/test_python_module.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 # Tests Python module functions and types.
3 #
4 # Version: 20240417
5
6 EXIT_SUCCESS=0;
7 EXIT_FAILURE=1;
8 EXIT_NO_TESTS_RAN=5;
9 EXIT_IGNORE=77;
10
11 TEST_FUNCTIONS="support";
12 TEST_FUNCTIONS_WITH_INPUT="file";
13 OPTION_SETS=();
14
15 TEST_TOOL_DIRECTORY=".";
16 INPUT_GLOB="*";
17
18 LIBRARY_NAME="libvhdi";
19 PYTHON_MODULE="pyvhdi";
20
21 test_python_function()
22 {
23 local TEST_FUNCTION=$1;
24
25 local TEST_DESCRIPTION="Testing Python-bindings functions: ${TEST_FUNCTION}";
26 local TEST_SCRIPT="${TEST_TOOL_DIRECTORY}/${PYTHON_MODULE}_test_${TEST_FUNCTION}.py";
27
28 run_test_with_arguments "${TEST_DESCRIPTION}" "${TEST_SCRIPT}";
29 local RESULT=$?;
30
31 return ${RESULT};
32 }
33
34 test_python_function_with_input()
35 {
36 local TEST_FUNCTION=$1;
37
38 local TEST_DESCRIPTION="Testing Python-bindings functions: ${TEST_FUNCTION}";
39 local TEST_SCRIPT="${TEST_TOOL_DIRECTORY}/${PYTHON_MODULE}_test_${TEST_FUNCTION}.py";
40
41 if ! test -d "input";
42 then
43 echo "Test input directory not found.";
44
45 return ${EXIT_IGNORE};
46 fi
47 local RESULT=`ls input/* | tr ' ' '\n' | wc -l`;
48
49 if test ${RESULT} -eq ${EXIT_SUCCESS};
50 then
51 echo "No files or directories found in the test input directory";
52
53 return ${EXIT_IGNORE};
54 fi
55
56 local TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "${PYTHON_MODULE}");
57
58 local IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}");
59
60 RESULT=${EXIT_SUCCESS};
61
62 for TEST_SET_INPUT_DIRECTORY in input/*;
63 do
64 if ! test -d "${TEST_SET_INPUT_DIRECTORY}";
65 then
66 continue;
67 fi
68 if check_for_directory_in_ignore_list "${TEST_SET_INPUT_DIRECTORY}" "${IGNORE_LIST}";
69 then
70 continue;
71 fi
72
73 local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");
74
75 if test -f "${TEST_SET_DIRECTORY}/files";
76 then
77 IFS="" read -a INPUT_FILES <<< $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?");
78 else
79 IFS="" read -a INPUT_FILES <<< $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB});
80 fi
81 for INPUT_FILE in "${INPUT_FILES[@]}";
82 do
83 local TESTED_WITH_OPTIONS=0;
84
85 for OPTION_SET in ${OPTION_SETS[@]};
86 do
87 local TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");
88
89 if test -f ${TEST_DATA_OPTION_FILE};
90 then
91 TESTED_WITH_OPTIONS=1;
92
93 IFS=" " read -a OPTIONS <<< $(read_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");
94
95 run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SET}" "${TEST_SCRIPT}" "${INPUT_FILE}" "${OPTIONS[@]}";
96 RESULT=$?;
97
98 if test ${RESULT} -ne ${EXIT_SUCCESS};
99 then
100 break;
101 fi
102 fi
103 done
104
105 if test ${TESTED_WITH_OPTIONS} -eq 0;
106 then
107 run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "" "${TEST_SCRIPT}" "${INPUT_FILE}";
108 RESULT=$?;
109 fi
110
111 if test ${RESULT} -ne ${EXIT_SUCCESS};
112 then
113 break;
114 fi
115 done
116
117 if test ${RESULT} -ne ${EXIT_SUCCESS};
118 then
119 break;
120 fi
121 done
122
123 return ${RESULT};
124 }
125
126 if test -n "${SKIP_PYTHON_TESTS}";
127 then
128 exit ${EXIT_IGNORE};
129 fi
130
131 TEST_DIRECTORY=`dirname $0`;
132
133 TEST_RUNNER="${TEST_DIRECTORY}/test_runner.sh";
134
135 if ! test -f "${TEST_RUNNER}";
136 then
137 echo "Missing test runner: ${TEST_RUNNER}";
138
139 exit ${EXIT_FAILURE};
140 fi
141
142 source ${TEST_RUNNER};
143
144 PLATFORM=`uname -s | sed 's/-.*$//'`;
145
146 if test "${PLATFORM}" = "MINGW64_NT" || test "${PLATFORM}" = "MSYS_NT";
147 then
148 cp ../${LIBRARY_NAME}/.libs/*.dll ../${PYTHON_MODULE}/.libs/;
149 cp ../${PYTHON_MODULE}/.libs/${PYTHON_MODULE}.dll ../${PYTHON_MODULE}/.libs/${PYTHON_MODULE}.pyd;
150 fi
151
152 RESULT=${EXIT_IGNORE};
153
154 for TEST_FUNCTION in ${TEST_FUNCTIONS};
155 do
156 test_python_function "${TEST_FUNCTION}";
157 RESULT=$?;
158
159 if test ${RESULT} -eq ${EXIT_NO_TESTS_RAN};
160 then
161 RESULT=${EXIT_IGNORE};
162 fi
163 if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE};
164 then
165 break;
166 fi
167 done
168
169 if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE};
170 then
171 exit ${RESULT};
172 fi
173
174 for TEST_FUNCTION in ${TEST_FUNCTIONS_WITH_INPUT};
175 do
176 if test -d "input";
177 then
178 test_python_function_with_input "${TEST_FUNCTION}";
179 RESULT=$?;
180 else
181 test_python_function "${TEST_FUNCTION}";
182 RESULT=$?;
183 fi
184 if test ${RESULT} -eq ${EXIT_NO_TESTS_RAN};
185 then
186 RESULT=${EXIT_IGNORE};
187 fi
188 if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE};
189 then
190 break;
191 fi
192 done
193
194 exit ${RESULT};
195