From 3fa9f1ec62ab71ccba7d1e87028c2ecc25721c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 8 Oct 2023 17:05:57 -1000 Subject: [PATCH] WIP venv testing --- manifests/install/venv.pp | 6 ++--- manifests/pyvenv.pp | 1 + spec/classes/install/venv_spec.rb | 37 +++++++++++++++++++++++++++++++ spec/classes/python_spec.rb | 12 ++++------ 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 spec/classes/install/venv_spec.rb diff --git a/manifests/install/venv.pp b/manifests/install/venv.pp index 865d7cff..56df8c70 100644 --- a/manifests/install/venv.pp +++ b/manifests/install/venv.pp @@ -2,10 +2,8 @@ class python::install::venv { include python - ## - ## CentOS has no extra package for venv - ## - unless $facts['os']['name'] == 'CentOS' { + # Main python package bundle venv on some operating systems + unless $facts['os']['name'] in ['Archlinux', 'CentOS', 'FreeBSD'] { package { 'python-venv': ensure => $python::venv, name => "${python::install::python}-venv", diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 14dcb9fb..dafc66f0 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -36,6 +36,7 @@ Python::Venv::PipVersion $pip_version = 'latest', ) { include python + include python::install::venv if $ensure == 'present' { $python_version = $version ? { diff --git a/spec/classes/install/venv_spec.rb b/spec/classes/install/venv_spec.rb new file mode 100644 index 00000000..6e3561c4 --- /dev/null +++ b/spec/classes/install/venv_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'python::install::venv' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context 'with default settings' do + if %w[Archlinux CentOS FreeBSD].include?(facts[:os]['name']) + it { is_expected.not_to contain_package('python-venv') } + else + it { is_expected.to contain_package('python-venv').with(ensure: 'absent') } + end + end + + context 'when ensuring venv is setup' do + let(:pre_condition) do + <<~PP + class { 'python': + venv => present, + } + PP + end + + if %w[Archlinux CentOS FreeBSD].include?(facts[:os]['name']) + it { is_expected.not_to contain_package('python-venv') } + else + it { is_expected.to contain_package('python-venv').with(ensure: 'present') } + end + end + end + end +end diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index d3bde4a4..3e9c0d28 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -23,10 +23,10 @@ it { is_expected.to contain_package('pip') } end - if %w[Archlinux CentOS].include?(facts[:os]['name']) - it { is_expected.not_to contain_package('python-venv') } + if %w[Archlinux].include?(facts[:os]['name']) + it { is_expected.not_to contain_class('python::install::venv') } else - it { is_expected.to contain_package('python-venv') } + it { is_expected.to contain_class('python::install::venv') } end end @@ -44,23 +44,19 @@ it { is_expected.not_to contain_package('python') } it { is_expected.not_to contain_package('python-dev') } it { is_expected.not_to contain_package('pip') } - it { is_expected.not_to contain_package('python-venv') } + it { is_expected.not_to contain_class('python::install::venv') } end context 'with packages present' do let :params do { manage_pip_package: true, - manage_venv_package: true, pip: 'present', - venv: 'present' } end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('pip').with(ensure: 'present') } - - it { is_expected.to contain_package('python-venv').with(ensure: 'present') } unless facts[:os]['name'] == 'CentOS' end case facts[:os]['family']