rbbt-util 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,19 +4,19 @@ require 'test/unit'
4
4
 
5
5
  class TestMisc < Test::Unit::TestCase
6
6
 
7
- def test_pdf2text_example
7
+ def _test_pdf2text_example
8
8
  assert PDF2Text.pdf2text(test_datafile('example.pdf')).read =~ /An Example Paper/i
9
9
  end
10
10
 
11
- def test_pdf2text_EPAR
11
+ def _test_pdf2text_EPAR
12
12
  assert PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB/document_library/EPAR_-_Scientific_Discussion/human/000402/WC500033103.pdf").read =~ /Tamiflu/i
13
13
  end
14
14
 
15
- def test_pdf2text_wrong
15
+ def _test_pdf2text_wrong
16
16
  assert_raise CMD::CMDError do PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB#") end
17
17
  end
18
18
 
19
- def test_string2hash
19
+ def _test_string2hash
20
20
  assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
21
21
  assert(Misc.string2hash(":true")[:true] == true)
22
22
  assert(Misc.string2hash("true")["true"] == true)
@@ -27,17 +27,17 @@ class TestMisc < Test::Unit::TestCase
27
27
  assert(Misc.string2hash("a=b#c=d#:h=:j")[:h] == :j)
28
28
  end
29
29
 
30
- def test_named_array
30
+ def _test_named_array
31
31
  a = NamedArray.name([1,2,3,4], %w(a b c d))
32
32
  assert_equal(1, a['a'])
33
33
  end
34
34
 
35
- def test_path_relative_to
35
+ def _test_path_relative_to
36
36
  assert_equal "test/foo", Misc.path_relative_to('test/test/foo', 'test')
37
37
  end
38
38
 
39
- def test_chunk
40
- test =<<-EOF
39
+ def _test_chunk
40
+ _test =<<-EOF
41
41
  This is an example file. Entries are separated by Entry
42
42
  -- Entry
43
43
  1
@@ -52,7 +52,7 @@ This is an example file. Entries are separated by Entry
52
52
  assert_equal "1\n2\n3", Misc.chunk(test, /^-- Entry/).first.strip
53
53
  end
54
54
 
55
- def test_hash2string
55
+ def _test_hash2string
56
56
  hash = {}
57
57
  assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
58
58
 
@@ -73,11 +73,43 @@ This is an example file. Entries are separated by Entry
73
73
 
74
74
  end
75
75
 
76
- def test_merge
76
+ def _test_merge
77
77
  a = [[1],[2]]
78
78
  a = NamedArray.name a, %w(1 2)
79
79
  a.merge [3,4]
80
80
  assert_equal [1,3], a[0]
81
81
  end
82
82
 
83
+ def _test_indiferent_hash
84
+ a = {:a => 1, "b" => 2}
85
+ a.extend IndiferentHash
86
+
87
+ assert 1, a["a"]
88
+ assert 1, a[:a]
89
+ assert 2, a["b"]
90
+ assert 2, a[:b]
91
+ end
92
+
93
+ def test_lockfile
94
+ TmpFile.with_file do |tmpfile|
95
+ pids = []
96
+ 3.times do |i|
97
+ pids << Process.fork do
98
+ pid = pid.to_s
99
+ Misc.lock(tmpfile, pid) do |f, val|
100
+ Open.write(f, val)
101
+ sleep rand * 2
102
+ if pid == Open.read(tmpfile)
103
+ exit(0)
104
+ else
105
+ exit(1)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ pids.each do |pid| Process.waitpid pid; assert $?.success? end
111
+ end
112
+
113
+ end
114
+
83
115
  end
@@ -27,7 +27,7 @@ class TestTask < Test::Unit::TestCase
27
27
  def test_task_options
28
28
  TmpFile.with_file do |f|
29
29
  task = Task.new(:test_task, nil, :name) do |name| Open.write(f, name) end
30
- job = task.job(:job1, :name => "TestName")
30
+ job = task.job(:job1, "TestName")
31
31
  assert_equal "job1" << "_" << Misc.hash2md5(:name => "TestName"), job.id
32
32
  job.fork
33
33
  job.join
@@ -39,13 +39,13 @@ class TestTask < Test::Unit::TestCase
39
39
 
