tap 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README +71 -0
  3. data/Rakefile +117 -0
  4. data/bin/tap +63 -0
  5. data/lib/tap.rb +15 -0
  6. data/lib/tap/app.rb +739 -0
  7. data/lib/tap/file_task.rb +354 -0
  8. data/lib/tap/generator.rb +29 -0
  9. data/lib/tap/generator/generators/config/USAGE +0 -0
  10. data/lib/tap/generator/generators/config/config_generator.rb +23 -0
  11. data/lib/tap/generator/generators/config/templates/config.erb +2 -0
  12. data/lib/tap/generator/generators/file_task/USAGE +0 -0
  13. data/lib/tap/generator/generators/file_task/file_task_generator.rb +21 -0
  14. data/lib/tap/generator/generators/file_task/templates/task.erb +27 -0
  15. data/lib/tap/generator/generators/file_task/templates/test.erb +12 -0
  16. data/lib/tap/generator/generators/root/USAGE +0 -0
  17. data/lib/tap/generator/generators/root/root_generator.rb +36 -0
  18. data/lib/tap/generator/generators/root/templates/Rakefile +48 -0
  19. data/lib/tap/generator/generators/root/templates/app.yml +19 -0
  20. data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +4 -0
  21. data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +26 -0
  22. data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
  23. data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +57 -0
  24. data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +108 -0
  25. data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +40 -0
  26. data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +21 -0
  27. data/lib/tap/generator/generators/root/templates/server/config/environment.rb +60 -0
  28. data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +5 -0
  29. data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +53 -0
  30. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +3 -0
  31. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +4 -0
  32. data/lib/tap/generator/generators/task/USAGE +0 -0
  33. data/lib/tap/generator/generators/task/task_generator.rb +21 -0
  34. data/lib/tap/generator/generators/task/templates/task.erb +21 -0
  35. data/lib/tap/generator/generators/task/templates/test.erb +29 -0
  36. data/lib/tap/generator/generators/workflow/USAGE +0 -0
  37. data/lib/tap/generator/generators/workflow/templates/task.erb +16 -0
  38. data/lib/tap/generator/generators/workflow/templates/test.erb +7 -0
  39. data/lib/tap/generator/generators/workflow/workflow_generator.rb +21 -0
  40. data/lib/tap/generator/options.rb +26 -0
  41. data/lib/tap/generator/usage.rb +26 -0
  42. data/lib/tap/root.rb +275 -0
  43. data/lib/tap/script/console.rb +7 -0
  44. data/lib/tap/script/destroy.rb +8 -0
  45. data/lib/tap/script/generate.rb +8 -0
  46. data/lib/tap/script/run.rb +111 -0
  47. data/lib/tap/script/server.rb +12 -0
  48. data/lib/tap/support/audit.rb +415 -0
  49. data/lib/tap/support/batch_queue.rb +165 -0
  50. data/lib/tap/support/combinator.rb +114 -0
  51. data/lib/tap/support/logger.rb +91 -0
  52. data/lib/tap/support/rap.rb +38 -0
  53. data/lib/tap/support/run_error.rb +20 -0
  54. data/lib/tap/support/template.rb +81 -0
  55. data/lib/tap/support/templater.rb +155 -0
  56. data/lib/tap/support/versions.rb +63 -0
  57. data/lib/tap/task.rb +448 -0
  58. data/lib/tap/test.rb +320 -0
  59. data/lib/tap/test/env_vars.rb +16 -0
  60. data/lib/tap/test/inference_methods.rb +298 -0
  61. data/lib/tap/test/subset_methods.rb +260 -0
  62. data/lib/tap/version.rb +3 -0
  63. data/lib/tap/workflow.rb +73 -0
  64. data/test/app/config/addition_template.yml +6 -0
  65. data/test/app/config/batch.yml +2 -0
  66. data/test/app/config/empty.yml +0 -0
  67. data/test/app/config/erb.yml +1 -0
  68. data/test/app/config/template.yml +6 -0
  69. data/test/app/config/version-0.1.yml +1 -0
  70. data/test/app/config/version.yml +1 -0
  71. data/test/app/lib/app_test_task.rb +2 -0
  72. data/test/app_class_test.rb +33 -0
  73. data/test/app_test.rb +1372 -0
  74. data/test/file_task/config/batch.yml +2 -0
  75. data/test/file_task/config/configured.yml +1 -0
  76. data/test/file_task/old_file_one.txt +0 -0
  77. data/test/file_task/old_file_two.txt +0 -0
  78. data/test/file_task_test.rb +1041 -0
  79. data/test/root/alt_lib/alt_module.rb +4 -0
  80. data/test/root/lib/absolute_alt_filepath.rb +2 -0
  81. data/test/root/lib/alternative_filepath.rb +2 -0
  82. data/test/root/lib/another_module.rb +2 -0
  83. data/test/root/lib/nested/some_module.rb +4 -0
  84. data/test/root/lib/no_module_included.rb +0 -0
  85. data/test/root/lib/some/module.rb +4 -0
  86. data/test/root/lib/some_class.rb +2 -0
  87. data/test/root/lib/some_module.rb +3 -0
  88. data/test/root/load_path/load_path_module.rb +2 -0
  89. data/test/root/load_path/skip_module.rb +2 -0
  90. data/test/root/mtime/older.txt +0 -0
  91. data/test/root/unload/full_path.rb +2 -0
  92. data/test/root/unload/loaded_by_nested.rb +2 -0
  93. data/test/root/unload/nested/nested_load.rb +6 -0
  94. data/test/root/unload/nested/nested_with_ext.rb +4 -0
  95. data/test/root/unload/nested/relative_path.rb +4 -0
  96. data/test/root/unload/older.rb +2 -0
  97. data/test/root/unload/unload_base.rb +9 -0
  98. data/test/root/versions/another.yml +0 -0
  99. data/test/root/versions/file-0.1.2.yml +0 -0
  100. data/test/root/versions/file-0.1.yml +0 -0
  101. data/test/root/versions/file.yml +0 -0
  102. data/test/root_test.rb +483 -0
  103. data/test/support/audit_test.rb +449 -0
  104. data/test/support/batch_queue_test.rb +320 -0
  105. data/test/support/combinator_test.rb +249 -0
  106. data/test/support/logger_test.rb +31 -0
  107. data/test/support/template_test.rb +122 -0
  108. data/test/support/templater/erb.txt +2 -0
  109. data/test/support/templater/erb.yml +2 -0
  110. data/test/support/templater/somefile.txt +2 -0
  111. data/test/support/templater_test.rb +192 -0
  112. data/test/support/versions_test.rb +71 -0
  113. data/test/tap_test_helper.rb +4 -0
  114. data/test/tap_test_suite.rb +4 -0
  115. data/test/task/config/batch.yml +2 -0
  116. data/test/task/config/batched.yml +2 -0
  117. data/test/task/config/configured.yml +1 -0
  118. data/test/task/config/example.yml +1 -0
  119. data/test/task/config/overriding.yml +2 -0
  120. data/test/task/config/task_with_config.yml +1 -0
  121. data/test/task/config/template.yml +4 -0
  122. data/test/task_class_test.rb +118 -0
  123. data/test/task_execute_test.rb +233 -0
  124. data/test/task_test.rb +424 -0
  125. data/test/test/inference_methods/test_assert_expected/expected/file.txt +1 -0
  126. data/test/test/inference_methods/test_assert_expected/expected/folder/file.txt +1 -0
  127. data/test/test/inference_methods/test_assert_expected/input/file.txt +1 -0
  128. data/test/test/inference_methods/test_assert_expected/input/folder/file.txt +1 -0
  129. data/test/test/inference_methods/test_assert_files_exist/input/input_1.txt +0 -0
  130. data/test/test/inference_methods/test_assert_files_exist/input/input_2.txt +0 -0
  131. data/test/test/inference_methods/test_file_compare/expected/output_1.txt +3 -0
  132. data/test/test/inference_methods/test_file_compare/expected/output_2.txt +1 -0
  133. data/test/test/inference_methods/test_file_compare/input/input_1.txt +3 -0
  134. data/test/test/inference_methods/test_file_compare/input/input_2.txt +3 -0
  135. data/test/test/inference_methods/test_infer_glob/expected/file.yml +0 -0
  136. data/test/test/inference_methods/test_infer_glob/expected/file_1.txt +0 -0
  137. data/test/test/inference_methods/test_infer_glob/expected/file_2.txt +0 -0
  138. data/test/test/inference_methods/test_yml_compare/expected/output_1.yml +6 -0
  139. data/test/test/inference_methods/test_yml_compare/expected/output_2.yml +6 -0
  140. data/test/test/inference_methods/test_yml_compare/input/input_1.yml +4 -0
  141. data/test/test/inference_methods/test_yml_compare/input/input_2.yml +4 -0
  142. data/test/test/inference_methods_test.rb +311 -0
  143. data/test/test/subset_methods_test.rb +115 -0
  144. data/test/test_test.rb +233 -0
  145. data/test/workflow_test.rb +108 -0
  146. metadata +274 -0
