scout-gear 7.2.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +37 -3
  3. data/VERSION +1 -1
  4. data/lib/scout/concurrent_stream.rb +9 -8
  5. data/lib/scout/exceptions.rb +1 -0
  6. data/lib/scout/log/color.rb +0 -1
  7. data/lib/scout/log/progress/util.rb +65 -0
  8. data/lib/scout/misc/helper.rb +31 -0
  9. data/lib/scout/misc/monitor.rb +1 -1
  10. data/lib/scout/misc.rb +1 -0
  11. data/lib/scout/open/stream.rb +21 -27
  12. data/lib/scout/persist.rb +42 -28
  13. data/lib/scout/semaphore.rb +8 -1
  14. data/lib/scout/tsv/dumper.rb +13 -8
  15. data/lib/scout/tsv/index.rb +127 -15
  16. data/lib/scout/tsv/open.rb +128 -0
  17. data/lib/scout/tsv/parser.rb +70 -43
  18. data/lib/scout/tsv/path.rb +4 -4
  19. data/lib/scout/tsv/persist/adapter.rb +52 -33
  20. data/lib/scout/tsv/persist/fix_width_table.rb +324 -0
  21. data/lib/scout/tsv/persist/serialize.rb +117 -0
  22. data/lib/scout/tsv/persist/tokyocabinet.rb +3 -3
  23. data/lib/scout/tsv/persist.rb +0 -2
  24. data/lib/scout/tsv/traverse.rb +130 -35
  25. data/lib/scout/tsv/util/filter.rb +303 -0
  26. data/lib/scout/tsv/util/process.rb +73 -0
  27. data/lib/scout/tsv/util/select.rb +220 -0
  28. data/lib/scout/tsv/util.rb +77 -19
  29. data/lib/scout/tsv.rb +2 -2
  30. data/lib/scout/work_queue/worker.rb +1 -1
  31. data/lib/scout/workflow/definition.rb +8 -0
  32. data/lib/scout/workflow/step/info.rb +4 -0
  33. data/lib/scout/workflow/step/progress.rb +14 -0
  34. data/lib/scout/workflow/step.rb +10 -5
  35. data/lib/scout/workflow/task.rb +8 -4
  36. data/lib/scout/workflow/usage.rb +2 -0
  37. data/scout-gear.gemspec +33 -10
  38. data/scout_commands/workflow/task +3 -2
  39. data/scout_commands/workflow/task_old +2 -2
  40. data/test/scout/open/test_stream.rb +1 -1
  41. data/test/scout/test_persist.rb +61 -0
  42. data/test/scout/test_tmpfile.rb +1 -1
  43. data/test/scout/test_tsv.rb +10 -1
  44. data/test/scout/test_work_queue.rb +1 -0
  45. data/test/scout/tsv/persist/test_adapter.rb +10 -0
  46. data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
  47. data/test/scout/tsv/test_index.rb +94 -2
  48. data/test/scout/tsv/test_open.rb +9 -0
  49. data/test/scout/tsv/test_parser.rb +28 -3
  50. data/test/scout/tsv/test_persist.rb +7 -0
  51. data/test/scout/tsv/test_traverse.rb +110 -3
  52. data/test/scout/tsv/test_util.rb +23 -0
  53. data/test/scout/tsv/util/test_filter.rb +188 -0
  54. data/test/scout/tsv/util/test_process.rb +47 -0
  55. data/test/scout/tsv/util/test_select.rb +44 -0
  56. data/test/scout/work_queue/test_worker.rb +63 -6
  57. data/test/scout/workflow/step/test_load.rb +3 -3
  58. data/test/scout/workflow/test_step.rb +10 -10
  59. data/test/test_helper.rb +3 -1
  60. metadata +19 -6
@@ -1,8 +1,25 @@
1
1
  require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
3
 
4
+ require 'scout/tsv'
4
5
  class TestTSVIndex < Test::Unit::TestCase
5
- def test_true
6
+ def load_segment_data(data)
7
+ tsv = TSV.open(data, type: :list, :sep=>":", :cast => proc{|e| e =~ /(\s*)(_*)/; ($1.length..($1.length + $2.length - 1))})
8
+
9
+ tsv = tsv.add_field "Start" do |key, values|
10
+ values["Range"].first
11
+ end
12
+
13
+ tsv = tsv.add_field "End" do |key, values|
14
+ values["Range"].last
15
+ end
16
+
17
+ tsv = tsv.slice ["Start", "End"]
18
+
19
+ tsv
20
+ end
21
+
22
+ def test_index
6
23
  content =<<-'EOF'
