SimControl 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/SimControl/controller.rb +1 -1
- data/lib/SimControl/environments/base.rb +5 -1
- data/lib/SimControl/environments/python.rb +2 -1
- data/lib/SimControl/version.rb +1 -1
- data/spec/controller_spec.rb +4 -3
- data/spec/environments/base_environment_spec.rb +13 -4
- data/spec/environments/python_environment_spec.rb +7 -7
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -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)
|
data/lib/SimControl/version.rb
CHANGED
data/spec/controller_spec.rb
CHANGED
@@ -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
|
-
|
62
|
-
|
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
|
-
|
10
|
-
|
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.
|
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-
|
12
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|