data/test/task_test.rb ADDED
@@ -0,0 +1,424 @@
1
+ require File.join(File.dirname(__FILE__), 'tap_test_helper')
2
+ require 'tap/task'
3
+
4
+ # used in documentation test
5
+ class ConfiguredTask < Tap::Task
6
+ set_default_config :one => 'one', :two => 'two'
7
+ end
8
+
9
+ class TaskTest < Test::Unit::TestCase
10
+ include Tap
11
+ include Benchmark
12
+
13
+ acts_as_tap_test
14
+ attr_accessor :t
15
+
16
+ def setup
17
+ super
18
+ @t = Task.new
19
+ end
20
+
21
+ def test_documentation
22
+ t = ConfiguredTask.new
23
+ assert_equal({:one => 'one', :two => 'two'}, t.config)
24
+ assert_equal("configured_task", t.name)
25
+ assert_equal(File.join(app[:config], "configured_task.yml"), t.config_file)
26
+
27
+ ###
28
+ # [/path/to/app/config/example.yml]
29
+ # one: ONE
30
+
31
+ t = ConfiguredTask.new "example", :three => 'three'
32
+ assert_equal("example", t.name)
33
+ assert_equal(File.join(app[:config], "example.yml"), t.config_file)
34
+ assert_equal({:one => 'ONE', :two => 'two', :three => 'three'}, t.config)
35
+
36
+ ###
37
+ runlist = []
38
+ t1 = Task.new {|task, input| runlist << input}
39
+ t1.enq 1
40
+ t1.enq 2,3
41
+ t1.app.run
42
+
43
+ assert_equal([1,2,3], runlist)
44
+
45
+ ###
46
+ runlist = []
47
+ assert_equal([t1], t1.batch)
48
+ t2 = t1.create_batch_task
49
+ assert_equal([t1, t2], t1.batch)
50
+
51
+ t1.enq 1
52
+ t2.enq 2,3
53
+ t1.app.run
54
+
55
+ assert_equal([1,2,3, 1,2,3], runlist)
56
+
57
+ ####
58
+ # [/path/to/app/config/batch.yml]
59
+ # - one: ONE
60
+ # - one: ANOTHER ONE
61
+
62
+ t = ConfiguredTask.new "batch"
63
+ assert_equal(2, t.batch.size)
64
+ t1, t2 = t.batch
65
+
66
+ assert_equal("batch", t1.name)
67
+ assert_equal({:one => 'ONE'}, t1.config_template)
68
+ assert_equal({:one => 'ONE', :two => 'two'}, t1.config)
69
+
70
+ assert_equal("batch", t2.name)
71
+ assert_equal({:one => 'ANOTHER ONE'}, t2.config_template)
72
+ assert_equal({:one => 'ANOTHER ONE', :two => 'two'}, t2.config)
73
+
74
+
75
+ ####
76
+ # [/path/to/app/config/template.yml]
77
+ # one: ONE
78
+ # variations!:
79
+ # - two: TWO
80
+ # - three: THREE
81
+
82
+ t = ConfiguredTask.new "template"
83
+ assert_equal(2, t.batch.size)
84
+ t1, t2 = t.batch
85
+
86
+ assert_equal({:one => 'ONE', :two => 'TWO'}, t1.config)
87
+ assert_equal({:one => 'ONE', :two => 'two', :three => 'THREE'}, t2.config)
88
+ end
89
+
90
+ #
91
+ # initialization tests
92
+ #
93
+
94
+ def test_default_task_initialization
95
+ assert_equal App.instance, t.app
96
+ assert_equal [], t.results
97
+ assert_equal({}, t.config)
98
+ assert_equal({}, t.config_template)
99
+ assert_equal [t], t.batch
100
+ assert_nil t.condition_block
101
+ assert_nil t.task_block
102
+ assert_nil t.on_complete_block
103
+ assert !t.multithread
104
+ assert t.iterate
105
+ assert_equal "tap/task", t.name
106
+ end
107
+
108
+ def test_task_init_speed
109
+ benchmark_test do |x|
110
+ x.report("10k") { 10000.times { Task.new } }
111
+ end
112
+ end
113
+
114
+ def test_by_default_tasks_share_application_instance
115
+ t1 = Task.new
116
+ t2 = Task.new
117
+
118
+ assert_equal t1.app, t2.app
119
+ assert_equal App.instance, t1.app
120
+ end
121
+
122
+ class NamedTask < Task
123
+ end
124
+
125
+ def test_name_is_initialized_to_task_class_underscored
126
+ t = NamedTask.new
127
+ assert_equal "task_test/named_task", t.name
128
+ end
129
+
130
+ def test_name_configs_app_and_task_block_are_set_from_initialize
131
+ a = App.new
132
+ b = lambda {}
133
+
134
+ t = Task.new("name", {:key => 'value'}, a, &b)
135
+ assert_equal "name", t.name
136
+ assert_equal({:key => 'value'}, t.config)
137
+ assert_equal a, t.app
138
+ assert_equal b, t.task_block
139
+ end
140
+
141
+ def test_config_template_is_loaded_from_config_file
142
+ t = Task.new "configured"
143
+ assert File.exists?(t.config_file)
144
+ assert_equal "key: value", File.read(t.config_file)
145
+ assert_equal({:key => 'value'}, t.config_template)
146
+ end
147
+
148
+ def test_batched_tasks_are_defined_with_corresponding_config_template_for_batched_config_files
149
+ t = Task.new "batched"
150
+ assert File.exists?(t.config_file)
151
+ assert_equal "- key: first\n- key: second", File.read(t.config_file)
152
+
153
+ assert_equal 2, t.batch.size
154
+
155
+ t1, t2 = t.batch
156
+ assert_equal({:key => 'first'}, t1.config_template)
157
+ assert_equal({:key => 'second'}, t2.config_template)
158
+ end
159
+
160
+ def test_configs_are_merged_to_each_batched_task
161
+ t = Task.new "batched", :another => 'value'
162
+ t1, t2 = t.batch
163
+ assert_equal({:key => 'first', :another => 'value'}, t1.config)
164
+ assert_equal({:key => 'second', :another => 'value'}, t2.config)
165
+ end
166
+
167
+ #
168
+ # create_batch_task test
169
+ #
170
+
171
+ def test_created_batch_tasks_are_added_to_and_share_the_same_batch
172
+ assert_equal [t], t.batch
173
+
174
+ t1 = t.create_batch_task
175
+ t2 = t1.create_batch_task
176
+
177
+ assert_equal [t, t1, t2], t.batch
178
+ assert_equal t.batch.object_id, t1.batch.object_id
179
+ assert_equal t.batch.object_id, t2.batch.object_id
180
+ end
181
+
182
+ def test_create_batch_task_uses_input_template_and_overrides
183
+ t = TaskWithDefaultConfig.new "overriding", :three => 3
184
+ assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.default_config)
185
+ assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
186
+ assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
187
+
188
+ t1 = t.create_batch_task
189
+ assert_equal({}, t1.config_template)
190
+ assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t1.config)
191
+
192
+ t2 = t.create_batch_task({:two => "TWO", :three => "THREE"}, {:three => 3})
193
+ assert_equal({:two => "TWO", :three => "THREE"}, t2.config_template)
194
+ assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t2.config)
195
+ end
196
+
197
+ #
198
+ # batched? test
199
+ #
200
+
201
+ def test_batched_returns_true_if_batch_size_is_greater_than_one
202
+ assert !t.batched?
203
+ assert_equal 1, t.batch.size
204
+
205
+ t1 = t.create_batch_task
206
+
207
+ assert t.batched?
208
+ assert t1.batched?
209
+ end
210
+
211
+ #
212
+ # batch_index test
213
+ #
214
+
215
+ def test_batch_index_returns_the_index_of_the_task_in_batch
216
+ t1 = t.create_batch_task
217
+
218
+ assert_equal [t, t1], t.batch
219
+ assert_equal 0, t.batch_index
220
+ assert_equal 1, t1.batch_index
221
+ end
222
+
223
+ #
224
+ # config_file test
225
+ #
226
+
227
+ def test_config_file_returns_yml_filepath_for_name_relative_to_app_config_dir
228
+ assert_equal File.join(t.app['config'], t.name + ".yml"), t.config_file
229
+ end
230
+
231
+ #
232
+ # multithread test
233
+ #
234
+
235
+ def test_multithread_returns_value_of_multithread
236
+ t.multithread = false
237
+ assert !t.multithread?
238
+ t.multithread = true
239
+ assert t.multithread?
240
+ end
241
+
242
+ #
243
+ # iterate test
244
+ #
245
+
246
+ def test_iterate_defaults_to_class_iterative_variable
247
+ assert Task.iterative
248
+ assert t.iterate?
249
+ end
250
+
251
+ def test_iterate_can_be_set
252
+ t.iterate = false
253
+ assert !t.iterate?
254
+ t.iterate = true
255
+ assert t.iterate?
256
+ end
257
+
258
+ #
259
+ # configuration tests
260
+ #
261
+
262
+ class TaskWithDefaultConfig < Task
263
+ set_default_config :one => 'one', :two => 'two', :three => 'three'
264
+ end
265
+
266
+ def test_config_sets_config
267
+ assert_equal({}, t.config)
268
+ t.config = {:key => 'value'}
269
+ assert_equal({:key => 'value'}, t.config)
270
+ end
271
+
272
+ def test_config_merges_class_defaults_and_config_template_and_inputs_in_order
273
+ t = TaskWithDefaultConfig.new "overriding"
274
+ assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.default_config)
275
+ assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
276
+
277
+ t.config = {:three => 3}
278
+ assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
279
+ end
280
+
281
+ def test_nil_is_treated_as_empty_hash
282
+ t = TaskWithDefaultConfig.new "overriding"
283
+ assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.default_config)
284
+ assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
285
+
286
+ t.config[:three] = 3
287
+ assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
288
+
289
+ t.config = nil
290
+ assert_equal({:one => 'one', :two => 'TWO', :three => 'THREE'}, t.config)
291
+ end
292
+
293
+ #
294
+ # condition block test
295
+ #
296
+
297
+ def test_condition_sets_condition_block
298
+ block = lambda {}
299
+ t.condition(&block)
300
+ assert_equal block, t.condition_block
301
+ end
302
+
303
+ def test_condition_can_only_be_set_once
304
+ t.condition {}
305
+ assert_raise(RuntimeError) { t.condition {} }
306
+ assert_raise(RuntimeError) { t.condition }
307
+ end
308
+
309
+ #
310
+ # executable? test
311
+ #
312
+
313
+ def test_executable_evaluates_condition_block_with_inputs
314
+ t.condition do |task, inputs|
315
+ inputs == [1,2,3]
316
+ end
317
+
318
+ assert t.executable?([1,2,3])
319
+ assert !t.executable?(1)
320
+ end
321
+
322
+ def test_executable_returns_true_if_condition_block_is_nil
323
+ assert_nil t.condition_block
324
+ assert t.executable?(nil)
325
+ end
326
+
327
+ #
328
+ # on_complete block test
329
+ #
330
+
331
+ def test_on_complete_sets_on_complete_block
332
+ block = lambda {}
333
+ t.on_complete(&block)
334
+ assert_equal block, t.on_complete_block
335
+ end
336
+
337
+ def test_on_complete_can_only_be_set_once
338
+ t.on_complete {}
339
+ assert_raise(RuntimeError) { t.on_complete {} }
340
+ assert_raise(RuntimeError) { t.on_complete }
341
+ end
342
+
343
+ #
344
+ # queue test
345
+ #
346
+
347
+ def test_queue_enqueues_task_to_app_queue_with_inputs
348
+ assert t.app.queue.empty?
349
+
350
+ t.enq 1
351
+
352
+ assert_equal 1, t.app.queue.size
353
+ assert_equal [t, [1]], t.app.queue.deq
354
+
355
+ t.enq 1
356
+ t.enq 2
357
+
358
+ assert_equal [t, [1,2]], t.app.queue.deq
359
+ end
360
+
361
+ #
362
+ # process test
363
+ #
364
+
365
+ def test_process_calls_task_block_with_input
366
+ b = lambda do |task, input|
367
+ runlist << input
368
+ input += 1
369
+ end
370
+ t = Task.new(&b)
371
+
372
+ assert_equal b, t.task_block
373
+ assert_equal 2, t.process(1)
374
+ assert_equal [1], runlist
375
+ end
376
+
377
+ def test_process_returns_input_if_task_block_is_not_set
378
+ t = Task.new
379
+
380
+ assert_nil t.task_block
381
+ assert_equal 1, t.process(1)
382
+ end
383
+
384
+ #
385
+ # synchronize tests
386
+ #
387
+
388
+ def test_tasks_publically_respond_to_synchronize
389
+ assert t.respond_to?(:synchronize)
390
+ was_in_block = false
391
+ t.synchronize { was_in_block = true }
392
+ assert was_in_block
393
+ end
394
+
395
+ def test_duplicate_tasks_are_monitored_separately
396
+ extended_test do
397
+ count = 0
398
+ max_count = 0
399
+
400
+ t1 = Task.new do |task, inputs|
401
+ task.synchronize do
402
+ count += 1
403
+
404
+ # max count will be 2 if both tasks execute
405
+ # simultaneously (ie they are monitored
406
+ # separately)
407
+ max_count = count if count > max_count
408
+ sleep 0.1
409
+ count -= 1
410
+ end
411
+ end
412
+ t2 = t1.dup
413
+
414
+ th_1 = Thread.new { t1.execute nil }
415
+ th_2 = Thread.new { t2.execute nil }
416
+
417
+ th_1.join
418
+ th_2.join
419
+
420
+ assert_equal 0, count
421
+ assert_equal 2, max_count
422
+ end
423
+ end
424
+ end
@@ -0,0 +1,3 @@
1
+ some
2
+ multiline file
3
+ content!
@@ -0,0 +1,3 @@
1
+ some
2
+ multiline file
3
+ content!