aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_language_python.rb
diff options
context:
space:
mode:
authorTim D. Smith2016-07-22 23:03:13 -0700
committerTim D. Smith2016-07-26 21:34:06 -0700
commit134d0bb4862f39a5d3415cc14c11990624f61f5a (patch)
tree9f5b13f9fed82d14ca59efc8837c41ca8c76a395 /Library/Homebrew/test/test_language_python.rb
parent2783adec4a906c8fb5c45aa1305b1460b5bc8a5b (diff)
downloadbrew-134d0bb4862f39a5d3415cc14c11990624f61f5a.tar.bz2
Test Language::Python::Virtualenv
Diffstat (limited to 'Library/Homebrew/test/test_language_python.rb')
-rw-r--r--Library/Homebrew/test/test_language_python.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_language_python.rb b/Library/Homebrew/test/test_language_python.rb
new file mode 100644
index 000000000..5e91c73b0
--- /dev/null
+++ b/Library/Homebrew/test/test_language_python.rb
@@ -0,0 +1,88 @@
+require "testing_env"
+require "language/python"
+require "resource"
+
+class LanguagePythonTests < Homebrew::TestCase
+ def setup
+ @dir = Pathname.new(mktmpdir)
+ resource = stub("resource", :stage => true)
+ @formula = mock("formula") do
+ stubs(:resource).returns(resource)
+ end
+ @venv = Language::Python::Virtualenv::Virtualenv.new(@formula, @dir, "python")
+ end
+
+ def teardown
+ FileUtils.rm_rf @dir
+ end
+
+ def test_virtualenv_creation
+ @formula.expects(:resource).with("homebrew-virtualenv").returns(
+ mock("resource", :stage => true)
+ )
+ @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(
+ mock("resource", :stage => true)
+ )
+ @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
+
+ def test_link_scripts_links_scripts
+ bin = (@dir/"bin")
+ dest = (@dir/"dest")
+ bin.mkpath
+ refute((bin/"kilroy").exist?)
+ refute((dest/"kilroy").exist?)
+ FileUtils.touch bin/"irrelevant"
+ @venv.link_scripts(dest) { FileUtils.touch bin/"kilroy" }
+ assert((bin/"kilroy").exist?)
+ assert((dest/"kilroy").exist?)
+ assert((dest/"kilroy").symlink?)
+ assert_equal((bin/"kilroy").realpath, (dest/"kilroy").realpath)
+ refute((dest/"irrelevant").exist?)
+ end
+end