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, 2023
1 parent 4aeedb4 commit 451d089
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']['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",
Expand Down
1 change: 1 addition & 0 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Python::Venv::PipVersion $pip_version = 'latest',
) {
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 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':

Check failure on line 23 in spec/classes/install/venv_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
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
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 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

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]['name'] == 'CentOS'
end

case facts[:os]['family']
Expand Down

0 comments on commit 451d089

Please sign in to comment.