Skip to content

Commit 1953a2b

Browse files
committed
Fixed and improved install tests
Details: * Fixed pywbemtools install tests to perform the import test in a directory where it does not import from the repo main directory. * Removed the temporary disablement of the install tests that was put in place during development of pywbem 1.2.0. Signed-off-by: Andreas Maier <[email protected]>
1 parent 7d88668 commit 1953a2b

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

docs/changes.rst

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Released: not yet
7272

7373
* Test: Fixed invocation of pipdeptree in test workflow to use python -m.
7474

75+
* Fixed pywbemtools install tests to perform the import test in a directory
76+
where it does not import from the repo main directory. Removed the temporary
77+
disablement of the install tests that was put in place during development of
78+
pywbem 1.2.0.
79+
7580
**Enhancements:**
7681

7782
* Added support for Python 3.12.

tests/install/test_install.sh

+58-42
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ VERBOSE="true"
3434
# Indicates that pywbem is installed from a repository. This will disable
3535
# some install tests because they don't support this. Keep in sync with
3636
# the installation of pywbem from repo vs package in requirements.txt.
37-
# TODO: Set to false once pywbem 1.2.0 is released.
38-
PYWBEM_FROM_REPO="true"
37+
PYWBEM_FROM_REPO="false"
3938

4039
MYNAME=$(basename "$0")
41-
MYDIR=$(dirname "$0") # Directory of this script, as seen by caller
40+
MYDIR=$(abspath $(dirname "$0")) # Absolute path of directory of this script
4241

4342
# Repo root dir, as seen by caller
4443
# Using MYDIR makes the script run with any caller's CWD.
@@ -106,6 +105,15 @@ function verbose()
106105
fi
107106
}
108107

108+
function heading()
109+
{
110+
local msg
111+
msg="$1"
112+
echo ""
113+
echo -e "${green}${msg}${endcolor}"
114+
echo ""
115+
}
116+
109117
function info()
110118
{
111119
local msg
@@ -192,11 +200,6 @@ function make_virtualenv()
192200
run "pip install pip $PIP_OPTS" "Reinstalling pip with PACKAGE_LEVEL=$PACKAGE_LEVEL"
193201
run "pip install setuptools $PIP_OPTS" "Reinstalling setuptools with PACKAGE_LEVEL=$PACKAGE_LEVEL"
194202
run "pip install wheel $PIP_OPTS" "Reinstalling wheel with PACKAGE_LEVEL=$PACKAGE_LEVEL"
195-
196-
verbose "Virtualenv before actual install test:"
197-
verbose "Pip version: $(pip --version 2>&1)"
198-
verbose "Packages:"
199-
pip list --format=columns 2>/dev/null || pip list 2>/dev/null
200203
}
201204

202205
function remove_virtualenv()
@@ -220,6 +223,15 @@ function remove_virtualenv()
220223
fi
221224
}
222225

