File tree Expand file tree Collapse file tree
test/cookbooks/python_test
files/default/tests/minitest Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,20 +35,23 @@ platforms:
3535suites :
3636- name : default
3737 run_list :
38+ - recipe[minitest-handler]
3839 - recipe[python]
40+ - recipe[python_test::cook-3084]
3941 attributes : {}
4042
4143- name : source
4244 run_list :
45+ - recipe[minitest-handler]
4346 - recipe[python]
47+ - recipe[python_test::cook-3084]
4448 attributes : {python: {install_method: "source"}}
4549- name : exert
4650 excludes : ["centos-5.9"]
4751 run_list :
4852 - recipe[python]
4953 - recipe[python_test::test_exert]
5054- name : virtualenv
51- excludes : ["centos-5.9"]
5255 run_list :
5356 - recipe[python]
5457 - recipe[python_test::test_virtualenv]
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ site :opscode
33metadata
44
55group :integration do
6+ cookbook "minitest-handler"
67 cookbook "apt"
78 cookbook "yum"
89 cookbook "build-essential"
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ Install packages using the new hotness in Python package management...[`pip`](ht
9595# Attribute Parameters
9696
9797- path: name attribute. The path where the virtualenv will be created
98- - interpreter: The Python interpreter to use. default is ` python2.6 `
98+ - interpreter: The Python interpreter to use. default is null (i.e. use whatever python the virtualenv command is using).
9999- owner: The owner for the virtualenv
100100- group: The group owner of the file (string or id)
101101- options : Command line options (string)
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ def whyrun_supported?
2929action :create do
3030 unless exists?
3131 Chef ::Log . info ( "Creating virtualenv #{ new_resource } at #{ new_resource . path } " )
32- execute "#{ virtualenv_cmd } --python=#{ new_resource . interpreter } #{ new_resource . options } #{ new_resource . path } " do
32+ interpreter = new_resource . interpreter ? " --python=#{ new_resource . interpreter } " : ""
33+ execute "#{ virtualenv_cmd } #{ interpreter } #{ new_resource . options } #{ new_resource . path } " do
3334 user new_resource . owner if new_resource . owner
3435 group new_resource . group if new_resource . group
3536 end
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ def initialize(*args)
2828end
2929
3030attribute :path , :kind_of => String , :name_attribute => true
31- attribute :interpreter , :default => 'python'
31+ attribute :interpreter , :kind_of => String
3232attribute :owner , :regex => Chef ::Config [ :user_valid_regex ]
3333attribute :group , :regex => Chef ::Config [ :group_valid_regex ]
3434attribute :options , :kind_of => String
Original file line number Diff line number Diff line change 1+ require 'minitest/spec'
2+
3+ describe_recipe 'python_test::cook-3084' do
4+ include MiniTest ::Chef ::Assertions
5+ include MiniTest ::Chef ::Context
6+ include MiniTest ::Chef ::Resources
7+
8+ it "created a virtualenv in cook-3084" do
9+ result = assert_sh ( "cook-3084/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'" )
10+ assert_match /cook-3084\n / , result
11+ end
12+
13+ it "created a virtualenv in cook-3084-interpreter" do
14+ result = assert_sh ( "cook-3084-interpreter/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'" )
15+ assert_match /cook-3084-interpreter\n / , result
16+ end
17+ end
Original file line number Diff line number Diff line change 1+ #
2+ # Author:: Alex Kiernan (<[email protected] >) 3+ # Cookbook Name:: python
4+ # Recipe:: cook-3084
5+ #
6+ # Copyright 2013, Alex Kiernan
7+ #
8+ # Licensed under the Apache License, Version 2.0 (the "License");
9+ # you may not use this file except in compliance with the License.
10+ # You may obtain a copy of the License at
11+ #
12+ # http://www.apache.org/licenses/LICENSE-2.0
13+ #
14+ # Unless required by applicable law or agreed to in writing, software
15+ # distributed under the License is distributed on an "AS IS" BASIS,
16+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+ # See the License for the specific language governing permissions and
18+ # limitations under the License.
19+ #
20+
21+ include_recipe "python"
22+
23+ python_virtualenv "cook-3084" do
24+ end
25+
26+ python_virtualenv "cook-3084-interpreter" do
27+ # on EL5 the default python we install is called python26
28+ if !node [ 'python' ] [ 'install_method' ] . eql? ( "source" ) &&
29+ platform_family? ( 'rhel' ) &&
30+ node [ 'platform_version' ] . split ( '.' ) . first . to_i < 6
31+ interpreter '/usr/bin/python26'
32+ else
33+ interpreter 'python'
34+ end
35+ end
Original file line number Diff line number Diff line change 1919#
2020
2121python_virtualenv "/tmp/virtualenv" do
22- interpreter "python"
2322 owner "root"
2423 group "root"
2524 action :create
2625end
2726
2827python_virtualenv "isolated python environment" do
2928 path "/tmp/tobedestroyed"
30- interpreter "python"
3129 action :create
3230end
3331
You can’t perform that action at this time.
0 commit comments