Sha256: 175e10b084758bfd22c3ecd0b5b940c287e80e089a53c66a37fd0d130837715d

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

require "spec_helper"

require "open3"

describe SimControl::PythonEnvironment do
  let(:script) { "a-script" }
  describe "#simulate" do
    it "uses popen3 to call the command and sets the cwd" do
      command = "a-command"
      basedir = "a-basedir"
      thread = double("Thread")
      
      simulation = SimControl::PythonEnvironment.new script, ""
      simulation.stub(:command).and_return(command)
      simulation.stub(:basedir).and_return(basedir)
      Open3.should_receive(:popen3).with(command, chdir: basedir).and_return([nil, nil, nil, thread])
      thread.should_receive(:join)
      simulation.execute(foo: 1)
    end

    it "calls the script if nothing is passed in args" do
      simulation = SimControl::PythonEnvironment.new script, ""
      expect(simulation.script).to eq("a-script")
    end

    it "uses a given interpreter" do
      simulation = SimControl::PythonEnvironment.new script, "", interpreter: "pypy"
      expect(simulation.interpreter).to eq("pypy")
    end

    it "uses a given virtualenv and interpreter" do
      simulation = SimControl::PythonEnvironment.new script, "", virtualenv: "foo/bar",  interpreter: "pypy"
      expect(simulation.interpreter).to eq("foo/bar/bin/pypy")
    end
    
    it "composes the command" do
      simulation = SimControl::PythonEnvironment.new script, ""
      scenario = "--args 1"
      simulation.stub(:interpreter).and_return "/foo/jpython"
      expect(simulation.command(scenario)).to eq("/foo/jpython a-script --args 1")
    end

    it "raised an exception is a virtualenv is passed but no interpreter" do
      expect do
        SimControl::PythonEnvironment.new script, "", virtualenv: "foo/bar"
      end.to raise_error /passing a virtualenv requires an interpreter/
    end

    it "returns the basedir" do
      simulation = SimControl::PythonEnvironment.new "/foo/bar/sim.py", ""
      expect(simulation.basedir).to eq("/foo/bar")
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
SimControl-0.1.10 spec/environments/python_environment_spec.rb
SimControl-0.1.9 spec/environments/python_environment_spec.rb
SimControl-0.1.8 spec/environments/python_environment_spec.rb
SimControl-0.1.7 spec/environments/python_environment_spec.rb