226+
function list_virtualenv()
227+
{
228+
local dir msg
229+
dir="$1"
230+
msg="$2"
231+
echo "$msg"
232+
sh -c "cd $dir; pip list --format=columns || pip list"
233+
}
234+
223235
function assert_eq()
224236
{
225237
local v1 v2
@@ -245,11 +257,12 @@ function run()
245257
verbose "$msg"
246258
fi
247259
if [[ "$DEBUG" == "true" ]]; then
248-
echo "Debug: running in this shell: $cmd"
260+
echo "Debug: Command: $cmd"
249261
eval "$cmd"
250262
rc=$?
251-
echo "Debug: command returns: rc=$rc"
263+
echo "Debug: Command returns: rc=$rc"
252264
else
265+
verbose "Command: $cmd"
253266
eval "$cmd" >$CMD_LOG_FILE 2>&1
254267
rc=$?
255268
fi
@@ -270,11 +283,12 @@ function call()
270283
verbose "$msg"
271284
fi
272285
if [[ "$DEBUG" == "true" ]]; then
273-
echo "Debug: running in sub-shell: $cmd"
286+
echo "Debug: Command (in subshell): $cmd"
274287
sh -c "$cmd"
275288
rc=$?
289+
echo "Debug: Command returns: rc=$rc"
276290
else
277-
verbose "$cmd"
291+
verbose "Command (in subshell): $cmd"
278292
sh -c "$cmd" >$CMD_LOG_FILE 2>&1
279293
rc=$?
280294
fi
@@ -292,11 +306,12 @@ function assert_run_ok()
292306
cmd="$1"
293307
msg="$2"
294308
if [[ "$DEBUG" == "true" ]]; then
295-
echo "Debug: running in this shell: $cmd"
309+
echo "Debug: Command: $cmd"
296310
eval "$cmd"
297311
rc=$?
312+
echo "Debug: Command returns: rc=$rc"
298313
else
299-
verbose "$cmd"
314+
verbose "Command: $cmd"
300315
eval "$cmd" >$CMD_LOG_FILE 2>&1
301316
rc=$?
302317
fi
@@ -317,10 +332,12 @@ function assert_run_fails()
317332
cmd="$1"
318333
msg="$2"
319334
if [[ "$DEBUG" == "true" ]]; then
320-
echo "Debug: running in this shell: $cmd"
335+
echo "Debug: Command: $cmd"
321336
eval "$cmd"
322337
rc=$?
338+
echo "Debug: Command returns: rc=$rc"
323339
else
340+
verbose "Command: $cmd"
324341
eval "$cmd" >$CMD_LOG_FILE 2>&1
325342
rc=$?
326343
fi
@@ -341,32 +358,34 @@ function ensure_uninstalled()
341358
pkg="$1"
342359
cmd="pip uninstall -y -q $pkg"
343360
if [[ "$DEBUG" == "true" ]]; then
344-
echo "Debug: running: $cmd"
361+
echo "Debug: Command: $cmd"
345362
fi
346363
eval $cmd >/dev/null 2>/dev/null
347364
}
348365

349366
function assert_import_ok()
350367
{
351-
local module
368+
local module dir
352369
module="$1"
353-
verbose "Checking for successful import of module: $module"
354-
assert_run_ok "python -c \"import ${module}\"" "Python module '${module}' cannot be imported"
370+
dir="$2"
371+
verbose "Checking for successful import of module $module in directory $dir"
372+
assert_run_ok "cd ${dir}; python -c \"import ${module}\"" "Python module '${module}' cannot be imported in directory $dir"
355373
}
356374

357375
function assert_import_fails()
358376
{
359-
local module
377+
local module dir
360378
module="$1"
361-
verbose "Checking for failing import of module: $module"
362-
assert_run_fails "python -c \"import ${module}\"" "Python module '${module}' can be imported but should have failed"
379+
dir="$2"
380+
verbose "Checking for failing import of module $module in directory $dir"
381+
assert_run_fails "cd ${dir}; python -c \"import ${module}\"" "Python module '${module}' can be imported in directory $dir but should have failed"
363382
}
364383

365384
#-------------------------------------------------
366385