7
24
  #: :sep=/\s+/#:type=:double#:merge=:concat
8
25
  #Id ValueA ValueB OtherID
@@ -20,12 +37,34 @@ row2 a b id3
20
37
  end
21
38
 
22
39
  TmpFile.with_file(content) do |filename|
23
- index = TSV.index(filename, :target => "ValueB", :fields => "OtherID")
40
+ index = TSV.index(filename, :target => "ValueB", :fields => ["OtherID"])
24
41
  assert_equal 'B', index["a"]
25
42
  assert_nil index["B"]
26
43
  end
27
44
  end
28
45
 
46
+ def test_from_tsv
47
+ content =<<-'EOF'
48
+ #: :sep=/\s+/#:type=:double#:merge=:concat
49
+ #Id ValueA ValueB OtherID
50
+ row1 a|aa|aaa b Id1|Id2
51
+ row2 A B Id3|a
52
+ row2 a b id3
53
+ EOF
54
+
55
+ TmpFile.with_file(content) do |filename|
56
+ tsv = TSV.open(filename)
57
+ index = TSV.index(tsv, :target => "ValueB", :fields => "OtherID")
58
+ assert_equal 'B', index["a"]
59
+ assert_nil index["B"]
60
+
61
+ index = tsv.index(:target => "ValueB", :fields => "OtherID")
62
+ assert_equal 'B', index["a"]
63
+ assert_nil index["B"]
64
+ end
65
+ end
66
+
67
+
29
68
  def test_persist
30
69
  content =<<-'EOF'
31
70
  #: :sep=/\s+/#:type=:double#:merge=:concat
@@ -43,6 +82,59 @@ row2 a b id3
43
82
  end
44
83
  end
45
84
 
85
+ def test_range_index
86
+ data =<<-EOF
87
+ # 012345678901234567890
88
+ #ID:Range
89
+ a: ______
90
+ b: ______
91
+ c: _______
92
+ d: ____
93
+ e: ______
94
+ f: ___
95
+ g: ____
96
+ EOF
97
+ TmpFile.with_file(data) do |datafile|
98
+ tsv = load_segment_data(datafile)
99
+ f = tsv.range_index("Start", "End", :persist => true)
100
+
101
+ assert_equal %w(), f[0].sort
102
+ assert_equal %w(b), f[1].sort
103
+ assert_equal %w(), f[20].sort
104
+ assert_equal %w(), f[(20..100)].sort
105
+ assert_equal %w(a b d), f[3].sort
106
+ assert_equal %w(a b c d e), f[(3..4)].sort
107
+ end
108
+ end
109
+
110
+ def test_range_index_persistent
111
+ data =<<-EOF
112
+ # 012345678901234567890
113
+ #ID:Range
114
+ a: ______
115
+ b: ______
116
+ c: _______
117
+ d: ____
118
+ e: ______
119
+ f: ___
120
+ g: ____
121
+ EOF
122
+ TmpFile.with_file(data) do |datafile|
123
+ load_segment_data(datafile)
124
+ TmpFile.with_file(load_segment_data(datafile).to_s) do |tsvfile|
125
+ f = TSV.range_index(tsvfile, "Start", "End", :persist => true)
126
+
127
+ assert_equal %w(), f[0].sort
128
+ assert_equal %w(b), f[1].sort
129
+ assert_equal %w(), f[20].sort
130
+ assert_equal %w(), f[(20..100)].sort
131
+ assert_equal %w(a b d), f[3].sort
132
+ assert_equal %w(a b c d e), f[(3..4)].sort
133
+ end
134
+ end
135
+ end
136
+
137
+
46
138
  def __test_speed
47
139
  content =<<-'EOF'
48
140
  #: :sep=/\s+/#:type=:double#:merge=:concat
@@ -0,0 +1,9 @@
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 TestOpenTraverse < Test::Unit::TestCase
5
+ def test_true
6
+ assert true
7
+ end
8
+ end
9
+
@@ -29,15 +29,16 @@ class TestTSVParser < Test::Unit::TestCase
29
29
  assert_equal (1..10).collect{|v| [v,v] }, values
