scout-gear 7.2.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +51 -6
  3. data/VERSION +1 -1
  4. data/bin/scout +6 -3
  5. data/lib/rbbt-scout.rb +1 -0
  6. data/lib/scout/cmd.rb +1 -1
  7. data/lib/scout/concurrent_stream.rb +33 -29
  8. data/lib/scout/config.rb +1 -1
  9. data/lib/scout/exceptions.rb +1 -0
  10. data/lib/scout/log/color.rb +4 -2
  11. data/lib/scout/log/progress/report.rb +1 -1
  12. data/lib/scout/log/progress/util.rb +71 -2
  13. data/lib/scout/log/progress.rb +1 -1
  14. data/lib/scout/log/trap.rb +107 -0
  15. data/lib/scout/log.rb +56 -21
  16. data/lib/scout/meta_extension.rb +13 -6
  17. data/lib/scout/misc/digest.rb +1 -1
  18. data/lib/scout/misc/format.rb +12 -0
  19. data/lib/scout/misc/helper.rb +31 -0
  20. data/lib/scout/misc/insist.rb +1 -1
  21. data/lib/scout/misc/monitor.rb +12 -1
  22. data/lib/scout/misc/system.rb +10 -0
  23. data/lib/scout/misc.rb +1 -0
  24. data/lib/scout/named_array.rb +65 -3
  25. data/lib/scout/open/lock/lockfile.rb +587 -0
  26. data/lib/scout/open/lock.rb +28 -2
  27. data/lib/scout/open/remote.rb +4 -0
  28. data/lib/scout/open/stream.rb +111 -42
  29. data/lib/scout/open/util.rb +13 -3
  30. data/lib/scout/path/find.rb +9 -1
  31. data/lib/scout/path/util.rb +35 -0
  32. data/lib/scout/persist/serialize.rb +18 -5
  33. data/lib/scout/persist.rb +60 -30
  34. data/lib/scout/resource/path.rb +53 -0
  35. data/lib/scout/resource/produce.rb +0 -8
  36. data/lib/scout/resource/util.rb +2 -1
  37. data/lib/scout/semaphore.rb +8 -1
  38. data/lib/scout/tmpfile.rb +7 -8
  39. data/lib/scout/tsv/attach.rb +177 -0
  40. data/lib/scout/tsv/change_id.rb +40 -0
  41. data/lib/scout/tsv/dumper.rb +85 -54
  42. data/lib/scout/tsv/index.rb +188 -20
  43. data/lib/scout/tsv/open.rb +182 -0
  44. data/lib/scout/tsv/parser.rb +200 -118
  45. data/lib/scout/tsv/path.rb +5 -6
  46. data/lib/scout/tsv/persist/adapter.rb +26 -37
  47. data/lib/scout/tsv/persist/fix_width_table.rb +327 -0
  48. data/lib/scout/tsv/persist/serialize.rb +117 -0
  49. data/lib/scout/tsv/persist/tokyocabinet.rb +6 -3
  50. data/lib/scout/tsv/persist.rb +4 -2
  51. data/lib/scout/tsv/transformer.rb +141 -0
  52. data/lib/scout/tsv/traverse.rb +136 -37
  53. data/lib/scout/tsv/util/filter.rb +312 -0
  54. data/lib/scout/tsv/util/process.rb +73 -0
  55. data/lib/scout/tsv/util/reorder.rb +81 -0
  56. data/lib/scout/tsv/util/select.rb +265 -0
  57. data/lib/scout/tsv/util/unzip.rb +86 -0
  58. data/lib/scout/tsv/util.rb +126 -19
  59. data/lib/scout/tsv.rb +28 -5
  60. data/lib/scout/work_queue/socket.rb +6 -1
  61. data/lib/scout/work_queue/worker.rb +5 -2
  62. data/lib/scout/work_queue.rb +15 -8
  63. data/lib/scout/workflow/definition.rb +29 -2
  64. data/lib/scout/workflow/step/dependencies.rb +24 -4
  65. data/lib/scout/workflow/step/info.rb +40 -5
  66. data/lib/scout/workflow/step/progress.rb +14 -0
  67. data/lib/scout/workflow/step/provenance.rb +8 -7
  68. data/lib/scout/workflow/step/status.rb +45 -0
  69. data/lib/scout/workflow/step.rb +104 -33
  70. data/lib/scout/workflow/task/inputs.rb +14 -20
  71. data/lib/scout/workflow/task.rb +86 -47
  72. data/lib/scout/workflow/usage.rb +10 -6
  73. data/scout-gear.gemspec +30 -3
  74. data/scout_commands/workflow/task +37 -9
  75. data/scout_commands/workflow/task_old +2 -2
  76. data/test/scout/open/test_stream.rb +61 -59
  77. data/test/scout/path/test_find.rb +10 -1
  78. data/test/scout/resource/test_produce.rb +15 -0
  79. data/test/scout/test_meta_extension.rb +25 -0
  80. data/test/scout/test_named_array.rb +18 -0
  81. data/test/scout/test_persist.rb +67 -0
  82. data/test/scout/test_tmpfile.rb +1 -1
  83. data/test/scout/test_tsv.rb +222 -3
  84. data/test/scout/test_work_queue.rb +21 -18
  85. data/test/scout/tsv/persist/test_adapter.rb +11 -1
  86. data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
  87. data/test/scout/tsv/persist/test_tokyocabinet.rb +29 -1
  88. data/test/scout/tsv/test_attach.rb +227 -0
  89. data/test/scout/tsv/test_change_id.rb +98 -0
  90. data/test/scout/tsv/test_dumper.rb +1 -1
  91. data/test/scout/tsv/test_index.rb +127 -3
  92. data/test/scout/tsv/test_open.rb +167 -0
  93. data/test/scout/tsv/test_parser.rb +45 -3
  94. data/test/scout/tsv/test_persist.rb +9 -0
  95. data/test/scout/tsv/test_transformer.rb +108 -0
  96. data/test/scout/tsv/test_traverse.rb +195 -3
  97. data/test/scout/tsv/test_util.rb +24 -0
  98. data/test/scout/tsv/util/test_filter.rb +188 -0
  99. data/test/scout/tsv/util/test_process.rb +47 -0
  100. data/test/scout/tsv/util/test_reorder.rb +94 -0
  101. data/test/scout/tsv/util/test_select.rb +58 -0
  102. data/test/scout/tsv/util/test_unzip.rb +112 -0
  103. data/test/scout/work_queue/test_socket.rb +0 -1
  104. data/test/scout/work_queue/test_worker.rb +63 -6
  105. data/test/scout/workflow/step/test_load.rb +3 -3
  106. data/test/scout/workflow/step/test_status.rb +31 -0
  107. data/test/scout/workflow/task/test_inputs.rb +14 -14
  108. data/test/scout/workflow/test_step.rb +13 -13
  109. data/test/scout/workflow/test_task.rb +168 -32
  110. data/test/scout/workflow/test_usage.rb +33 -6
  111. data/test/test_helper.rb +3 -1
  112. metadata +29 -2
