summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-08-26 17:08:01 -0700
committerlamont-granquist <lamont@scriptkiddie.org>2014-08-26 17:08:01 -0700
commita44e979aea238939e9f260696ee34e471eb3d0cc (patch)
tree98baf66505585bf9a828eb4fc2e85c0feec6a6d2
parent4ead24370ca723be41f9ee58054b9b00f01e51aa (diff)
parentac78e9a1475ef143aa343991252cc715ceb47c0f (diff)
downloadohai-a44e979aea238939e9f260696ee34e471eb3d0cc.tar.gz
Merge pull request #322 from opscode/lcg/python-parens
Encapsulate print command in function
-rw-r--r--lib/ohai/plugins/python.rb6
-rw-r--r--spec/unit/plugins/python_spec.rb42
2 files changed, 25 insertions, 23 deletions
diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb
index 683042ba..c6c4dfc8 100644
--- a/lib/ohai/plugins/python.rb
+++ b/lib/ohai/plugins/python.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,7 @@ Ohai.plugin(:Python) do
python = Mash.new
- so = shell_out("python -c \"import sys; print sys.version\"")
+ so = shell_out("python -c \"import sys; print (sys.version)\"")
if so.exitstatus == 0
output = so.stdout.split
diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb
index 85892fc2..2d4d90a1 100644
--- a/spec/unit/plugins/python_spec.rb
+++ b/spec/unit/plugins/python_spec.rb
@@ -7,9 +7,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,33 +17,35 @@
# limitations under the License.
#
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin python" do
+ let(:stdout) { "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n" }
+
+ let(:retval) { 0 }
- before(:each) do
- @plugin = get_plugin("python")
- @plugin[:languages] = Mash.new
- @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
- @plugin.stub(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, ""))
+ let(:plugin) do
+ plugin = get_plugin("python")
+ plugin[:languages] = Mash.new
+ expect(plugin).to receive(:shell_out).with("python -c \"import sys; print (sys.version)\"").and_return(mock_shell_out(retval, stdout, ""))
+ plugin
end
-
+
it "should get the python version from printing sys.version and sys.platform" do
- @plugin.should_receive(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, ""))
- @plugin.run
+ plugin.run
end
it "should set languages[:python][:version]" do
- @plugin.run
- @plugin.languages[:python][:version].should eql("2.5.2")
- end
-
- it "should not set the languages[:python] tree up if python command fails" do
- @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
- @plugin.stub(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(1, @stdout, ""))
- @plugin.run
- @plugin.languages.should_not have_key(:python)
+ plugin.run
+ expect(plugin.languages[:python][:version]).to eql("2.5.2")
end
+ context "when the python command fails" do
+ let(:retval) { 1 }
+
+ it "should not set the languages[:python] tree up" do
+ plugin.run
+ expect(plugin.languages).not_to have_key(:python)
+ end
+ end
end