Skip to content

Commit

Permalink
Add a new test to verify python311_virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepthiYV committed Jul 15, 2024
1 parent 7d7ff65 commit f154e67
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 11 deletions.
26 changes: 15 additions & 11 deletions schedule/functional/stack_tests_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,59 @@ schedule:
- installation/bootloader_start
- boot/boot_to_desktop
- '{{add_phub_extension}}'
- console/python_scientific
- '{{distri_version_specific}}'
- console/python_scientific
conditional_schedule:
distri_version_specific:
DISTRI:
sle:
- '{{version_specific}}'
opensuse:
- console/python3_new_version_check
- console/python3_setuptools
- console/python_virtualenv
- console/python3_beautifulsoup4
- console/python3_websocket_client
- console/python_flake8
- console/python_pycairo
- console/django
- '{{python_liblouis}}'
- console/rabbitmq
version_specific:
VERSION:
15-SP6:
- console/python3_new_version_check
- console/python3_setuptools
- console/python_virtualenv
- console/python3_beautifulsoup4
- console/python3_websocket_client
version_specific:
VERSION:
15-SP6:
- console/python_flake8
- console/python_pycairo
- console/django
- '{{python_liblouis}}'
- console/rabbitmq
15-SP5:
- console/python3_new_version_check
- console/python3_setuptools
- console/python_virtualenv
- console/python3_beautifulsoup4
- console/python3_websocket_client
15-SP5:
- console/python_flake8
- console/python_pycairo
- console/django
- '{{python_liblouis}}'
- console/rabbitmq
15-SP4:
- console/python3_new_version_check
- console/python3_setuptools
- console/python3_beautifulsoup4
- console/python_virtualenv
- console/python3_websocket_client
15-SP4:
- console/python3_beautifulsoup4
- console/python_flake8
- console/python_pycairo
- console/django
- '{{python_liblouis}}'
- console/rabbitmq
- console/python3_new_version_check
- console/python3_setuptools
- console/python3_beautifulsoup4
- console/python3_websocket_client
15-SP3:
- console/python_flake8
- console/django
Expand Down
5 changes: 5 additions & 0 deletions tests/console/python3_setuptools.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ sub run {
# Verify the system's python3 version
my $system_python_version = get_system_python_version();
record_info("System python version", "$system_python_version");
# In tumbleweed python3-setuptools is just a provides from python311-setuptools package
zypper_call("install $system_python_version-setuptools") if (is_tumbleweed);
# Import the project directory for creating a source distribution package.
# The directory should contain setup.py and a Python module named test_module.py
assert_script_run('curl -L -s ' . data_url('python/python3-setuptools') . ' | cpio --make-directories --extract && cd data');
Expand Down Expand Up @@ -97,6 +99,9 @@ sub cleanup {
# Deletion of work folders
assert_script_run("rm -rf dist user_package_setuptools.egg-info repo_webroot");
assert_script_run("deactivate"); # leave the virtual env
assert_script_run("cd ..");
script_run("rm -r data");

}

sub post_run_hook {
Expand Down
101 changes: 101 additions & 0 deletions tests/console/python_virtualenv.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# SUSE's openQA tests
#
# Copyright 2024 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Package: python3-virtualenv
# Summary: testsuite python3-virtualenv
# - Install python311-pipx and with pipx download the latest version of
# a package to a temporary virtual environment, then run the app from it
# - Activate virtual environment
# - Install build tools
# - Setup the package structure and
# - Build the local package and install it
# - Verify the installation
# - Deactivate the virtual environment
# Summary: testsuite python3-virtualenv
# Maintainer: QE Core <[email protected]>

use base "consoletest";
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use version_utils;
use python_version_utils;
use utils "zypper_call";
use feature qw(signatures);
no warnings qw(experimental::signatures);

sub run {
select_serial_terminal;
# Import the project directory for creating a source distribution package.
# The directory should contain setup.py and a Python module named test_module.py
assert_script_run('curl -L -s ' . data_url('python/python3-setuptools') . ' | cpio --make-directories --extract && cd data');
# Verify the system's python3 version
my $system_python_version = get_system_python_version();
record_info("System python version", "$system_python_version");
# Run the package creation and install test for system python
run_tests($system_python_version);
# Test all available new python3 versions in SLEs if any
if (is_sle() || is_leap('>15.5')) { run_tests($_) foreach (get_available_python_versions()); }
}

sub run_tests ($python3_spec_release) {
if ($python3_spec_release eq 'python39' && check_var('VERSION', '15-SP5')) {
# python39-pip not availbale on 15sp5 https://progress.opensuse.org/issues/159777
record_info("Skip python39", 'https://jira.suse.com/browse/PED-8196');
return;
}
record_info("$python3_spec_release");
# Install python311-virtualenv
if ((zypper_call("se -x $python3_spec_release-pipx", exitcode => [0, 104]) == 104) or (zypper_call("se -x $python3_spec_release-virtualenv", exitcode => [0, 104]) == 104)) {
record_info("Skip! either $python3_spec_release-pipx or $python3_spec_release-virtualenv doesn't exist");
return;
}
zypper_call("in $python3_spec_release-pipx $python3_spec_release-virtualenv");
# create a virtual environment named myenv using virtualenv with Python 3.11 and activate it
my $python_binary = get_python3_binary($python3_spec_release);
my $version_number = (split("python", $python_binary))[1];
assert_script_run("pipx run --python=$python_binary virtualenv myenv");
assert_script_run("source myenv/bin/activate");
# Install build tools and build, install the package locally
assert_script_run("pip$version_number install setuptools wheel");
assert_script_run("python$version_number setup.py sdist bdist_wheel");
validate_script_output("pip$version_number install dist/user_package_setuptools-1.0-py3-none-any.whl", sub { m/Successfully installed/ });
# Verify the installed package
validate_script_output("pip$version_number list", sub { m/user_package_setuptools/ });
assert_script_run("python$version_number sample_test_module/test_module.py");
uninstall_package($version_number);
assert_script_run("deactivate");
}

# Uninstall the installed user_package_setuptools and verify it.
sub uninstall_package ($version_number) {
assert_script_run("pip$version_number uninstall user_package_setuptools -y");
my $out = script_output "python$version_number sample_test_module/test_module.py", proceed_on_failure => 1;
die("pip uninstall failed for the package") if (index($out, "ModuleNotFoundError") == -1);
assert_script_run("rm -rf dist user_package_setuptools.egg-info");
}

sub cleanup {
if (is_sle()) {
foreach my $python_version (get_available_python_versions()) {
zypper_call("rm $python_version-base", exitcode => [0, 104]);
}
}
assert_script_run("cd ..");
script_run("rm -r data");
}

sub post_run_hook {
script_run("deactivate");
cleanup();
}

sub post_fail_hook {
script_run("deactivate");
cleanup();
}

1;

0 comments on commit f154e67

Please sign in to comment.