| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  | # typed: false | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "language/python" | 
					
						
							|  |  |  | require "resource" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Language::Python::Virtualenv::Virtualenv, :needs_python do | 
					
						
							|  |  |  |   subject(:virtualenv) { described_class.new(formula, dir, "python") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:dir) { mktmpdir } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-22 17:07:43 -08:00
										 |  |  |   let(:resource) { instance_double(Resource, "resource", stage: true) } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   let(:formula_bin) { dir/"formula_bin" } | 
					
						
							| 
									
										
										
										
											2022-11-12 20:25:27 -08:00
										 |  |  |   let(:formula_man) { dir/"formula_man" } | 
					
						
							| 
									
										
										
										
											2023-01-22 17:07:43 -08:00
										 |  |  |   let(:formula) { instance_double(Formula, "formula", resource: resource, bin: formula_bin, man: formula_man) } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#create" do | 
					
						
							|  |  |  |     it "creates a venv" do | 
					
						
							| 
									
										
										
										
											2021-06-28 03:20:03 +01:00
										 |  |  |       expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", dir) | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |       virtualenv.create | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#pip_install" do | 
					
						
							|  |  |  |     it "accepts a string" do | 
					
						
							|  |  |  |       expect(formula).to receive(:system) | 
					
						
							| 
									
										
										
										
											2022-12-19 23:25:53 -08:00
										 |  |  |         .with(dir/"bin/pip", "install", "-v", "--no-deps", "--no-binary", ":all:", | 
					
						
							| 
									
										
										
										
											2022-12-10 15:02:18 +00:00
										 |  |  |               "--use-feature=no-binary-enable-wheel-cache", "--ignore-installed", "foo") | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         .and_return(true) | 
					
						
							|  |  |  |       virtualenv.pip_install "foo" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "accepts a multi-line strings" do | 
					
						
							|  |  |  |       expect(formula).to receive(:system) | 
					
						
							| 
									
										
										
										
											2022-12-19 23:25:53 -08:00
										 |  |  |         .with(dir/"bin/pip", "install", "-v", "--no-deps", "--no-binary", ":all:", | 
					
						
							| 
									
										
										
										
											2022-12-10 15:02:18 +00:00
										 |  |  |               "--use-feature=no-binary-enable-wheel-cache", "--ignore-installed", "foo", "bar") | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         .and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualenv.pip_install <<~EOS | 
					
						
							|  |  |  |         foo | 
					
						
							|  |  |  |         bar | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "accepts an array" do | 
					
						
							|  |  |  |       expect(formula).to receive(:system) | 
					
						
							| 
									
										
										
										
											2022-12-19 23:25:53 -08:00
										 |  |  |         .with(dir/"bin/pip", "install", "-v", "--no-deps", "--no-binary", ":all:", | 
					
						
							| 
									
										
										
										
											2022-12-10 15:02:18 +00:00
										 |  |  |               "--use-feature=no-binary-enable-wheel-cache", "--ignore-installed", "foo") | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         .and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(formula).to receive(:system) | 
					
						
							| 
									
										
										
										
											2022-12-19 23:25:53 -08:00
										 |  |  |         .with(dir/"bin/pip", "install", "-v", "--no-deps", "--no-binary", ":all:", | 
					
						
							| 
									
										
										
										
											2022-12-10 15:02:18 +00:00
										 |  |  |               "--use-feature=no-binary-enable-wheel-cache", "--ignore-installed", "bar") | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         .and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualenv.pip_install ["foo", "bar"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "accepts a Resource" do | 
					
						
							|  |  |  |       res = Resource.new("test") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res).to receive(:stage).and_yield | 
					
						
							|  |  |  |       expect(formula).to receive(:system) | 
					
						
							| 
									
										
										
										
											2022-12-19 23:25:53 -08:00
										 |  |  |         .with(dir/"bin/pip", "install", "-v", "--no-deps", "--no-binary", ":all:", | 
					
						
							| 
									
										
										
										
											2022-12-10 15:02:18 +00:00
										 |  |  |               "--use-feature=no-binary-enable-wheel-cache", "--ignore-installed", Pathname.pwd) | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         .and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualenv.pip_install res | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#pip_install_and_link" do | 
					
						
							|  |  |  |     let(:src_bin) { dir/"bin" } | 
					
						
							| 
									
										
										
										
											2022-11-12 20:25:27 -08:00
										 |  |  |     let(:src_man) { dir/"share/man" } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     let(:dest_bin) { formula.bin } | 
					
						
							| 
									
										
										
										
											2022-11-12 20:25:27 -08:00
										 |  |  |     let(:dest_man) { formula.man } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "can link scripts" do | 
					
						
							|  |  |  |       src_bin.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(src_bin/"kilroy").not_to exist | 
					
						
							|  |  |  |       expect(dest_bin/"kilroy").not_to exist | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       FileUtils.touch src_bin/"irrelevant" | 
					
						
							|  |  |  |       bin_before = Dir.glob(src_bin/"*") | 
					
						
							|  |  |  |       FileUtils.touch src_bin/"kilroy" | 
					
						
							|  |  |  |       bin_after = Dir.glob(src_bin/"*") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(virtualenv).to receive(:pip_install).with("foo") | 
					
						
							|  |  |  |       expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualenv.pip_install_and_link "foo" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(src_bin/"kilroy").to exist | 
					
						
							|  |  |  |       expect(dest_bin/"kilroy").to exist | 
					
						
							|  |  |  |       expect(dest_bin/"kilroy").to be_a_symlink | 
					
						
							|  |  |  |       expect((src_bin/"kilroy").realpath).to eq((dest_bin/"kilroy").realpath) | 
					
						
							|  |  |  |       expect(dest_bin/"irrelevant").not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-11-12 20:25:27 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "can link manpages" do | 
					
						
							|  |  |  |       (src_man/"man1").mkpath | 
					
						
							|  |  |  |       (src_man/"man3").mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(src_man/"man1/kilroy.1").not_to exist | 
					
						
							|  |  |  |       expect(dest_man/"man1").not_to exist | 
					
						
							|  |  |  |       expect(dest_man/"man3").not_to exist | 
					
						
							|  |  |  |       expect(dest_man/"man5").not_to exist | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       FileUtils.touch src_man/"man1/irrelevant.1" | 
					
						
							|  |  |  |       FileUtils.touch src_man/"man3/irrelevant.3" | 
					
						
							|  |  |  |       man_before = Dir.glob(src_man/"**/*") | 
					
						
							|  |  |  |       (src_man/"man5").mkpath | 
					
						
							|  |  |  |       FileUtils.touch src_man/"man1/kilroy.1" | 
					
						
							|  |  |  |       FileUtils.touch src_man/"man5/kilroy.5" | 
					
						
							|  |  |  |       man_after = Dir.glob(src_man/"**/*") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(virtualenv).to receive(:pip_install).with("foo") | 
					
						
							|  |  |  |       expect(Dir).to receive(:[]).with(src_bin/"*").and_return([]) | 
					
						
							|  |  |  |       expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_before) | 
					
						
							|  |  |  |       expect(Dir).to receive(:[]).with(src_bin/"*").and_return([]) | 
					
						
							|  |  |  |       expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_after) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualenv.pip_install_and_link("foo", link_manpages: true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(src_man/"man1/kilroy.1").to exist | 
					
						
							|  |  |  |       expect(dest_man/"man1/kilroy.1").to exist | 
					
						
							|  |  |  |       expect(dest_man/"man5/kilroy.5").to exist | 
					
						
							|  |  |  |       expect(dest_man/"man1/kilroy.1").to be_a_symlink | 
					
						
							|  |  |  |       expect((src_man/"man1/kilroy.1").realpath).to eq((dest_man/"man1/kilroy.1").realpath) | 
					
						
							|  |  |  |       expect(dest_man/"man1/irrelevant.1").not_to exist | 
					
						
							|  |  |  |       expect(dest_man/"man3").not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end |