SimControl 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- SimControl (0.1.5)
4
+ SimControl (0.1.6)
5
5
  active_support
6
6
  i18n
7
7
  thor
@@ -50,7 +50,7 @@ module SimControl
50
50
  end
51
51
 
52
52
  def simulation(klass, script, arguments)
53
- @current_simulation = klass.new script, arguments
53
+ @current_simulation = klass.new script, @results_directory, arguments
54
54
  end
55
55
 
56
56
  def seeds
@@ -1,8 +1,12 @@
1
1
  module SimControl
2
2
  class BaseEnvironment
3
+ def initialize(results_path)
4
+ @results_path = results_path
5
+ end
6
+
3
7
  def simulate(scenario, seeds)
4
8
  seeds.each do |seed|
5
- execute(scenario.args({seed: seed}))
9
+ execute(scenario.args({seed: seed, results: @results_path}))
6
10
  end
7
11
  end
8
12
  end
@@ -2,7 +2,8 @@ require "open3"
2
2
 
3
3
  module SimControl
4
4
  class PythonEnvironment < BaseEnvironment
5
- def initialize(script, args = {})
5
+ def initialize(script, results_directory, args = {})
6
+ super(results_directory)
6
7
  @script = script
7
8
  @interpreter = args.delete(:interpreter)
8
9
  @virtualenv = args.delete(:virtualenv)
@@ -1,3 +1,3 @@
1
1
  module SimControl
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -55,11 +55,12 @@ scenario
55
55
 
56
56
  describe "#simulation" do
57
57
  let(:klass) { double("Klass") }
58
- it "creates a new instance of the given class and passes the hash" do
58
+ it "creates a new instance of the given class and passes the hash, and the results directory" do
59
59
  script = "a-script"
60
60
  hash = double("Hash")
61
- instance = SimControl::Controller.new("", "", "", "")
62
- klass.should_receive(:new).with(script, hash)
61
+ results_directory = "results/scenario_name"
62
+ instance = SimControl::Controller.new("", "", "", results_directory)
63
+ klass.should_receive(:new).with(script, results_directory, hash)
63
64
  instance.simulation klass, script, hash
64
65
  end
65
66
 
@@ -3,11 +3,20 @@ require "spec_helper"
3
3
  describe SimControl::BaseEnvironment do
4
4
  describe "#simulate" do
5
5
  it "calls #execute for each seed" do
6
+ environment = SimControl::BaseEnvironment.new ""
6
7
  scenario = double("scenario")
7
- scenario.should_receive(:args).with(seed: 1)
8
- scenario.should_receive(:args).with(seed: 2)
9
- subject.should_receive(:execute).twice
10
- subject.simulate(scenario, [1, 2])
8
+ scenario.should_receive(:args).with(seed: 1, results: "")
9
+ scenario.should_receive(:args).with(seed: 2, results: "")
10
+ environment.should_receive(:execute).twice
11
+ environment.simulate(scenario, [1, 2])
12
+ end
13
+
14
+ it "the results directory is merged in the scenario" do
15
+ scenario = double("scenario")
16
+ scenario.should_receive(:args).with(seed: 1, results: "path")
17
+ environment = SimControl::BaseEnvironment.new "path"
18
+ environment.stub(:execute)
19
+ environment.simulate scenario, [1]
11
20
  end
12
21
  end
13
22
  end
@@ -10,7 +10,7 @@ describe SimControl::PythonEnvironment do
10
10
  basedir = "a-basedir"
11
11
  thread = double("Thread")
12
12
 
13
- simulation = SimControl::PythonEnvironment.new script
13
+ simulation = SimControl::PythonEnvironment.new script, ""
14
14
  simulation.stub(:command).and_return(command)
15
15
  simulation.stub(:basedir).and_return(basedir)
16
16
  Open3.should_receive(:popen3).with(command, chdir: basedir).and_return([nil, nil, nil, thread])
@@ -19,22 +19,22 @@ describe SimControl::PythonEnvironment do
19
19
  end
20
20
 
21
21
  it "calls the script if nothing is passed in args" do
22
- simulation = SimControl::PythonEnvironment.new script
22
+ simulation = SimControl::PythonEnvironment.new script, ""
23
23
  expect(simulation.script).to eq("a-script")
24
24
  end
25
25
 
26
26
  it "uses a given interpreter" do
27
- simulation = SimControl::PythonEnvironment.new script, interpreter: "pypy"
27
+ simulation = SimControl::PythonEnvironment.new script, "", interpreter: "pypy"
28
28
  expect(simulation.interpreter).to eq("pypy")
29
29
  end
30
30
 
31
31
  it "uses a given virtualenv and interpreter" do
32
- simulation = SimControl::PythonEnvironment.new script, virtualenv: "foo/bar", interpreter: "pypy"
32
+ simulation = SimControl::PythonEnvironment.new script, "", virtualenv: "foo/bar", interpreter: "pypy"
33
33
  expect(simulation.interpreter).to eq("foo/bar/bin/pypy")
34
34
  end
35
35
 
36
36
  it "composes the command" do
37
- simulation = SimControl::PythonEnvironment.new script
37
+ simulation = SimControl::PythonEnvironment.new script, ""
38
38
  scenario = "--args 1"
39
39
  simulation.stub(:interpreter).and_return "/foo/jpython"
40
40
  expect(simulation.command(scenario)).to eq("/foo/jpython a-script --args 1")
@@ -42,12 +42,12 @@ describe SimControl::PythonEnvironment do
42
42
 
43
43
  it "raised an exception is a virtualenv is passed but no interpreter" do
44
44
  expect do
45
- SimControl::PythonEnvironment.new script, virtualenv: "foo/bar"
45
+ SimControl::PythonEnvironment.new script, "", virtualenv: "foo/bar"
46
46
  end.to raise_error /passing a virtualenv requires an interpreter/
47
47
  end
48
48
 
49
49
  it "returns the basedir" do
50
- simulation = SimControl::PythonEnvironment.new "/foo/bar/sim.py"
50
+ simulation = SimControl::PythonEnvironment.new "/foo/bar/sim.py", ""
51
51
  expect(simulation.basedir).to eq("/foo/bar")
52
52
  end
53
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SimControl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor