2016-07-22 23:03:13 -07:00
|
|
|
require "testing_env"
|
|
|
|
require "language/python"
|
|
|
|
require "resource"
|
|
|
|
|
|
|
|
class LanguagePythonTests < Homebrew::TestCase
|
|
|
|
def setup
|
2017-01-21 11:21:30 +00:00
|
|
|
super
|
2016-07-22 23:03:13 -07:00
|
|
|
@dir = Pathname.new(mktmpdir)
|
2016-09-17 15:32:44 +01:00
|
|
|
resource = stub("resource", stage: true)
|
2016-08-02 22:37:15 +02:00
|
|
|
formula_bin = @dir/"formula_bin"
|
2016-07-22 23:03:13 -07:00
|
|
|
@formula = mock("formula") do
|
|
|
|
stubs(:resource).returns(resource)
|
2016-08-02 22:37:15 +02:00
|
|
|
stubs(:bin).returns(formula_bin)
|
2016-07-22 23:03:13 -07:00
|
|
|
end
|
|
|
|
@venv = Language::Python::Virtualenv::Virtualenv.new(@formula, @dir, "python")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_virtualenv_creation
|
|
|
|
@formula.expects(:resource).with("homebrew-virtualenv").returns(
|
2017-02-12 15:06:54 +00:00
|
|
|
mock("resource", stage: true),
|
2016-07-22 23:03:13 -07:00
|
|
|
)
|
|
|
|
@venv.create
|
|
|
|
end
|
|
|
|
|
|
|
|
# or at least doesn't crash the second time
|
|
|
|
def test_virtualenv_creation_is_idempotent
|
|
|
|
@formula.expects(:resource).with("homebrew-virtualenv").returns(
|
2017-02-12 15:06:54 +00:00
|
|
|
mock("resource", stage: true),
|
2016-07-22 23:03:13 -07:00
|
|
|
)
|
|
|
|
@venv.create
|
|
|
|
FileUtils.mkdir_p @dir/"bin"
|
|
|
|
FileUtils.touch @dir/"bin/python"
|
|
|
|
@venv.create
|
|
|
|
FileUtils.rm @dir/"bin/python"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pip_install_accepts_string
|
|
|
|
@formula.expects(:system).returns(true).with do |*params|
|
|
|
|
params.first == @dir/"bin/pip" && params.last == "foo"
|
|
|
|
end
|
|
|
|
@venv.pip_install "foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pip_install_accepts_multiline_string
|
|
|
|
@formula.expects(:system).returns(true).with do |*params|
|
|
|
|
params.first == @dir/"bin/pip" && params[-2..-1] == ["foo", "bar"]
|
|
|
|
end
|
|
|
|
@venv.pip_install <<-EOS.undent
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pip_install_accepts_array
|
|
|
|
@formula.expects(:system).returns(true).with do |*params|
|
|
|
|
params.first == @dir/"bin/pip" && params.last == "foo"
|
|
|
|
end
|
|
|
|
@formula.expects(:system).returns(true).with do |*params|
|
|
|
|
params.first == @dir/"bin/pip" && params.last == "bar"
|
|
|
|
end
|
|
|
|
@venv.pip_install ["foo", "bar"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pip_install_accepts_resource
|
|
|
|
res = Resource.new "test"
|
|
|
|
res.expects(:stage).yields(nil)
|
|
|
|
@formula.expects(:system).returns(true).with do |*params|
|
|
|
|
params.first == @dir/"bin/pip" && params.last == Pathname.pwd
|
|
|
|
end
|
|
|
|
@venv.pip_install res
|
|
|
|
end
|
|
|
|
|
2016-08-02 22:37:15 +02:00
|
|
|
def test_pip_install_and_link_links_scripts
|
|
|
|
bin = @dir/"bin"
|
2016-07-22 23:03:13 -07:00
|
|
|
bin.mkpath
|
2016-08-02 22:37:15 +02:00
|
|
|
dest = @formula.bin
|
|
|
|
|
|
|
|
refute_predicate bin/"kilroy", :exist?
|
|
|
|
refute_predicate dest/"kilroy", :exist?
|
|
|
|
|
2016-07-22 23:03:13 -07:00
|
|
|
FileUtils.touch bin/"irrelevant"
|
2016-08-02 22:37:15 +02:00
|
|
|
bin_before = Dir[bin/"*"]
|
|
|
|
FileUtils.touch bin/"kilroy"
|
|
|
|
bin_after = Dir[bin/"*"]
|
|
|
|
@venv.expects(:pip_install).with("foo")
|
|
|
|
Dir.expects(:[]).twice.returns(bin_before, bin_after)
|
|
|
|
|
|
|
|
@venv.pip_install_and_link "foo"
|
|
|
|
|
|
|
|
assert_predicate bin/"kilroy", :exist?
|
|
|
|
assert_predicate dest/"kilroy", :exist?
|
|
|
|
assert_predicate dest/"kilroy", :symlink?
|
2016-07-22 23:03:13 -07:00
|
|
|
assert_equal((bin/"kilroy").realpath, (dest/"kilroy").realpath)
|
2016-08-02 22:37:15 +02:00
|
|
|
refute_predicate dest/"irrelevant", :exist?
|
2016-07-22 23:03:13 -07:00
|
|
|
end
|
|
|
|
end
|