30
30
  end
31
31
 
32
- def __test_benchmark
32
+ def ___test_benchmark
33
33
  num = 10_000
34
34
  txt = num.times.inject(nil) do |acc,i|
35
35
  (acc.nil? ? "" : acc << "\n") << (0..10).collect{|v| v == 0 ? i : [v,v] * "|" } * "\t"
36
36
  end
37
37
 
38
38
  txt = StringIO.new(([txt] * (10))*"\n")
39
- Misc.benchmark 1 do
40
- #Misc.profile do
39
+ Misc.benchmark 5 do
40
+ txt.rewind
41
+ #Misc.profile do
41
42
  data = TSV.parse_stream(txt, fix: true, type: :double, bar: true, merge: :concat)
42
43
  assert_equal num, data.size
43
44
  assert_equal 20, data['1'][0].length
@@ -170,4 +171,28 @@ k a|A b|B
170
171
 
171
172
  assert_equal [["k", [%w(b B)]]], values
172
173
  end
174
+
175
+
176
+ def test_parse_persist_serializer
177
+ content =<<-EOF
178
+ Key ValueA ValueB
179
+ k 1 2
180
+ EOF
181
+ content = StringIO.new content
182
+
183
+ TmpFile.with_file do |db|
184
+ data = ScoutCabinet.open db, true, "HDB"
185
+ TSV.parse content, sep: " ", header_hash: '', data: data, cast: :to_i, type: :list
186
+ assert_equal [1, 2], data["k"]
187
+ end
188
+
189
+ TmpFile.with_file do |db|
190
+ content.rewind
191
+ data = ScoutCabinet.open db, true, "HDB"
192
+ TSV.parse content, sep: " ", header_hash: '', data: data, cast: :to_i, type: :list, serializer: :float_array
193
+ assert_equal [1.0, 2.0], data["k"]
194
+ end
195
+
196
+ end
197
+
173
198
  end
@@ -23,6 +23,13 @@ row2 a a id3
23
23
  assert_include tsv.keys, 'row1'
24
24
  assert_include tsv.keys, 'row2'
25
25
 
26
+ tsv = Persist.persist("TEST Persist TSV", :tsv) do
27
+ TmpFile.with_file(content) do |filename|
28
+ TSV.open(filename)
29
+ end
30
+ end
31
+
32
+
26
33
  assert_nothing_raised do
27
34
  tsv = Persist.persist("TEST Persist TSV", :tsv) do
28
35
  raise
@@ -1,9 +1,116 @@
1
1
  require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
3
 
