-
-
Notifications
You must be signed in to change notification settings - Fork 272
/
python_dir_spec.rb
48 lines (43 loc) · 1.96 KB
/
python_dir_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'spec_helper'
describe 'python_dir', type: :fact do
before { Facter.clear }
describe 'python dir' do
context 'default path' do
before do
# This is needed to make this spec work on Fedora, apparently
Facter.fact(:osfamily).stubs(:value).returns('AnythingNotRedHat')
Facter::Util::Resolution.stubs(:which).with('python').returns(true)
Facter::Util::Resolution.stubs(:exec).with('python -c "import site; print(site.getsitepackages()[0])"').returns('/usr/local/lib/python2.7/dist-packages')
end
it do
expect(Facter.value(:python_dir)).to eq('/usr/local/lib/python2.7/dist-packages')
end
end
context 'RedHat' do
before do
Facter.fact(:osfamily).stubs(:value).returns('RedHat')
Facter::Util::Resolution.stubs(:which).with('python').returns(true)
Facter::Util::Resolution.stubs(:exec).with('python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"').returns('/usr/lib/python2.7/site-packages')
end
it do
expect(Facter.value(:python_dir)).to eq('/usr/lib/python2.7/site-packages')
end
end
context 'RedHat versioned python' do
before do
Facter.fact(:osfamily).stubs(:value).returns('RedHat')
Facter::Util::Resolution.stubs(:which).with('python').returns(false)
Facter::Util::Resolution.stubs(:which).with('python3').returns(true)
Facter::Util::Resolution.stubs(:exec).with('python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"').returns('/usr/lib/python3.6/site-packages')
end
it do
expect(Facter.value(:python_dir)).to eq('/usr/lib/python3.6/site-packages')
end
end
end
it 'is empty string if python not installed' do
Facter::Util::Resolution.stubs(:which).with('python').returns(nil)
Facter::Util::Resolution.stubs(:which).with('python3').returns(nil)
expect(Facter.fact(:python_dir).value).to eq('')
end
end