scout-gear 2.0.0 → 5.2.0

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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +65 -2
  3. data/Rakefile +2 -0
  4. data/VERSION +1 -1
  5. data/bin/scout +233 -24
  6. data/lib/scout/cmd.rb +344 -0
  7. data/lib/scout/concurrent_stream.rb +259 -0
  8. data/lib/scout/exceptions.rb +15 -8
  9. data/lib/scout/indiferent_hash/options.rb +8 -26
  10. data/lib/scout/log/color.rb +2 -2
  11. data/lib/scout/log/fingerprint.rb +11 -1
  12. data/lib/scout/log/progress/report.rb +0 -1
  13. data/lib/scout/log/progress/util.rb +1 -1
  14. data/lib/scout/log/progress.rb +4 -4
  15. data/lib/scout/log.rb +10 -2
  16. data/lib/scout/meta_extension.rb +19 -3
  17. data/lib/scout/misc/digest.rb +56 -0
  18. data/lib/scout/misc/filesystem.rb +26 -0
  19. data/lib/scout/misc/format.rb +17 -6
  20. data/lib/scout/misc/insist.rb +56 -0
  21. data/lib/scout/misc/monitor.rb +23 -0
  22. data/lib/scout/misc.rb +5 -11
  23. data/lib/scout/open/lock.rb +61 -0
  24. data/lib/scout/open/remote.rb +120 -0
  25. data/lib/scout/open/stream.rb +373 -0
  26. data/lib/scout/open/util.rb +225 -0
  27. data/lib/scout/open.rb +169 -0
  28. data/lib/scout/path/find.rb +68 -21
  29. data/lib/scout/path/tmpfile.rb +8 -0
  30. data/lib/scout/path/util.rb +14 -1
  31. data/lib/scout/path.rb +6 -30
  32. data/lib/scout/persist/open.rb +17 -0
  33. data/lib/scout/persist/path.rb +15 -0
  34. data/lib/scout/persist/serialize.rb +151 -0
  35. data/lib/scout/persist.rb +54 -0
  36. data/lib/scout/resource/path.rb +20 -0
  37. data/lib/scout/resource/produce/rake.rb +69 -0
  38. data/lib/scout/resource/produce.rb +246 -0
  39. data/lib/scout/resource/scout.rb +3 -0
  40. data/lib/scout/resource/util.rb +48 -0
  41. data/lib/scout/resource.rb +39 -0
  42. data/lib/scout/simple_opt/accessor.rb +1 -1
  43. data/lib/scout/simple_opt/doc.rb +29 -23
  44. data/lib/scout/simple_opt/parse.rb +4 -3
  45. data/lib/scout/tmpfile.rb +39 -1
  46. data/lib/scout/workflow/definition.rb +78 -0
  47. data/lib/scout/workflow/documentation.rb +83 -0
  48. data/lib/scout/workflow/step/info.rb +77 -0
  49. data/lib/scout/workflow/step/load.rb +18 -0
  50. data/lib/scout/workflow/step.rb +132 -0
  51. data/lib/scout/workflow/task/inputs.rb +114 -0
  52. data/lib/scout/workflow/task.rb +155 -0
  53. data/lib/scout/workflow/usage.rb +314 -0
  54. data/lib/scout/workflow/util.rb +11 -0
  55. data/lib/scout/workflow.rb +40 -0
  56. data/lib/scout-gear.rb +4 -0
  57. data/lib/scout.rb +1 -0
  58. data/lib/workflow-scout.rb +2 -0
  59. data/scout-gear.gemspec +77 -5
  60. data/scout_commands/alias +48 -0
  61. data/scout_commands/find +83 -0
  62. data/scout_commands/glob +0 -0
  63. data/scout_commands/rbbt +23 -0
  64. data/scout_commands/workflow/info +29 -0
  65. data/scout_commands/workflow/list +27 -0
  66. data/scout_commands/workflow/task +58 -0
  67. data/scout_commands/workflow/task_old +706 -0
  68. data/test/scout/indiferent_hash/test_options.rb +11 -1
  69. data/test/scout/misc/test_digest.rb +30 -0
  70. data/test/scout/misc/test_filesystem.rb +30 -0
  71. data/test/scout/misc/test_insist.rb +13 -0
  72. data/test/scout/open/test_lock.rb +52 -0
  73. data/test/scout/open/test_remote.rb +25 -0
  74. data/test/scout/open/test_stream.rb +515 -0
  75. data/test/scout/open/test_util.rb +73 -0
  76. data/test/scout/path/test_find.rb +28 -0
  77. data/test/scout/persist/test_open.rb +37 -0
  78. data/test/scout/persist/test_path.rb +37 -0
  79. data/test/scout/persist/test_serialize.rb +114 -0
  80. data/test/scout/resource/test_path.rb +40 -0
  81. data/test/scout/resource/test_produce.rb +62 -0
  82. data/test/scout/resource/test_util.rb +27 -0
  83. data/test/scout/simple_opt/test_doc.rb +16 -0
  84. data/test/scout/test_cmd.rb +85 -0
  85. data/test/scout/test_concurrent_stream.rb +29 -0
  86. data/test/scout/test_meta_extension.rb +9 -0
  87. data/test/scout/test_misc.rb +0 -7
  88. data/test/scout/test_open.rb +146 -0
  89. data/test/scout/test_path.rb +3 -1
  90. data/test/scout/test_persist.rb +83 -0
  91. data/test/scout/test_resource.rb +26 -0
  92. data/test/scout/test_workflow.rb +87 -0
  93. data/test/scout/workflow/step/test_info.rb +30 -0
  94. data/test/scout/workflow/step/test_load.rb +65 -0
  95. data/test/scout/workflow/task/test_inputs.rb +182 -0
  96. data/test/scout/workflow/test_definition.rb +0 -0
  97. data/test/scout/workflow/test_documentation.rb +30 -0
  98. data/test/scout/workflow/test_step.rb +36 -0
  99. data/test/scout/workflow/test_task.rb +179 -0
  100. data/test/scout/workflow/test_usage.rb +35 -0
  101. data/test/scout/workflow/test_util.rb +17 -0
  102. data/test/test_helper.rb +17 -0
  103. data/test/test_scout-gear.rb +0 -0
  104. 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
+
@@ -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 '#{File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')}'
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
+