367386
function prep()
368387
{
369-
info "Preparing for the tests"
388+
heading "Preparing for the tests"
370389

371390
if [[ -d $TMP_TEST_DIR ]]; then
372391
echo "Removing test directory: $TMP_TEST_DIR"
@@ -388,7 +407,7 @@ function prep()
388407

389408
function cleanup()
390409
{
391-
info "Cleaning up from the tests"
410+
heading "Cleaning up from the tests"
392411

393412
if [[ "$DEBUG" == "true" ]]; then
394413
echo "Debug: Not removing $TMP_TEST_DIR for debug inspection"
@@ -414,16 +433,15 @@ function cleanup_egg_file()
414433
function test1()
415434
{
416435
testcase="test1"
417-
info "Testcase $testcase: Pip install from repo root directory: $ROOT_DIR"
436+
heading "Testcase $testcase: Pip install from repo root directory: $ROOT_DIR"
418437
make_virtualenv "$testcase"
438+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv before installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
419439

420440
if [[ "$PYWBEM_FROM_REPO" == "false" ]]; then
421441
call "cd $ROOT_DIR; pip install . $PIP_OPTS" "Installing with pip from repo root directory (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
422442

423-
verbose "Packages before running pywbemcli:"
424-
pip list --format=columns 2>/dev/null || pip list 2>/dev/null
425-
426-
assert_run_ok "pywbemcli --version"
443+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv after installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
444+
assert_run_ok "cd ${TMP_TEST_DIR}; pywbemcli --version"
427445
else
428446
warning "Skipping pywbemcli check because pywbem is installed from repo"
429447
fi
@@ -435,16 +453,15 @@ function test1()
435453
function test3()
436454
{
437455
testcase="test3"
438-
info "Testcase $testcase: Pip install from wheel distribution archive: $WHL_DISTFILE"
456+
heading "Testcase $testcase: Pip install from wheel distribution archive: $WHL_DISTFILE"
439457
make_virtualenv "$testcase"
458+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv before installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
440459

441460
if [[ "$PYWBEM_FROM_REPO" == "false" ]]; then
442461
call "cd $TMP_TEST_DIR; pip install $(abspath $WHL_DISTFILE) $PIP_OPTS" "Installing with pip from wheel distribution archive (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
443462

444-
verbose "Packages before running pywbemcli:"
445-
pip list --format=columns 2>/dev/null || pip list 2>/dev/null
446-
447-
assert_run_ok "pywbemcli --version"
463+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv after installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
464+
assert_run_ok "cd ${TMP_TEST_DIR}; pywbemcli --version"
448465
else
449466
warning "Skipping pywbemcli check because pywbem is installed from repo"
450467
fi
@@ -456,16 +473,15 @@ function test3()
456473
function test4()
457474
{
458475
testcase="test4"
459-
info "Testcase $testcase: Pip install from source distribution archive: $SRC_DISTFILE"
476+
heading "Testcase $testcase: Pip install from source distribution archive: $SRC_DISTFILE"
460477
make_virtualenv "$testcase"
478+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv before installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
461479

462480
if [[ "$PYWBEM_FROM_REPO" == "false" ]]; then
463481
call "cd $TMP_TEST_DIR; pip install $(abspath $SRC_DISTFILE) $PIP_OPTS" "Installing with pip from source distribution archive (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
464482

465-
verbose "Packages before running pywbemcli:"
466-
pip list --format=columns 2>/dev/null || pip list 2>/dev/null
467-
468-
assert_run_ok "pywbemcli --version"
483+
list_virtualenv "$TMP_TEST_DIR" "Python packages in virtualenv after installation (PACKAGE_LEVEL=$PACKAGE_LEVEL)"
484+
assert_run_ok "cd ${TMP_TEST_DIR}; pywbemcli --version"
469485
else
470486
warning "Skipping pywbemcli check because pywbem is installed from repo"
471487
fi
@@ -476,8 +492,8 @@ function test4()
476492

477493
#----- main
478494

479-
WHL_DISTFILE="$1" # absolute or relative to caller's cwd
480-
SRC_DISTFILE="$2" # absolute or relative to caller's cwd
495+
WHL_DISTFILE=$(abspath "$1") # absolute or relative to caller's cwd
496+
SRC_DISTFILE=$(abspath "$2") # absolute or relative to caller's cwd
481497
PYTHON_CMD="$3" # Python command to use (outside of the created virtualenvs)
482498

483499
if [[ -z $PYTHON_CMD ]]; then
@@ -505,4 +521,4 @@ test4
505521

506522
cleanup
507523

508-
info "All testcases succeeded."
524+
heading "All testcases succeeded."

0 commit comments

Comments
 (0)