@@ -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,45 @@ k a|A b|B
170
171
 
171
172
  assert_equal [["k", [%w(b B)]]], values
172
173
  end
174
+
175
+ def test_parser_traverse_all
176
+ content =<<-EOF
177
+ Key ValueA ValueB
178
+ k a|A b|B
179
+ EOF
180
+ content = StringIO.new content
181
+
182
+ parser = TSV::Parser.new content, sep: " ", header_hash: ''
183
+
184
+ assert_equal "Key", parser.key_field
185
+
186
+ values = []
187
+ parser.traverse key_field: "ValueA", fields: :all, type: :double do |k,v|
188
+ values << v
189
+ end
190
+
191
+ assert_include values.flatten, 'a'
192
+ end
193
+
194
+
195
+ def test_parse_persist_serializer
196
+ content =<<-EOF
197
+ Key ValueA ValueB
198
+ k 1 2
199
+ EOF
200
+ content = StringIO.new content
201
+
202
+ TmpFile.with_file do |db|
203
+ data = ScoutCabinet.open db, true, "HDB"
204
+ TSV.parse content, sep: " ", header_hash: '', data: data, cast: :to_i, type: :list
205
+ assert_equal [1, 2], data["k"]
206
+ end
207
+
208
+ TmpFile.with_file do |db|
209
+ content.rewind
210
+ data = ScoutCabinet.open db, true, "HDB"
211
+ TSV.parse content, sep: " ", header_hash: '', data: data, cast: :to_i, type: :list, serializer: :float_array
212
+ assert_equal [1.0, 2.0], data["k"]
213
+ end
214
+ end
173
215
  end
