scout-gear 2.0.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vimproject +65 -2
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bin/scout +233 -24
- data/lib/scout/cmd.rb +344 -0
- data/lib/scout/concurrent_stream.rb +259 -0
- data/lib/scout/exceptions.rb +15 -8
- data/lib/scout/indiferent_hash/options.rb +8 -26
- data/lib/scout/log/color.rb +2 -2
- data/lib/scout/log/fingerprint.rb +11 -1
- data/lib/scout/log/progress/report.rb +0 -1
- data/lib/scout/log/progress/util.rb +1 -1
- data/lib/scout/log/progress.rb +4 -4
- data/lib/scout/log.rb +10 -2
- data/lib/scout/meta_extension.rb +19 -3
- data/lib/scout/misc/digest.rb +56 -0
- data/lib/scout/misc/filesystem.rb +26 -0
- data/lib/scout/misc/format.rb +17 -6
- data/lib/scout/misc/insist.rb +56 -0
- data/lib/scout/misc/monitor.rb +23 -0
- data/lib/scout/misc.rb +5 -11
- data/lib/scout/open/lock.rb +61 -0
- data/lib/scout/open/remote.rb +120 -0
- data/lib/scout/open/stream.rb +373 -0
- data/lib/scout/open/util.rb +225 -0
- data/lib/scout/open.rb +169 -0
- data/lib/scout/path/find.rb +68 -21
- data/lib/scout/path/tmpfile.rb +8 -0
- data/lib/scout/path/util.rb +14 -1
- data/lib/scout/path.rb +6 -30
- data/lib/scout/persist/open.rb +17 -0
- data/lib/scout/persist/path.rb +15 -0
- data/lib/scout/persist/serialize.rb +151 -0
- data/lib/scout/persist.rb +54 -0
- data/lib/scout/resource/path.rb +20 -0
- data/lib/scout/resource/produce/rake.rb +69 -0
- data/lib/scout/resource/produce.rb +246 -0
- data/lib/scout/resource/scout.rb +3 -0
- data/lib/scout/resource/util.rb +48 -0
- data/lib/scout/resource.rb +39 -0
- data/lib/scout/simple_opt/accessor.rb +1 -1
- data/lib/scout/simple_opt/doc.rb +29 -23
- data/lib/scout/simple_opt/parse.rb +4 -3
- data/lib/scout/tmpfile.rb +39 -1
- data/lib/scout/workflow/definition.rb +78 -0
- data/lib/scout/workflow/documentation.rb +83 -0
- data/lib/scout/workflow/step/info.rb +77 -0
- data/lib/scout/workflow/step/load.rb +18 -0
- data/lib/scout/workflow/step.rb +132 -0
- data/lib/scout/workflow/task/inputs.rb +114 -0
- data/lib/scout/workflow/task.rb +155 -0
- data/lib/scout/workflow/usage.rb +314 -0
- data/lib/scout/workflow/util.rb +11 -0
- data/lib/scout/workflow.rb +40 -0
- data/lib/scout-gear.rb +4 -0
- data/lib/scout.rb +1 -0
- data/lib/workflow-scout.rb +2 -0
- data/scout-gear.gemspec +77 -5
- data/scout_commands/alias +48 -0
- data/scout_commands/find +83 -0
- data/scout_commands/glob +0 -0
- data/scout_commands/rbbt +23 -0
- data/scout_commands/workflow/info +29 -0
- data/scout_commands/workflow/list +27 -0
- data/scout_commands/workflow/task +58 -0
- data/scout_commands/workflow/task_old +706 -0
- data/test/scout/indiferent_hash/test_options.rb +11 -1
- data/test/scout/misc/test_digest.rb +30 -0
- data/test/scout/misc/test_filesystem.rb +30 -0
- data/test/scout/misc/test_insist.rb +13 -0
- data/test/scout/open/test_lock.rb +52 -0
- data/test/scout/open/test_remote.rb +25 -0
- data/test/scout/open/test_stream.rb +515 -0
- data/test/scout/open/test_util.rb +73 -0
- data/test/scout/path/test_find.rb +28 -0
- data/test/scout/persist/test_open.rb +37 -0
- data/test/scout/persist/test_path.rb +37 -0
- data/test/scout/persist/test_serialize.rb +114 -0
- data/test/scout/resource/test_path.rb +40 -0
- data/test/scout/resource/test_produce.rb +62 -0
- data/test/scout/resource/test_util.rb +27 -0
- data/test/scout/simple_opt/test_doc.rb +16 -0
- data/test/scout/test_cmd.rb +85 -0
- data/test/scout/test_concurrent_stream.rb +29 -0
- data/test/scout/test_meta_extension.rb +9 -0
- data/test/scout/test_misc.rb +0 -7
- data/test/scout/test_open.rb +146 -0
- data/test/scout/test_path.rb +3 -1
- data/test/scout/test_persist.rb +83 -0
- data/test/scout/test_resource.rb +26 -0
- data/test/scout/test_workflow.rb +87 -0
- data/test/scout/workflow/step/test_info.rb +30 -0
- data/test/scout/workflow/step/test_load.rb +65 -0
- data/test/scout/workflow/task/test_inputs.rb +182 -0
- data/test/scout/workflow/test_definition.rb +0 -0
- data/test/scout/workflow/test_documentation.rb +30 -0
- data/test/scout/workflow/test_step.rb +36 -0
- data/test/scout/workflow/test_task.rb +179 -0
- data/test/scout/workflow/test_usage.rb +35 -0
- data/test/scout/workflow/test_util.rb +17 -0
- data/test/test_helper.rb +17 -0
- data/test/test_scout-gear.rb +0 -0
- metadata +75 -3
@@ -0,0 +1,146 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestOpen < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_read
|
7
|
+
content =<<-EOF
|
8
|
+
1
|
9
|
+
2
|
10
|
+
3
|
11
|
+
4
|
12
|
+
EOF
|
13
|
+
TmpFile.with_file(content) do |file|
|
14
|
+
sum = 0
|
15
|
+
Open.read file do |line| sum += line.to_i end
|
16
|
+
assert_equal(1 + 2 + 3 + 4, sum)
|
17
|
+
assert_equal(content, Open.read(file))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_gzip
|
22
|
+
content =<<-EOF
|
23
|
+
1
|
24
|
+
2
|
25
|
+
3
|
26
|
+
4
|
27
|
+
EOF
|
28
|
+
TmpFile.with_file(content) do |file|
|
29
|
+
`gzip #{file}`
|
30
|
+
assert_equal(content, Open.read(file + '.gz'))
|
31
|
+
FileUtils.rm file + '.gz'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
#def test_wget
|
38
|
+
# assert(Misc.fixutf8(Open.wget('http://google.com', :quiet => true).read) =~ /html/)
|
39
|
+
#end
|
40
|
+
|
41
|
+
#def test_nice
|
42
|
+
# nice = 0.5
|
43
|
+
|
44
|
+
# t = Time.now
|
45
|
+
# Open.wget('http://google.com', :quiet => true, :nice => nice).read
|
46
|
+
# assert(Time.now - t + 0.5 >= nice)
|
47
|
+
|
48
|
+
# Open.wget('http://google.com', :quiet => true, :nice => nice, :nice_key => 1).read
|
49
|
+
# t = Time.now
|
50
|
+
# Open.wget('http://google.com', :quiet => true, :nice => nice, :nice_key => 1).read
|
51
|
+
# assert(Time.now - t + 0.5 >= nice)
|
52
|
+
#end
|
53
|
+
|
54
|
+
#def test_remote?
|
55
|
+
# assert(Open.remote?('http://google.com'))
|
56
|
+
# assert(! Open.remote?('~/.bashrc'))
|
57
|
+
#end
|
58
|
+
|
59
|
+
#def test_open
|
60
|
+
# assert(Open.read('http://google.com', :quiet => true, :nocache => :update) =~ /html/)
|
61
|
+
#end
|
62
|
+
|
63
|
+
#def test_repo_dir
|
64
|
+
# file1 = "TEST"
|
65
|
+
# file2 = "TEST" * 1000
|
66
|
+
# TmpFile.with_file do |tmpdir|
|
67
|
+
# tmpdir = Rbbt.tmp.repo_dir.find
|
68
|
+
# normal = File.join(tmpdir, 'normal')
|
69
|
+
# repo = File.join(tmpdir, 'repo')
|
70
|
+
|
71
|
+
# Open.repository_dirs.push(repo)
|
72
|
+
|
73
|
+
# Misc.benchmark(100) do
|
74
|
+
# filename = "file" << (rand * 100).to_i.to_s
|
75
|
+
# Open.write(File.join(normal, filename), file2)
|
76
|
+
# 100.times do
|
77
|
+
# Open.read(File.join(normal, filename))
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
81
|
+
# Misc.benchmark(100) do
|
82
|
+
# filename = "file" << (rand * 100).to_i.to_s
|
83
|
+
# Open.write(File.join(repo, filename), file2)
|
84
|
+
# 100.times do
|
85
|
+
# Open.read(File.join(repo, filename))
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
#end
|
90
|
+
#
|
91
|
+
#def test_repo_dir2
|
92
|
+
# TmpFile.with_file do |tmpdir|
|
93
|
+
# tmpdir = Rbbt.tmp.repo_dir.find
|
94
|
+
# repo = File.join(tmpdir, 'repo')
|
95
|
+
|
96
|
+
# Open.repository_dirs.push(repo)
|
97
|
+
|
98
|
+
# obj = { :a => "???a"}
|
99
|
+
# filename = "file" << (rand * 100).to_i.to_s
|
100
|
+
# Open.write(File.join(repo, filename), Marshal.dump(obj))
|
101
|
+
# dump = Open.read(File.join(repo, filename))
|
102
|
+
# obj_cp = Marshal.load(dump)
|
103
|
+
# assert_equal obj, obj_cp
|
104
|
+
# end
|
105
|
+
#end
|
106
|
+
|
107
|
+
#def test_repo_marshal
|
108
|
+
# TmpFile.with_file do |tmpdir|
|
109
|
+
# tmpdir = Rbbt.tmp.repo_dir.find
|
110
|
+
# repo = File.join(tmpdir, 'repo')
|
111
|
+
|
112
|
+
# filename = 'file'
|
113
|
+
# Open.repository_dirs.push(repo)
|
114
|
+
|
115
|
+
# obj = {:a => "string", :pid => nil, :num => 1000, :p => Rbbt.tmp.foo}
|
116
|
+
# Open.write(File.join(repo, filename), Marshal.dump(obj))
|
117
|
+
# new =Open.open(File.join(repo, filename)) do |f|
|
118
|
+
# Marshal.load(f)
|
119
|
+
# end
|
120
|
+
|
121
|
+
# assert_equal new, obj
|
122
|
+
# end
|
123
|
+
|
124
|
+
#end
|
125
|
+
|
126
|
+
#def test_write_stream_repo
|
127
|
+
# TmpFile.with_file do |tmpdir|
|
128
|
+
# tmpdir = Rbbt.tmp.repo_dir.find
|
129
|
+
# repo = File.join(tmpdir, 'repo')
|
130
|
+
|
131
|
+
# file = File.join(repo, 'file')
|
132
|
+
# Open.repository_dirs.push(repo)
|
133
|
+
|
134
|
+
# text = (["text"] * 5) * "\n"
|
135
|
+
|
136
|
+
# Misc.consume_stream(StringIO.new(text), false, file)
|
137
|
+
|
138
|
+
# assert_equal text, Open.read(file)
|
139
|
+
# assert !File.exist?(file)
|
140
|
+
# assert Open.exists? file
|
141
|
+
# end
|
142
|
+
|
143
|
+
#end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
data/test/scout/test_path.rb
CHANGED
@@ -37,8 +37,10 @@ class TestPath < Test::Unit::TestCase
|
|
37
37
|
TmpFile.with_file do |tmpdir|
|
38
38
|
Path.setup tmpdir
|
39
39
|
FileUtils.mkdir_p tmpdir.lib
|
40
|
+
lib_path = File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
41
|
+
lib_path = File.join(Path.caller_lib_dir, 'lib', lib_path)
|
40
42
|
File.write tmpdir.lib.file, <<-EOR
|
41
|
-
require '#{
|
43
|
+
require '#{lib_path}'
|
42
44
|
a = "1"
|
43
45
|
Path.setup(a)
|
44
46
|
print a.libdir
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestPersist < Test::Unit::TestCase
|
5
|
+
def test_string
|
6
|
+
TmpFile.with_file do |tmpfile|
|
7
|
+
Path.setup(tmpfile)
|
8
|
+
obj = "TEST"
|
9
|
+
type = :string
|
10
|
+
refute tmpdir.persist.glob("*").any?
|
11
|
+
assert_equal obj, Persist.persist(tmpfile, type, :dir => tmpdir.persist){ obj }
|
12
|
+
assert tmpdir.persist.glob("*").any?
|
13
|
+
assert_equal obj, Persist.persist(tmpfile, type, :dir => tmpdir.persist){ raise "Error" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_float_array
|
18
|
+
TmpFile.with_file do |tmpfile|
|
19
|
+
Path.setup(tmpfile)
|
20
|
+
obj = [1.2,2.2]
|
21
|
+
type = :float_array
|
22
|
+
refute tmpdir.persist.glob("*").any?
|
23
|
+
assert_equal obj, Persist.persist(tmpfile, type, :dir => tmpdir.persist){ obj }
|
24
|
+
assert tmpdir.persist.glob("*").any?
|
25
|
+
assert_equal obj, Persist.persist(tmpfile, type, :dir => tmpdir.persist){ raise "Error" }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_string_update
|
30
|
+
TmpFile.with_file do |tmpfile|
|
31
|
+
Path.setup(tmpfile)
|
32
|
+
obj = "TEST"
|
33
|
+
type = :string
|
34
|
+
refute tmpdir.persist.glob("*").any?
|
35
|
+
assert_equal obj, Persist.persist(tmpfile, type, :dir => tmpdir.persist){ obj }
|
36
|
+
assert tmpdir.persist.glob("*").any?
|
37
|
+
assert_raises ScoutException do
|
38
|
+
Persist.persist(tmpfile, type, :dir => tmpdir.persist, :update => true){ raise ScoutException }
|
39
|
+
end
|
40
|
+
assert_raises ScoutException do
|
41
|
+
Persist.persist(tmpfile, type, :persist_dir => tmpdir.persist, :persist_update => true){ raise ScoutException }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_stream
|
47
|
+
TmpFile.with_file do |tmpfile|
|
48
|
+
Path.setup(tmpfile)
|
49
|
+
obj = "TEST\nTEST"
|
50
|
+
stream = StringIO.new obj
|
51
|
+
stream.rewind
|
52
|
+
res = Persist.persist(tmpfile, :string, :dir => tmpdir.persist){ stream }
|
53
|
+
assert IO === res
|
54
|
+
assert_equal obj, res.read
|
55
|
+
assert_equal obj, Persist.persist(tmpfile, :string, :dir => tmpdir.persist){ raise ScoutException }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_update_time
|
60
|
+
TmpFile.with_file do |dir|
|
61
|
+
Path.setup(dir)
|
62
|
+
obj = "TEST"
|
63
|
+
type = :string
|
64
|
+
|
65
|
+
Open.write(dir.file, "TEST")
|
66
|
+
assert_equal "TEST", Persist.persist(dir.cache, type, :dir => tmpdir.persist){ Open.read(dir.file) }
|
67
|
+
Open.rm(dir.file)
|
68
|
+
assert_equal "TEST", Persist.persist(dir.cache, type, :dir => tmpdir.persist){ Open.read(dir.file) }
|
69
|
+
|
70
|
+
sleep 1
|
71
|
+
Open.write(dir.file2, "TEST2")
|
72
|
+
assert_equal "TEST", Persist.persist(dir.cache, type, :dir => tmpdir.persist){ Open.read(dir.file2) }
|
73
|
+
assert_equal "TEST2", Persist.persist(dir.cache, type, :dir => tmpdir.persist, :update => dir.file2){ Open.read(dir.file2) }
|
74
|
+
|
75
|
+
sleep 1
|
76
|
+
Open.write(dir.file3, "TEST3")
|
77
|
+
sleep 1
|
78
|
+
Open.touch tmpdir.persist.glob("*").first
|
79
|
+
assert_equal "TEST2", Persist.persist(dir.cache, type, :dir => tmpdir.persist, :update => dir.file3){ Open.read(dir.file3) }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestResourceUnit < Test::Unit::TestCase
|
5
|
+
module TestResource
|
6
|
+
extend Resource
|
7
|
+
|
8
|
+
self.subdir = Path.setup('tmp/test-resource')
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def test_root
|
13
|
+
|
14
|
+
p = TestResource.root.some_file
|
15
|
+
assert p.find(:user).include?(ENV["HOME"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def __test_identify
|
19
|
+
assert_equal 'etc/', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/etc/'))
|
20
|
+
assert_equal 'share/databases/', Rbbt.identify('/usr/local/share/rbbt/databases/')
|
21
|
+
assert_equal 'share/databases/DATABASE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE')
|
22
|
+
assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
|
23
|
+
assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/share/databases/DATABASE/FILE'))
|
24
|
+
assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestWorkflow < Test::Unit::TestCase
|
5
|
+
|
6
|
+
module Pantry
|
7
|
+
extend Resource
|
8
|
+
self.subdir = 'share/pantry'
|
9
|
+
|
10
|
+
Pantry.claim Pantry.eggs, :proc do
|
11
|
+
Log.info "Buying Eggs in the store"
|
12
|
+
"Eggs"
|
13
|
+
end
|
14
|
+
|
15
|
+
Pantry.claim Pantry.flour, :proc do
|
16
|
+
Log.info "Buying Flour in the store"
|
17
|
+
"Flour"
|
18
|
+
end
|
19
|
+
|
20
|
+
Pantry.claim Pantry.blueberries, :proc do
|
21
|
+
Log.info "Buying Bluberries in the store"
|
22
|
+
"Bluberries"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Baking
|
27
|
+
def self.whisk(eggs)
|
28
|
+
"Whisking eggs from #{eggs}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.mix(base, mixer)
|
32
|
+
"Mixing base (#{base}) with mixer (#{mixer})"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.bake(batter)
|
36
|
+
"Baking batter (#{batter})"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Baking
|
41
|
+
extend Workflow
|
42
|
+
|
43
|
+
dep :prepare_batter
|
44
|
+
task :bake_muffin_tray => :string do
|
45
|
+
Baking.bake(step(:prepare_batter).load)
|
46
|
+
end
|
47
|
+
|
48
|
+
dep :whisk_eggs
|
49
|
+
input :add_bluberries, :boolean
|
50
|
+
task :prepare_batter => :string do |add_bluberries|
|
51
|
+
whisked_eggs = step(:whisk_eggs).load
|
52
|
+
batter = Baking.mix(whisked_eggs, Pantry.flour.produce)
|
53
|
+
|
54
|
+
if add_bluberries
|
55
|
+
batter = Baking.mix(batter, Pantry.blueberries.produce)
|
56
|
+
end
|
57
|
+
|
58
|
+
batter
|
59
|
+
end
|
60
|
+
|
61
|
+
task :whisk_eggs => :string do
|
62
|
+
Baking.whisk(Pantry.eggs.produce)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
setup do
|
67
|
+
Baking.directory = tmpdir.var.jobs.baking.find
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_task
|
71
|
+
wf = Workflow.annonymous_workflow do
|
72
|
+
task :length => :integer do
|
73
|
+
self.length
|
74
|
+
end
|
75
|
+
end
|
76
|
+
bindings = "12345"
|
77
|
+
assert_equal 5, wf.tasks[:length].exec_on(bindings)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_baking
|
81
|
+
assert_equal "Baking batter (Mixing base (Mixing base (Whisking eggs from share/pantry/eggs) with mixer (share/pantry/flour)) with mixer (share/pantry/blueberries))",
|
82
|
+
Baking.job(:bake_muffin_tray, :add_bluberries => true).run
|
83
|
+
|
84
|
+
assert_equal "Baking batter (Mixing base (Whisking eggs from share/pantry/eggs) with mixer (share/pantry/flour))",
|
85
|
+
Baking.job(:bake_muffin_tray).run
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
require 'scout/workflow'
|
4
|
+
|
5
|
+
class TestStepInfo < Test::Unit::TestCase
|
6
|
+
def test_dependency
|
7
|
+
sss 0 do
|
8
|
+
TmpFile.with_file do |tmpdir|
|
9
|
+
Path.setup(tmpdir)
|
10
|
+
tmpfile = tmpdir.test_step
|
11
|
+
step1 = Step.new tmpfile.step1, ["12"] do |s|
|
12
|
+
s.length
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal 2, step1.exec
|
16
|
+
assert_equal 2, step1.run
|
17
|
+
|
18
|
+
step2 = Step.new tmpfile.step2 do
|
19
|
+
step1 = dependencies.first
|
20
|
+
step1.inputs.first + " has " + step1.load.to_s + " characters"
|
21
|
+
end
|
22
|
+
|
23
|
+
step2.dependencies = [step1]
|
24
|
+
|
25
|
+
assert_equal "12 has 2 characters", step2.run
|
26
|
+
assert_equal "12 has 2 characters", step2.run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
require 'scout/workflow/step'
|
5
|
+
|
6
|
+
class TestStepLoad < Test::Unit::TestCase
|
7
|
+
def test_dependency
|
8
|
+
sss 0 do
|
9
|
+
tmpfile = tmpdir.test_step
|
10
|
+
step1 = Step.new tmpfile.step1, ["12"] do |s|
|
11
|
+
s.length
|
12
|
+
end
|
13
|
+
|
14
|
+
step2 = Step.new tmpfile.step2 do
|
15
|
+
step1 = dependencies.first
|
16
|
+
step1.inputs.first + " has " + step1.load.to_s + " characters"
|
17
|
+
end
|
18
|
+
|
19
|
+
step2.dependencies = [step1]
|
20
|
+
|
21
|
+
step2.recursive_clean
|
22
|
+
step2.run
|
23
|
+
|
24
|
+
new_step2 = Step.load(step2.path)
|
25
|
+
|
26
|
+
assert_equal "12 has 2 characters", new_step2.load
|
27
|
+
assert_equal "12 has 2 characters", new_step2.run
|
28
|
+
assert_equal 2, new_step2.dependencies.first.run
|
29
|
+
assert_equal "12", new_step2.dependencies.first.inputs.first
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_relocate
|
34
|
+
wf = Workflow.annonymous_workflow "RelocateWorkflow" do
|
35
|
+
input :input1, :string
|
36
|
+
task :step1 => :string do |input1|
|
37
|
+
input1
|
38
|
+
end
|
39
|
+
|
40
|
+
dep :step1
|
41
|
+
task :step2 => :string do
|
42
|
+
step(:step1).load.reverse
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
step2 = wf.job(:step2, :input1 => "TEST")
|
47
|
+
step1 = step2.step(:step1)
|
48
|
+
|
49
|
+
step2.run
|
50
|
+
new_step2 = Step.load(step2.path)
|
51
|
+
TmpFile.with_file do |dir|
|
52
|
+
Misc.in_dir dir do
|
53
|
+
Path.setup(dir)
|
54
|
+
Open.mv step1.path, dir.var.jobs.RelocateWorkflow.step1[File.basename(step1.path)]
|
55
|
+
Open.mv step1.info_file, dir.var.jobs.RelocateWorkflow.step1[File.basename(step1.info_file)]
|
56
|
+
|
57
|
+
new_step2 = Step.load(step2.path)
|
58
|
+
assert_equal "TEST".reverse, new_step2.load
|
59
|
+
assert_equal "TEST", new_step2.dependencies.first.load
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
require 'scout/workflow/util'
|
5
|
+
|
6
|
+
class TestTaskInput < Test::Unit::TestCase
|
7
|
+
def example_workflow
|
8
|
+
Workflow.annonymous_workflow do
|
9
|
+
input :string, :string, "", "String"
|
10
|
+
input :integer, :integer, "", 1
|
11
|
+
input :float, :float, "", 1.1
|
12
|
+
input :boolean, :boolean, "", false
|
13
|
+
input :array, :array, "", %w(a b)
|
14
|
+
input :path, :path, "", "dir/subdir/file"
|
15
|
+
input :file, :file, ""
|
16
|
+
input :integer_array, :integer_array, "", [1, 2]
|
17
|
+
input :float_array, :float_array, "", [1.1, 2.2]
|
18
|
+
input :boolean_array, :boolean_array, "", [true, false, true]
|
19
|
+
input :path_array, :path_array, "", %w(dir/subdir/file1 dir/subdir/file2)
|
20
|
+
input :file_array, :file_array
|
21
|
+
task :task => :array do
|
22
|
+
inputs
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def example_task
|
28
|
+
example_workflow.tasks[:task]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_assign_inputs
|
32
|
+
task = self.example_task
|
33
|
+
|
34
|
+
assert_equal [:integer], task.assign_inputs(:string => "String", :integer => 2, :integer_array => %w(1 2)).last
|
35
|
+
|
36
|
+
TmpFile.with_file("1\n2") do |integer_array_file|
|
37
|
+
assert_equal [:integer], task.assign_inputs(:string => "String", :integer => 2, :integer_array => integer_array_file).last
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_boolean
|
42
|
+
task = self.example_task
|
43
|
+
|
44
|
+
assert_equal [:boolean], task.assign_inputs(:string => "String", :integer => 1, :boolean => true).last
|
45
|
+
|
46
|
+
TmpFile.with_file("1\n2") do |integer_array_file|
|
47
|
+
Open.open(integer_array_file) do |f|
|
48
|
+
inputs, _ = task.assign_inputs(:string => "String", :integer => 2, :integer_array => f)
|
49
|
+
input_pos = task.inputs.index{|p| p.first == :integer_array}
|
50
|
+
assert File === inputs[input_pos]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_keep_stream
|
56
|
+
task = self.example_task
|
57
|
+
|
58
|
+
assert_equal [:integer], task.assign_inputs(:string => "String", :integer => 2, :integer_array => %w(1 2)).last
|
59
|
+
|
60
|
+
TmpFile.with_file("1\n2") do |integer_array_file|
|
61
|
+
Open.open(integer_array_file) do |f|
|
62
|
+
inputs, _ = task.assign_inputs(:string => "String", :integer => 2, :integer_array => f)
|
63
|
+
input_pos = task.inputs.index{|p| p.first == :integer_array}
|
64
|
+
assert File === inputs[input_pos]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_digest_inputs
|
71
|
+
task = self.example_task
|
72
|
+
|
73
|
+
TmpFile.with_file("2\n3") do |integer_array_file|
|
74
|
+
assert_equal task.digest_inputs(:string => "String", :integer => 2, :integer_array => %w(2 3)),
|
75
|
+
task.digest_inputs(:string => "String", :integer => 2, :integer_array => integer_array_file)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_digest_stream
|
80
|
+
task = self.example_task
|
81
|
+
|
82
|
+
assert_equal [:integer], task.assign_inputs(:string => "String", :integer => 2, :integer_array => %w(1 2)).last
|
83
|
+
|
84
|
+
TmpFile.with_file("1\n2") do |integer_array_file|
|
85
|
+
hash1 = Open.open(integer_array_file) do |f|
|
86
|
+
task.digest_inputs(:string => "String", :integer => 2, :integer_array => f)
|
87
|
+
end
|
88
|
+
hash2 = Open.open(integer_array_file) do |f|
|
89
|
+
task.digest_inputs(:string => "String", :integer => 2, :integer_array => f)
|
90
|
+
end
|
91
|
+
assert_equal hash1, hash2
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def test_digest_file
|
98
|
+
task = self.example_task
|
99
|
+
|
100
|
+
TmpFile.with_file("2\n3") do |integer_array_file|
|
101
|
+
assert_equal task.digest_inputs(:string => "String", :integer => 2, :integer_array => %w(2 3)),
|
102
|
+
task.digest_inputs(:string => "String", :integer => 2, :integer_array => integer_array_file)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_save_and_load
|
107
|
+
task = self.example_task
|
108
|
+
|
109
|
+
TmpFile.with_file("2\n3") do |integer_array_file|
|
110
|
+
inputs = {:string => "String", :integer => 2, :integer_array => integer_array_file, :float_array => %w(1.1 2.2)}
|
111
|
+
original_digest = task.digest_inputs(inputs)
|
112
|
+
|
113
|
+
TmpFile.with_file do |save_directory|
|
114
|
+
task.save_inputs(save_directory, inputs)
|
115
|
+
new_inputs = task.load_inputs(save_directory)
|
116
|
+
new_digest = task.digest_inputs(new_inputs)
|
117
|
+
assert_equal original_digest, new_digest
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_save_and_load_file
|
123
|
+
task = self.example_task
|
124
|
+
|
125
|
+
TmpFile.with_file("TEST") do |somefile|
|
126
|
+
inputs = {:string => "String", :integer => 2, :file => somefile, :float_array => %w(1.1 2.2)}
|
127
|
+
original_digest = task.digest_inputs(inputs)
|
128
|
+
|
129
|
+
TmpFile.with_file do |save_directory|
|
130
|
+
task.save_inputs(save_directory, inputs)
|
131
|
+
Open.rm somefile
|
132
|
+
new_inputs = task.load_inputs(save_directory)
|
133
|
+
new_digest = task.digest_inputs(new_inputs)
|
134
|
+
assert_equal original_digest, new_digest
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_save_and_load_file_with_copy
|
140
|
+
task = self.example_task
|
141
|
+
|
142
|
+
TmpFile.with_file("TEST") do |somefile|
|
143
|
+
inputs = {:string => "String", :integer => 2, :file => somefile, :float_array => %w(1.1 2.2)}
|
144
|
+
original_digest = task.digest_inputs(inputs)
|
145
|
+
|
146
|
+
TmpFile.with_file do |save_directory|
|
147
|
+
task.save_inputs(save_directory, inputs)
|
148
|
+
TmpFile.with_file do |copy_directory|
|
149
|
+
Open.cp save_directory, copy_directory
|
150
|
+
Open.rm_rf save_directory
|
151
|
+
new_inputs = task.load_inputs(copy_directory)
|
152
|
+
new_digest = task.digest_inputs(new_inputs)
|
153
|
+
assert_equal original_digest, new_digest
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
def test_save_and_load_file_array
|
161
|
+
task = self.example_task
|
162
|
+
|
163
|
+
TmpFile.with_file do |dir|
|
164
|
+
file1 = File.join(dir, 'subdir1/file')
|
165
|
+
file2 = File.join(dir, 'subdir2/file')
|
166
|
+
|
167
|
+
Open.write(file1, "TEST1")
|
168
|
+
Open.write(file2, "TEST2")
|
169
|
+
inputs = {:string => "String", :integer => 2, :file_array => [file1, file2], :float_array => %w(1.1 2.2)}
|
170
|
+
original_digest = task.digest_inputs(inputs)
|
171
|
+
|
172
|
+
TmpFile.with_file do |save_directory|
|
173
|
+
task.save_inputs(save_directory, inputs)
|
174
|
+
Open.rm(file1)
|
175
|
+
Open.rm(file2)
|
176
|
+
new_inputs = task.load_inputs(save_directory)
|
177
|
+
new_digest = task.digest_inputs(new_inputs)
|
178
|
+
assert_equal original_digest, new_digest
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestWorkflowDocumentation < Test::Unit::TestCase
|
5
|
+
module UsageWorkflow
|
6
|
+
extend Workflow
|
7
|
+
|
8
|
+
self.name = "UsageWorkflow"
|
9
|
+
|
10
|
+
self.title = "Workflow to test documentation"
|
11
|
+
self.description = "Use this workflow to test if the documentation is correctly presented"
|
12
|
+
|
13
|
+
desc "Desc"
|
14
|
+
input :array, :array, "Array"
|
15
|
+
task :step1 => :string do
|
16
|
+
end
|
17
|
+
|
18
|
+
dep :step1
|
19
|
+
desc "Desc2"
|
20
|
+
input :float, :float, "Float"
|
21
|
+
task :step2 => :string do
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_usage
|
26
|
+
assert_match 'test', UsageWorkflow.documentation[:title]
|
27
|
+
assert_match 'presented', UsageWorkflow.documentation[:description]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|