Skip to content

Commit

Permalink
WIP venv testing
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Oct 9, 2024
1 parent 0a0da14 commit 673e4e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
6 changes: 2 additions & 4 deletions manifests/install/venv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Optional[Stdlib::Absolutepath] $python_path = undef,
) {
include python
include python::install::venv

if $ensure == 'present' {
$python_version = $version ? {
Expand Down
37 changes: 37 additions & 0 deletions spec/classes/install/venv_spec.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 4 additions & 8 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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']
Expand Down

0 comments on commit 673e4e1

Please sign in to comment.