@@ -14,6 +14,15 @@ row2 a a id3
14
14
  EOF
15
15
 
16
16
 
17
+ tsv = Persist.persist("TEST Persist TSV", :tsv) do
18
+ TmpFile.with_file(content) do |filename|
19
+ TSV.open(filename)
20
+ end
21
+ end
22
+
23
+ assert_include tsv.keys, 'row1'
24
+ assert_include tsv.keys, 'row2'
25
+
17
26
  tsv = Persist.persist("TEST Persist TSV", :tsv) do
18
27
  TmpFile.with_file(content) do |filename|
19
28
  TSV.open(filename)
@@ -0,0 +1,108 @@
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 TestTSVTransformer < Test::Unit::TestCase
6
+ def test_traverse
7
+ content =<<-EOF
8
+ #: :sep=" "
9
+ #ID ValueA ValueB
10
+ row1 A1|A11 B1|B11
11
+ row2 A2|A22 B2|B22
12
+ EOF
13
+
14
+ TmpFile.with_file(content) do |file|
15
+ parser = TSV::Parser.new file
16
+ dumper = TSV::Dumper.new :key_field => "Key", :fields => ["Values"], type: :flat
17
+ dumper.init
18
+
19
+ trans = TSV::Transformer.new parser, dumper
20
+ dumper = trans.traverse do |k,values|
21
+ [k, values.flatten]
22
+ end
23
+
24
+ tsv = trans.tsv
25
+ assert_equal %w(A1 A11 B1 B11), tsv['row1']
26
+ end
27
+ end
28
+
29
+ def test_each
30
+ content =<<-EOF
31
+ #: :sep=" "
32
+ #ID ValueA ValueB
33
+ row1 A1|A11 B1|B11
34
+ row2 A2|A22 B2|B22
35
+ EOF
36
+
37
+ TmpFile.with_file(content) do |file|
38
+ parser = TSV::Parser.new file
39
+ dumper = TSV::Dumper.new :key_field => "Key", :fields => ["Values"], type: :flat
40
+ dumper.init
41
+
42
+ trans = TSV::Transformer.new parser, dumper
43
+ dumper = trans.each do |k,values|
44
+ values.replace values.flatten
45
+ end
46
+
47
+ trans["row3"] = %w(A3 A33)
48
+
49
+ tsv = trans.tsv
50
+ assert_equal %w(A1 A11 B1 B11), tsv['row1']
51
+ assert_equal %w(A3 A33), tsv['row3']
52
+ end
53
+ end
54
+
55
+ def test_no_dumper_no_parser
56
+ content =<<-EOF
57
+ #: :sep=" "
58
+ #ID ValueA ValueB
59
+ row1 A1|A11 B1|B11
60
+ row2 A2|A22 B2|B22
61
+ EOF
62
+
63
+ TmpFile.with_file(content) do |file|
64
+ trans = TSV::Transformer.new file
65
+ trans.key_field = "Key"
66
+ trans.fields = ["Values"]
67
+ trans.type = :flat
68
+ trans.sep = "\t"
69
+
70
+
71
+ trans["row3"] = %w(A3 A33)
72
+
73
+ trans.each do |k,values|
74
+ values.replace values.flatten
75
+ end
76
+
77
+ tsv = trans.tsv
78
+ assert_equal %w(A1 A11 B1 B11), tsv['row1']
79
+ assert_equal %w(A3 A33), tsv['row3']
80
+ end
81
+ end
82
+
83
+ def test_to_list
84
+ content =<<-EOF
85
+ #: :sep=" "
86
+ #ID ValueA ValueB
87
+ row1 A1|A11 B1|B11
88
+ row2 A2|A22 B2|B22
89
+ EOF
90
+
91
+ tsv = TSV.open(content)
92
+ assert_equal "A1", tsv.to_list["row1"]["ValueA"]
93
+ assert_equal "B2", tsv.to_list["row2"]["ValueB"]
94
+ end
95
+
96
+ def test_to_single
97
+ content =<<-EOF
98
+ #: :sep=" "
99
+ #ID ValueA ValueB
100
+ row1 A1|A11 B1|B11
101
+ row2 A2|A22 B2|B22
102
+ EOF
103
+
104
+ tsv = TSV.open(content)
105
+ assert_equal "A1", tsv.to_single["row1"]
106
+ assert_equal "A2", tsv.to_single["row2"]
107
+ end
108
+ end
@@ -1,9 +1,201 @@
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
+ tsv = TmpFile.with_file(content) do |filename|
17
+ TSV.open(filename, :persist => true)
18
+ end
19
+
20
+ res = {}
21
+ tsv.traverse :key, %w(OtherID ValueB) do |k,v|
22
+ res[k] = v
23
+ end
24
+ assert_equal [%w(Id3 Id33), %w(B BB)], res["row2"]
25
+
26
+ res = {}
27
+ tsv.traverse :key, %w(OtherID ValueB), type: :list do |k,v|
28
+ res[k] = v
29
+ end
30
+ assert_equal ["Id3", "B"], res["row2"]
31
+
32
+ res = {}
33
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: :strict do |k,v|
34
+ res[k] = v
35
+ end
36
+ assert_equal [[nil], %w(BB)], res["Id33"]
37
+
38
+ res = {}
39
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: :strict, type: :list do |k,v|
40
+ res[k] = v
41
+ end
42
+ assert_equal ["row2", "B"], res["Id3"]
43
+ assert_equal [nil, "BB"], res["Id33"]
44
+
45
+ res = {}
46
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: true, type: :list do |k,v|
47
+ res[k] = v
48
+ end
49
+ assert_equal ["row2", "B"], res["Id3"]
50
+ assert_equal ["row2", "BB"], res["Id33"]
51
+
52
+
53
+ tsv.traverse "OtherID", %w(Id ValueB), one2one: false, type: :list do |k,v|
54
+ res[k] = v
55
+ end
56
+ assert_equal ["row2", "B"], res["Id3"]
57
+ assert_equal [nil, "BB"], res["Id33"]
58
+
59
+ res = {}
60
+ key_name, field_names = tsv.traverse "OtherID" do |k,v|
61
+ res[k] = v
62
+ end
63
+ assert_equal "OtherID", key_name
64
+ assert_equal %w(Id ValueA ValueB), field_names
65
+ end
66
+
67
+ def test_tsv_traverse_all
68
+ content =<<-'EOF'
69
+ #: :sep=/\s+/#:type=:double
70
+ #Id ValueA ValueB OtherID
71
+ row1 a|aa|aaa b Id1|Id2
72
+ row2 A B Id3
73
+ row2 AA BB Id33
74
+ EOF
75
+
76
+ tsv = TmpFile.with_file(content) do |filename|
77
+ TSV.open(filename, :persist => true)
78
+ end
79
+
80
+ all_values = []
81
+ tsv.traverse "ValueA", :all do |k,v|
82
+ all_values.concat(v)
83
+ end
84
+ assert_include all_values.flatten, "row1"
85
+ assert_include all_values.flatten, "a"
86
+ assert_include all_values.flatten, "aaa"
87
+
88
+ all_values = []
89
+ tsv.traverse "Id", :all do |k,v|
90
+ all_values.concat(v)
91
+ end
92
+ assert_include all_values.flatten, "row1"
93
+ assert_include all_values.flatten, "a"
94
+ assert_include all_values.flatten, "aaa"
95
+ end
96
+
97
+ def test_tsv_traverse_list
98
+ content =<<-'EOF'
99
+ #: :sep=/\s+/#:type=:list
100
+ #Id ValueA ValueB OtherID
101
+ row1 a b Id1
102
+ row2 A B Id3
103
+ EOF
104
+
105
+ tsv = TmpFile.with_file(content) do |filename|
106
+ TSV.open(filename, :persist => true)
107
+ end
108
+
109
+ res = {}
110
+ tsv.traverse :key, %w(OtherID ValueB) do |k,v|
111
+ res[k] = v
112
+ end
113
+ assert_equal ["Id3", "B"], res["row2"]
114
+
115
+ res = {}
116
+ tsv.traverse :key, %w(OtherID ValueB), type: :double do |k,v|
117
+ res[k] = v
118
+ end
119
+ assert_equal [%w(Id3), %w(B)], res["row2"]
120
+
121
+ res = {}
122
+ tsv.traverse :key, %w(OtherID ValueB), type: :flat do |k,v|
123
+ res[k] = v
124
+ end
125
+ assert_equal %w(Id3 B), res["row2"]
126
+ end
127
+
128
+ def test_tsv_traverse_single
129
+ content =<<-'EOF'
130
+ #: :sep=/\s+/#:type=:single
131
+ #Id ValueA
132
+ row1 a
133
+ row2 A
134
+ EOF
135
+
136
+ tsv = TmpFile.with_file(content) do |filename|
137
+ TSV.open(filename, :persist => true)
138
+ end
139
+
140
+ res = {}
141
+ tsv.traverse "ValueA", %w(Id) do |k,v|
142
+ res[k] = v
143
+ end
144
+ assert_equal "row1", res["a"]
145
+
146
+ res = {}
147
+ tsv.traverse "ValueA", %w(Id), type: :double do |k,v|
148
+ res[k] = v
149
+ end
150
+ assert_equal [["row1"]], res["a"]
151
+ end
152
+
153
+ def test_traverse_reorder_one2one
154
+ content =<<-'EOF'
155
+ #: :sep=" "
156
+ #ID ValueA ValueB
157
+ row1 A1|A11 B1|B11
158
+ row2 A2|A22 B2|B22
159
+ EOF
160
+
161
+ tsv = TmpFile.with_file(content) do |filename|
162
+ TSV.open(filename, :persist => true)
163
+ end
164
+
165
+ res = {}
166
+ tsv.traverse "ValueA", one2one: true do |k,v|
167
+ res[k] = v
168
+ end
169
+
170
+ assert_include res["A2"][0], "row2"
171
+
172
+ end
173
+
174
+ def test_traverse_select
175
+ content =<<-'EOF'
176
+ #: :sep=" "
177
+ #ID ValueA ValueB
178
+ row1 A1|A11 B1|B11
179
+ row2 A2|A22 B2|B22
180
+ EOF
181
+
182
+ TmpFile.with_file(content) do |filename|
183
+ tsv = TSV.open(filename, :persist => true, select: "B1")
184
+
185
+ assert_equal %w(row1), tsv.keys
186
+
187
+ tsv = TSV.open(filename, :persist => true, select: "B2")
188
+
189
+ assert_equal %w(row2), tsv.keys
190
+
191
+ tsv = TSV.open(filename, :persist => true, select: "B1")
192
+
193
+ assert_equal %w(row1), tsv.keys
194
+
195
+ tsv = TSV.open(filename, :persist => true, select: "B2")
196
+
197
+ assert_equal %w(row2), tsv.keys
198
+ end
7
199
  end
8
200
  end
9
201
 
@@ -0,0 +1,24 @@
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
+ assert "row1", tsv["row1"].key
21
+ end
22
+
23
+ end
24
+
@@ -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
+