python_spec.rb (fpm-1.13.1) | : | python_spec.rb (fpm-1.14.0) | ||
---|---|---|---|---|
require "spec_setup" | require "spec_setup" | |||
require "fpm" # local | require "fpm" # local | |||
require "fpm/package/python" # local | require "fpm/package/python" # local | |||
require "find" # stdlib | require "find" # stdlib | |||
def find_python | ||||
[ "python", "python3", "python2" ].each do |i| | ||||
return i if program_exists?(i) | ||||
end | ||||
return nil | ||||
end | ||||
def python_usable? | def python_usable? | |||
return program_exists?("python") && program_exists?("easy_install") | return find_python | |||
end | end | |||
if !python_usable? | if !python_usable? | |||
Cabin::Channel.get("rspec").warn("Skipping Python#input tests because " \ | Cabin::Channel.get("rspec").warn("Skipping Python#input tests because 'python' | |||
"'python' and/or 'easy_install' isn't in your PATH") | wasn't found in $PATH") | |||
end | end | |||
is_travis = ENV["TRAVIS_OS_NAME"] && !ENV["TRAVIS_OS_NAME"].empty? | is_travis = ENV["TRAVIS_OS_NAME"] && !ENV["TRAVIS_OS_NAME"].empty? | |||
# Determine default value of a given easy_install's option | # Determine default value of a given easy_install's option | |||
def easy_install_default(python_bin, option) | def easy_install_default(python_bin, option) | |||
result = nil | result = nil | |||
execmd({:PYTHONPATH=>"#{example_dir}"}, python_bin, :stderr=>false) do |stdin, stdout| | execmd({:PYTHONPATH=>"#{example_dir}"}, python_bin, :stderr=>false) do |stdin, stdout| | |||
stdin.write("from easy_install_default import default_options\n" \ | stdin.write("from easy_install_default import default_options\n" \ | |||
"print default_options.#{option}\n") | "print default_options.#{option}\n") | |||
stdin.close | stdin.close | |||
result = stdout.read.chomp | result = stdout.read.chomp | |||
end | end | |||
return result | return result | |||
end | end | |||
describe FPM::Package::Python do | describe FPM::Package::Python do | |||
before do | before do | |||
skip("Python and/or easy_install not found") unless python_usable? | skip("Python program not found") unless python_usable? | |||
subject.attributes[:python_bin] = find_python | ||||
end | end | |||
let (:example_dir) do | let (:example_dir) do | |||
File.expand_path("../../fixtures/python/", File.dirname(__FILE__)) | File.expand_path("../../fixtures/python/", File.dirname(__FILE__)) | |||
end | end | |||
after :each do | after :each do | |||
subject.cleanup | subject.cleanup | |||
end | end | |||
skipping to change at line 127 | skipping to change at line 134 | |||
end | end | |||
end | end | |||
context "when :python_dependencies is set" do | context "when :python_dependencies is set" do | |||
before :each do | before :each do | |||
subject.attributes[:python_dependencies] = true | subject.attributes[:python_dependencies] = true | |||
end | end | |||
it "it should include the dependencies from setup.py" do | it "it should include the dependencies from setup.py" do | |||
subject.input(example_dir) | subject.input(example_dir) | |||
insist { subject.dependencies.sort } == ["python-dependency1 ","python-de | # XXX: Why is there extra whitespace in these strings? | |||
pendency2 "] | insist { subject.dependencies.sort } == ["python-dependency1 ","python-de | |||
pendency2 ", "python-rtxt-dep4 "] | ||||
end | end | |||
context "and :python_disable_dependency is set" do | context "and :python_disable_dependency is set" do | |||
before :each do | before :each do | |||
subject.attributes[:python_disable_dependency] = "Dependency1" | subject.attributes[:python_disable_dependency] = "Dependency1" | |||
end | end | |||
it "it should exclude the dependency" do | it "it should exclude the dependency" do | |||
subject.input(example_dir) | subject.input(example_dir) | |||
insist { subject.dependencies.sort } == ["python-dependency2 "] | insist { subject.dependencies.sort } == ["python-dependency2 ", "python -rtxt-dep4 "] | |||
end | end | |||
end | end | |||
end | end | |||
context "when python_obey_requirements_txt? is true" do | context "when python_obey_requirements_txt? is true" do | |||
before :each do | before :each do | |||
subject.attributes[:python_obey_requirements_txt?] = true | subject.attributes[:python_obey_requirements_txt?] = true | |||
subject.attributes[:python_dependencies?] = true | subject.attributes[:python_dependencies?] = true | |||
end | end | |||
skipping to change at line 185 | skipping to change at line 193 | |||
it "it should exclude the dependency" do | it "it should exclude the dependency" do | |||
subject.attributes[:python_disable_dependency] = "rtxt-dep1" | subject.attributes[:python_disable_dependency] = "rtxt-dep1" | |||
subject.input(example_dir) | subject.input(example_dir) | |||
insist { subject.dependencies.sort } == ["rtxt-dep2 = 0.1", "rtxt-dep4 "] | insist { subject.dependencies.sort } == ["rtxt-dep2 = 0.1", "rtxt-dep4 "] | |||
end | end | |||
end | end | |||
end | end | |||
context "python_scripts_executable is set" do | context "python_scripts_executable is set" do | |||
it "should have scripts with a custom hashbang line" do | it "should have scripts with a custom hashbang line" do | |||
pending("Disabled on travis-ci because it always fails, and there is no wa | pending("Disabled on travis-ci becaulamese it always fails, and there is n | |||
y to debug it?") if is_travis | o way to debug it?") if is_travis | |||
skip("Requires python3 executable") unless program_exists?("python3") | ||||
subject.attributes[:python_scripts_executable] = "fancypants" | subject.attributes[:python_scripts_executable] = "fancypants" | |||
# Newer versions of Django require Python 3. | # Newer versions of Django require Python 3. | |||
subject.attributes[:python_bin] = "python3" | subject.attributes[:python_bin] = "python3" | |||
subject.input("django") | subject.input("django") | |||
# Determine, where 'easy_install' is going to install scripts | # Determine, where 'easy_install' is going to install scripts | |||
#script_dir = easy_install_default(subject.attributes[:python_bin], 'scrip t_dir') | #script_dir = easy_install_default(subject.attributes[:python_bin], 'scrip t_dir') | |||
#path = subject.staging_path(File.join(script_dir, "django-admin.py")) | #path = subject.staging_path(File.join(script_dir, "django-admin.py")) | |||
End of changes. 7 change blocks. | ||||
9 lines changed or deleted | 19 lines changed or added |