40
40
  def test_task_result
41
41
  task = Task.new(:test_task, nil, :name) do |name| name end
42
- job = task.job(:job1, :name => "TestName")
42
+ job = task.job(:job1, "TestName")
43
43
  assert_equal "TestName", job.fork.join.load
44
44
  end
45
45
 
46
46
  def test_task_info
47
47
  task = Task.new(:test_task, nil, :name) do |name| name end
48
- job = task.job(:job1, :name => "TestName")
48
+ job = task.job(:job1, "TestName")
49
49
  assert_equal "TestName", job.fork.join.info[:options][:name]
50
50
  end
51
51
 
@@ -54,15 +54,15 @@ class TestTask < Test::Unit::TestCase
54
54
  step :one
55
55
  name
56
56
  end
57
- job = task.job(:job1, :name => "TestName")
57
+ job = task.job(:job1, "TestName")
58
58
  assert_equal "TestName", job.fork.join.info[:options][:name]
59
59
  end
60
60
 
61
61
  def test_task_reopen
62
62
  task = Task.new(:test_task, nil, :name) do |name| name end
63
- job = task.job(:job1, :name => "TestName")
63
+ job = task.job(:job1, "TestName")
64
64
  assert_equal "TestName", job.fork.join.info[:options][:name]
65
- job = task.job(:job1, :name => "TestName")
65
+ job = task.job(:job1, "TestName")
66
66
  assert_equal "TestName", job.join.info[:options][:name]
67
67
  end
68
68
 
@@ -114,5 +114,6 @@ class TestTask < Test::Unit::TestCase
114
114
  job.clean
115
115
  assert (not File.exists?(job.path))
116
116
  end
117
+
117
118
  end
118
119
 
@@ -61,9 +61,27 @@ class TestTCHash < Test::Unit::TestCase
61
61
  t["2"] = [[3],[4,5]]
62
62
 
63
63
  t = TCHash.get f
64
- t.collect do |k,v|
65
- assert_equal [["3"],["4","5"]], t["2"]
64
+ assert_equal [["3"],["4","5"]], t["2"]
65
+ end
66
+ end
67
+
68
+ def test_non_blocking
69
+ TmpFile.with_file do |f|
70
+ t = TCHash.get f, true, :double
71
+ t["1"] = [[1],[2]]
72
+ t["2"] = [[3],[4,5]]
73
+ t.close
74
+
75
+ pid = Process.fork do
76
+ t2 = TCHash.get f, true, :double
77
+ assert_equal [["3"],["4","5"]], t2["2"]
78
+ exit
66
79
  end
80
+
81
+ t2 = TCHash.get f, true, :double
82
+ assert_equal [["3"],["4","5"]], t2["2"]
83
+
84
+ Process.wait pid
67
85
  end
68
86
  end
69
87
  end
@@ -13,7 +13,6 @@ module MathWF
13
13
  self.tasks.each do |name, task| task.workflow = self end
14
14
  end
15
15
 
16
- MathWF.basedir = Rbbt.tmp.test.jobs.mathwf.find :user
17
16
 
18
17
  module MathWF2
19
18
  def mult(num, t)
@@ -22,6 +21,7 @@ module MathWF2
22
21
 
23
22
  extend WorkFlow
24
23
 
24
+
25
25
  task_option :value
26
26
  task :input => :integer do |value| value end
27
27
 
@@ -35,29 +35,51 @@ module MathWF2
35
35
  task_option :times, "Times to multiply by", :integer, 10
36
36
  task_dependencies :add_1
37
37
  task :times => :integer do |times| mult(input, times) end
38
+
39
+ task_dependencies []
40
+ task :persist do task.workflow.methods.include? "local_persist" end
41
+ end
42
+
43
+
44
+ module ConWF
45
+ extend WorkFlow
46
+ task :one => :integer do 1 end
47
+
48
+ task_dependencies []
49
+ task :two => :integer do 2 end
50
+
51
+ task_option :init, "Initial value", :string
52
+ task_dependencies Proc.new{|jobname,run_options|
53
+ ConWF.job(run_options[:init].to_sym, jobname, {})
54
+ }
55
+ task :times_2 => :integer do
56
+ input * 2
57
+ end
38
58
  end