4
- class TestClass < Test::Unit::TestCase
5
- def test_true
6
- assert true
4
+ require 'scout/tsv'
5
+
6
+ class TestTSVTraverse < Test::Unit::TestCase
7
+ def test_tsv_traverse_double
8
+ content =<<-'EOF'
9
+ #: :sep=/\s+/#:type=:double
10
+ #Id ValueA ValueB OtherID
11
+ row1 a|aa|aaa b Id1|Id2
12
+ row2 A B Id3
13
+ row2 AA BB Id33
14
+ EOF
15
+
16
+ sss 0
17
+ tsv = TmpFile.with_file(content) do |filename|
18
+ TSV.open(filename, :persist => true)
19
+ end
20
+
21
+ res = {}
22
+ tsv.traverse :key, %w(OtherID ValueB) do |k,v|
23
+ res[k] = v
24
+ end
25
+ assert_equal [%w(Id3 Id33), %w(B BB)], res["row2"]
26
+
27
+ res = {}
28
+ tsv.traverse :key, %w(OtherID ValueB), type: :list do |k,v|
29
+ res[k] = v
30
+ end
31
+ assert_equal ["Id3", "B"], res["row2"]
32
+
33
+ res = {}
34
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: true do |k,v|
35
+ res[k] = v
36
+ end
37
+ assert_equal [[nil], %w(BB)], res["Id33"]
38
+
39
+ res = {}
40
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: true, type: :list do |k,v|
41
+ res[k] = v
42
+ end
43
+ assert_equal ["row2", "B"], res["Id3"]
44
+ assert_equal [nil, "BB"], res["Id33"]
45
+
46
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: false, type: :list do |k,v|
47
+ res[k] = v
48
+ end
49
+ assert_equal ["row2", "B"], res["Id3"]
50
+ assert_equal [nil, "BB"], res["Id33"]
51
+
52
+ res = {}
53
+ key_name, field_names = tsv.traverse "OtherID" do |k,v|
54
+ res[k] = v
55
+ end
56
+ assert_equal "OtherID", key_name
57
+ assert_equal %w(Id ValueA ValueB), field_names
58
+ end
59
+
60
+ def test_tsv_traverse_list
61
+ content =<<-'EOF'
62
+ #: :sep=/\s+/#:type=:list
63
+ #Id ValueA ValueB OtherID
64
+ row1 a b Id1
65
+ row2 A B Id3
66
+ EOF
67
+
68
+ tsv = TmpFile.with_file(content) do |filename|
69
+ TSV.open(filename, :persist => true)
70
+ end
71
+
72
+ res = {}
73
+ tsv.traverse :key, %w(OtherID ValueB) do |k,v|
74
+ res[k] = v
75
+ end
76
+ assert_equal ["Id3", "B"], res["row2"]
77
+
78
+ res = {}
79
+ tsv.traverse :key, %w(OtherID ValueB), type: :double do |k,v|
80
+ res[k] = v
81
+ end
82
+ assert_equal [%w(Id3), %w(B)], res["row2"]
83
+
84
+ res = {}
85
+ tsv.traverse :key, %w(OtherID ValueB), type: :flat do |k,v|
86
+ res[k] = v
87
+ end
88
+ assert_equal %w(Id3 B), res["row2"]
89
+ end
90
+
91
+ def test_tsv_traverse_single
92
+ content =<<-'EOF'
93
+ #: :sep=/\s+/#:type=:single
94
+ #Id ValueA
95
+ row1 a
96
+ row2 A
97
+ EOF
98
+
99
+ tsv = TmpFile.with_file(content) do |filename|
100
+ TSV.open(filename, :persist => true)
101
+ end
102
+
103
+ res = {}
104
+ tsv.traverse "ValueA", %w(Id) do |k,v|
105
+ res[k] = v
106
+ end
107
+ assert_equal "row1", res["a"]
108
+
109
+ res = {}
110
+ tsv.traverse "ValueA", %w(Id), type: :double do |k,v|
111
+ res[k] = v
112
+ end
113
+ assert_equal [["row1"]], res["a"]
7
114
  end
8
115
  end
9
116
 
