Skip to content

Commit fe02203

Browse files
committed
Change resolution order of python2_version to use python first
1 parent 2d7829d commit fe02203

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lib/facter/python_version.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ def get_python_version(executable)
1414

1515
Facter.add("python2_version") do
1616
setcode do
17-
python2_version = get_python_version 'python2'
18-
if python2_version.nil?
19-
default_version = get_python_version 'python'
20-
if !default_version.nil? and default_version.start_with?('2')
21-
python2_version = default_version
22-
end
17+
default_version = get_python_version 'python'
18+
if default_version.nil? or !default_version.start_with?('2')
19+
get_python_version 'python2'
20+
else
21+
default_version
2322
end
24-
python2_version
2523
end
2624
end
2725

spec/unit/facter/python_version_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,32 @@
3535
end
3636

3737
describe "python2_version" do
38-
context 'returns Python 2 version when `python2` is present' do
38+
context 'returns Python 2 version when `python` is present and Python 2' do
3939
it do
4040
Facter::Util::Resolution.stubs(:exec)
41-
Facter::Util::Resolution.expects(:which).with("python2").returns(true)
42-
Facter::Util::Resolution.expects(:exec).with("python2 -V 2>&1").returns(python2_version_output)
41+
Facter::Util::Resolution.expects(:which).with("python").returns(true)
42+
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
4343
Facter.value(:python2_version).should == '2.7.9'
4444
end
4545
end
4646

47-
context 'returns Python 2 version when `python2` is absent and `python` is Python 2' do
47+
context 'returns Python 2 version when `python` is Python 3 and `python2` is present' do
4848
it do
4949
Facter::Util::Resolution.stubs(:exec)
50-
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
5150
Facter::Util::Resolution.expects(:which).with("python").returns(true)
52-
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
51+
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
52+
Facter::Util::Resolution.expects(:which).with("python2").returns(true)
53+
Facter::Util::Resolution.expects(:exec).with("python2 -V 2>&1").returns(python2_version_output)
5354
Facter.value(:python2_version).should == '2.7.9'
5455
end
5556
end
5657

57-
context 'returns nil when `python2` is absent and `python` is Python 3' do
58+
context 'returns nil when `python` is Python 3 and `python2` is absent' do
5859
it do
5960
Facter::Util::Resolution.stubs(:exec)
60-
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
6161
Facter::Util::Resolution.expects(:which).with("python").returns(true)
6262
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
63+
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
6364
Facter.value(:python2_version).should == nil
6465
end
6566
end

0 commit comments

Comments
 (0)