From 673e4e1d768c132c8cebc06044d08f87329ee159 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 3169137c..1b35479a 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']['family'] == 'RedHat' { + # Main python package bundle venv on some operating systems + unless $facts['os']['family'] in ['Archlinux', 'RedHat', 'FreeBSD'] { package { 'python-venv': ensure => $python::venv, name => "${python::install::python}-venv", diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 5bfc2103..4e0a91d5 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -38,6 +38,7 @@ Optional[Stdlib::Absolutepath] $python_path = undef, ) { 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..554559b5 --- /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 RedHat FreeBSD].include?(facts[:os]['family']) + 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 RedHat FreeBSD].include?(facts[:os]['family']) + 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 54c47fc7..dcebdc89 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 RedHat].include?(facts[:os]['family']) - it { is_expected.not_to contain_package('python-venv') } + if %w[Archlinux].include?(facts[:os]['family']) + 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]['family'] == 'RedHat' end case facts[:os]['family']