39
59
 
40
60
  MathWF2.jobdir = Rbbt.tmp.test.jobs.mathwf.find :user
61
+ MathWF.jobdir = Rbbt.tmp.test.jobs.mathwf.find :user
62
+ ConWF.jobdir = Rbbt.tmp.test.jobs.mathwf.find :user
41
63
 
42
64
  class TestWorkFlow < Test::Unit::TestCase
43
65
 
44
66
  def test_math_wf
45
- job = MathWF.tasks[:times_2].job(:job1, :value => 1)
67
+ job = MathWF.tasks[:times_2].job(:job1, 1)
46
68
  assert_equal 4, job.fork.join.load
47
- job = MathWF.tasks[:times_4].job(:job1, :value => 1)
69
+ job = MathWF.tasks[:times_4].job(:job1, 1)
48
70
  assert_equal 8, job.fork.join.load
49
71
  end
50
72
 
51
73
  def test_math_wf2
52
- job = MathWF2.tasks[:times_2].job(:job1, :value => 1)
74
+ job = MathWF2.tasks[:times_2].job(:job1, 1)
53
75
  job.fork.join
54
76
  assert_equal 4, job.load
55
- job = MathWF2.tasks[:times_4].job(:job1, :value => 1)
77
+ job = MathWF2.tasks[:times_4].job(:job1, 1)
56
78
  assert_equal 8, job.fork.join.load
57
79
  end
58
80
 
59
81
  def test_math_run
60
- job = MathWF2.job(:times_2, :job1,1)
82
+ job = MathWF2.job(:times_2, :job1, 1)
61
83
  job.fork.join
62
84
  assert_equal 4, job.load
63
85
  end
@@ -84,10 +106,18 @@ class TestWorkFlow < Test::Unit::TestCase
84
106
  assert File.exists?(job.path)
85
107
  job.clean
86
108
  assert (not File.exists?(job.path))
87
- assert File.exists?(job.dependencies.first.first.path)
109
+ assert File.exists?(job.previous_jobs.first.path)
88
110
  job.recursive_clean
89
- assert (not File.exists?(job.dependencies.first.first.path))
111
+ assert (not File.exists?(job.previous_jobs.first.path))
90
112
  end
91
113
 
114
+ def test_local_persist
115
+ assert MathWF2.run(:persist, :persist).load
116
+ end
117
+
118
+ def test_conditional
119
+ assert 2, ConWF.run(:times_2, "Test", "one").load
120
+ assert 4, ConWF.run(:times_2, "Test", "two").load
121
+ end
92
122
  end
93
123
 
@@ -352,5 +352,22 @@ row6,dd,dd,ee,,
352
352
  end
353
353
 
354
354
  end
355
+
356
+ def test_merge_rows
357
+ file1 =<<-EOF
358
+ row1,a,b,c
359
+ row1,aa,bb,cc
360
+ row2,A,B,C
361
+ row3,1,2,3
362
+ EOF
363
+ TmpFile.with_file(file1) do |input|
364
+ TmpFile.with_file() do |output|
365
+ TSV.merge_rows Open.open(input), output
366
+ assert Open.read(output) =~ /a|aa/
367
+ end
368
+ end
369
+
370
+
371
+ end
355
372
  end
356
373
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 2
10
- version: 3.0.2
9
+ - 3
10
+ version: 3.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Miguel Vazquez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-19 00:00:00 +01:00
18
+ date: 2011-03-23 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -88,6 +88,20 @@ dependencies:
88
88
  version: "0"
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: lockfile
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ version_requirements: *id006
91
105
  description: Utilities for handling tsv files, caches, etc
92
106
  email: miguel.vazquez@fdi.ucm.es
93
107
  executables:
@@ -119,6 +133,7 @@ files:
119
133
  - lib/rbbt/util/simpleDSL.rb
120
134
  - lib/rbbt/util/simpleopt.rb
121
135
  - lib/rbbt/util/task.rb
136
+ - lib/rbbt/util/task/job.rb
122
137
  - lib/rbbt/util/tc_hash.rb
123
138
  - lib/rbbt/util/tmpfile.rb
124
139
  - lib/rbbt/util/tsv.rb