@@ -0,0 +1,23 @@
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/tsv'
5
+ class TestTSVUtil < Test::Unit::TestCase
6
+ def test_open_persist
7
+ content =<<-'EOF'
8
+ #: :sep=/\s+/#:type=:double#:merge=:concat
9
+ #Id ValueA ValueB OtherID
10
+ row1 a|aa|aaa b Id1|Id2
11
+ row2 A B Id3
12
+ row2 a a id3
13
+ EOF
14
+
15
+ tsv = TmpFile.with_file(content) do |filename|
16
+ TSV.open(filename, :sep => " " )
17
+ end
18
+ assert_equal %w(row1 row2), tsv.collect{|k,v| k }
19
+ assert NamedArray === tsv.collect{|k,v| v }.first
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,188 @@
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/tsv'
5
+ class TestTSVFilters < Test::Unit::TestCase
6
+ def test_collect
7
+ content1 =<<-EOF
8
+ #: :sep=/\\s+/#:case_insensitive=false
9
+ #Id ValueA ValueB
10
+ row1 a|aa|aaa b
11
+ row2 A B
12
+ EOF
13
+
14
+ TmpFile.with_file(content1) do |filename|
15
+ tsv = TSV.open filename
16
+ assert_equal 2, tsv.collect.size
17
+ tsv.filter
18
+ tsv.add_filter "field:ValueA", ["A"]
19
+ assert_equal 1, tsv.collect.size
20
+ end
21
+ end
22
+
23
+ def test_through
24
+ content1 =<<-EOF
25
+ #: :sep=/\\s+/#:case_insensitive=false
26
+ #Id ValueA ValueB
27
+ row1 a|aa|aaa b
28
+ row2 A B
29
+ EOF
30
+
31
+ TmpFile.with_file(content1) do |filename|
32
+ tsv = TSV.open filename
33
+ tsv.filter
34
+ tsv.add_filter "field:ValueA", ["A"]
35
+ elem = []
36
+ tsv.through do |k,v| elem << k end
37
+ assert_equal 1, elem.size
38
+ end
39
+ end
40
+
41
+ def test_2_filters
42
+ content1 =<<-EOF
43
+ #: :sep=/\\s+/#:case_insensitive=false
44
+ #Id ValueA ValueB
45
+ row1 a|aa|aaa b
46
+ row2 A B
47
+ row3 A C
48
+ EOF
49
+
50
+ TmpFile.with_file(content1) do |filename|
51
+ tsv = TSV.open filename
52
+ tsv.filter
53
+ tsv.add_filter "field:ValueA", ["A"]
54
+
55
+ elem = []
56
+ tsv.through do |k,v| elem << k end
57
+ assert_equal 2, elem.size
58
+ assert_equal ["row2", "row3"], elem.sort
59
+
60
+ tsv.add_filter "field:ValueB", ["C"]
61
+
62
+ elem = []
63
+ tsv.through do |k,v| elem << k end
64
+ assert_equal 1, elem.size
65
+ end
66
+ end
67
+
68
+ def test_filter_persistence
69
+ content1 =<<-EOF
70
+ #: :sep=/\\s+/#:case_insensitive=false
71
+ #Id ValueA ValueB
72
+ row1 a|aa|aaa b
73
+ row2 A B
74
+ row3 A C
75
+ EOF
76
+
77
+ TmpFile.with_file(content1) do |filename|
78
+ tsv = TSV.open filename
79
+ tsv.filter
80
+ tsv.add_filter "field:ValueA", ["A"], tmpdir.fieldValueA.find(:user)
81
+
82
+ elem = []
83
+ tsv.through do |k,v| elem << k end
84
+ assert_equal 2, elem.size
85
+
86
+ tsv.add_filter "field:ValueB", ["C"]
87
+
88
+ elem = []
89
+ tsv.through do |k,v| elem << k end
90
+ assert_equal 1, elem.size
91
+
92
+ tsv = TSV.open filename
93
+ tsv.filter
94
+ tsv.add_filter "field:ValueA", ["A"], tmpdir.fieldValueA.find(:user)
95
+
96
+ elem = []
97
+ tsv.through do |k,v| elem << k end
98
+ assert_equal 2, elem.size
99
+ end
100
+ end
101
+
102
+ def __test_filter_persistence_update
103
+ content1 =<<-EOF
104
+ #: :sep=/\\s+/#:case_insensitive=false
105
+ #Id ValueA ValueB
106
+ row1 a|aa|aaa b
107
+ row2 A B
108
+ EOF
109
+
110
+ TmpFile.with_file(content1) do |filename|
111
+ tsv = TSV.open filename
112
+ tsv.filter
113
+ tsv.add_filter "field:ValueA", ["A"], Scout.tmp.test.Filter.fieldValueA.find(:user)
114
+
115
+ elem = []
116
+ tsv.through do |k,v| elem << k end
117
+ assert_equal 1, elem.size
118
+
119
+ tsv["row3"] = [["A"], ["C"]]
120
+
121
+ elem = []
122
+ tsv.through do |k,v| elem << k end
123
+ assert_equal 2, elem.size
124
+
125
+ tsv.add_filter "field:ValueB", ["C"]
126
+
127
+ elem = []
128
+ tsv.through do |k,v| elem << k end
129
+ assert_equal 1, elem.size
130
+
131
+ tsv = TSV.open filename
132
+ tsv.filter
133
+ tsv.add_filter "field:ValueA", ["A"], Scout.tmp.test.Filter.fieldValueA.find(:user)
134
+
135
+ elem = []
136
+ tsv.through do |k,v| elem << k end
137
+ assert_equal 1, elem.size
138
+ end
139
+ end
140
+
141
+ def test_delete
142
+ content =<<-EOF
143
+ #ID ValueA ValueB Comment
144
+ row1 a b c
145
+ row2 A B C
146
+ EOF
147
+
148
+ TmpFile.with_file(content) do |filename|
149
+ tsv = TSV.open(File.open(filename), type: :double, :sep => /\s/)
150
+ assert_equal 2, tsv.keys.length
151
+ tsv.delete "row2"
152
+ assert_equal 1, tsv.keys.length
153
+
154
+ tsv = TSV.open(File.open(filename), type: :double, :sep => /\s/)
155
+ tsv.filter
156
+ tsv.add_filter "field:ValueA", ["A"]
157
+
158
+ assert_equal 1, tsv.keys.length
159
+ assert_equal ["row2"], tsv.keys
160
+
161
+ tsv.delete "row2"
162
+ assert_equal 0, tsv.keys.length
163
+
164
+ tsv.pop_filter
165
+ assert_equal ["row1"], tsv.keys
166
+ end
167
+ end
168
+
169
+ def test_filename
170
+ content1 =<<-EOF
171
+ #: :sep=/\\s+/#:case_insensitive=false
172
+ #Id ValueA ValueB
173
+ row1 a|aa|aaa b
174
+ row2 A B
175
+ EOF
176
+
177
+ TmpFile.with_file(content1) do |filename|
178
+ tsv = TSV.open filename
179
+ tsv.filter
180
+ tsv.add_filter "field:ValueA", ["A"]
181
+ assert tsv.filename =~ /ValueA/
182
+ tsv.pop_filter
183
+ assert tsv.filename !~ /ValueA/
184
+ end
185
+
186
+ end
187
+ end
188
+
@@ -0,0 +1,47 @@
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/tsv'
5
+ class TestTSVProcess < Test::Unit::TestCase
6
+ def test_process
7
+ content =<<-'EOF'
8
+ #: :sep=/\s+/#:type=:double
9
+ #Id ValueA ValueB OtherID
10
+ row1 a|aa|aaa b Id1|Id2
11
+ row2 A B Id3
12
+ row2 AA BB Id33
13
+ EOF
14
+
15
+ tsv = TmpFile.with_file(content) do |filename|
16
+ TSV.open(filename)
17
+ end
18
+
19
+ tsv.process "ValueA" do |v|
20
+ v.collect{|e| e.upcase }
21
+ end
22
+
23
+ assert_equal %w(A AA AAA), tsv["row1"][0]
24
+ end
25
+
26
+ def test_add_field
27
+ content =<<-'EOF'
28
+ #: :sep=/\s+/#:type=:double
29
+ #Id ValueA ValueB OtherID
30
+ row1 a|aa|aaa b Id1|Id2
31
+ row2 A B Id3
32
+ row2 AA BB Id33
33
+ EOF
34
+
35
+ tsv = TmpFile.with_file(content) do |filename|
36
+ TSV.open(filename)
37
+ end
38
+
39
+ tsv.add_field "ValueC" do |k,v|
40
+ v[0].collect{|e| e.gsub("a", "c").gsub("A", "C") }
41
+ end
42
+
43
+ assert_equal %w(c cc ccc), tsv["row1"]["ValueC"]
44
+ assert_equal %w(C CC), tsv["row2"]["ValueC"]
45
+ end
46
+ end
47
+
@@ -0,0 +1,44 @@
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/tsv'
5
+ class TestTSVSelect < Test::Unit::TestCase
6
+ def test_select
7
+ content =<<-'EOF'
8
+ #: :sep=/\s+/#:type=:double
9
+ #Id ValueA ValueB OtherID
10
+ row1 a|aa|aaa b Id1|Id2
11
+ row2 A B Id3
12
+ row2 AA BB Id33
13
+ EOF
14
+
15
+ tsv = TmpFile.with_file(content) do |filename|
16
+ TSV.open(filename, :persist => true)
17
+ end
18
+
19
+ s = tsv.select do |k,v|
20
+ k.include? "2"
21
+ end
22
+
23
+ assert_equal ['row2'], s.keys
24
+ end
25
+
26
+ def test_reorder
27
+ content =<<-'EOF'
28
+ #: :sep=/\s+/#:type=:double
29
+ #Id ValueA ValueB OtherID
30
+ row1 a1|a2 b1|b2 Id1|Id2
31
+ row2 A1|A3 B1|B3 Id1|Id3
32
+ EOF
33
+
34
+ tsv = TmpFile.with_file(content) do |filename|
35
+ TSV.open(filename)
36
+ end
37
+
38
+ r = tsv.reorder "OtherID", %w(ValueB Id)
39
+
40
+ assert_equal %w(row1 row2), r["Id1"]["Id"]
41
+ assert_equal %w(row2), r["Id3"]["Id"]
42
+ end
43
+ end
44
+