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.
- checksums.yaml +4 -4
- data/.vimproject +51 -6
- data/VERSION +1 -1
- data/bin/scout +6 -3
- data/lib/rbbt-scout.rb +1 -0
- data/lib/scout/cmd.rb +1 -1
- data/lib/scout/concurrent_stream.rb +33 -29
- data/lib/scout/config.rb +1 -1
- data/lib/scout/exceptions.rb +1 -0
- data/lib/scout/log/color.rb +4 -2
- data/lib/scout/log/progress/report.rb +1 -1
- data/lib/scout/log/progress/util.rb +71 -2
- data/lib/scout/log/progress.rb +1 -1
- data/lib/scout/log/trap.rb +107 -0
- data/lib/scout/log.rb +56 -21
- data/lib/scout/meta_extension.rb +13 -6
- data/lib/scout/misc/digest.rb +1 -1
- data/lib/scout/misc/format.rb +12 -0
- data/lib/scout/misc/helper.rb +31 -0
- data/lib/scout/misc/insist.rb +1 -1
- data/lib/scout/misc/monitor.rb +12 -1
- data/lib/scout/misc/system.rb +10 -0
- data/lib/scout/misc.rb +1 -0
- data/lib/scout/named_array.rb +65 -3
- data/lib/scout/open/lock/lockfile.rb +587 -0
- data/lib/scout/open/lock.rb +28 -2
- data/lib/scout/open/remote.rb +4 -0
- data/lib/scout/open/stream.rb +111 -42
- data/lib/scout/open/util.rb +13 -3
- data/lib/scout/path/find.rb +9 -1
- data/lib/scout/path/util.rb +35 -0
- data/lib/scout/persist/serialize.rb +18 -5
- data/lib/scout/persist.rb +60 -30
- data/lib/scout/resource/path.rb +53 -0
- data/lib/scout/resource/produce.rb +0 -8
- data/lib/scout/resource/util.rb +2 -1
- data/lib/scout/semaphore.rb +8 -1
- data/lib/scout/tmpfile.rb +7 -8
- data/lib/scout/tsv/attach.rb +177 -0
- data/lib/scout/tsv/change_id.rb +40 -0
- data/lib/scout/tsv/dumper.rb +85 -54
- data/lib/scout/tsv/index.rb +188 -20
- data/lib/scout/tsv/open.rb +182 -0
- data/lib/scout/tsv/parser.rb +200 -118
- data/lib/scout/tsv/path.rb +5 -6
- data/lib/scout/tsv/persist/adapter.rb +26 -37
- data/lib/scout/tsv/persist/fix_width_table.rb +327 -0
- data/lib/scout/tsv/persist/serialize.rb +117 -0
- data/lib/scout/tsv/persist/tokyocabinet.rb +6 -3
- data/lib/scout/tsv/persist.rb +4 -2
- data/lib/scout/tsv/transformer.rb +141 -0
- data/lib/scout/tsv/traverse.rb +136 -37
- data/lib/scout/tsv/util/filter.rb +312 -0
- data/lib/scout/tsv/util/process.rb +73 -0
- data/lib/scout/tsv/util/reorder.rb +81 -0
- data/lib/scout/tsv/util/select.rb +265 -0
- data/lib/scout/tsv/util/unzip.rb +86 -0
- data/lib/scout/tsv/util.rb +126 -19
- data/lib/scout/tsv.rb +28 -5
- data/lib/scout/work_queue/socket.rb +6 -1
- data/lib/scout/work_queue/worker.rb +5 -2
- data/lib/scout/work_queue.rb +15 -8
- data/lib/scout/workflow/definition.rb +29 -2
- data/lib/scout/workflow/step/dependencies.rb +24 -4
- data/lib/scout/workflow/step/info.rb +40 -5
- data/lib/scout/workflow/step/progress.rb +14 -0
- data/lib/scout/workflow/step/provenance.rb +8 -7
- data/lib/scout/workflow/step/status.rb +45 -0
- data/lib/scout/workflow/step.rb +104 -33
- data/lib/scout/workflow/task/inputs.rb +14 -20
- data/lib/scout/workflow/task.rb +86 -47
- data/lib/scout/workflow/usage.rb +10 -6
- data/scout-gear.gemspec +30 -3
- data/scout_commands/workflow/task +37 -9
- data/scout_commands/workflow/task_old +2 -2
- data/test/scout/open/test_stream.rb +61 -59
- data/test/scout/path/test_find.rb +10 -1
- data/test/scout/resource/test_produce.rb +15 -0
- data/test/scout/test_meta_extension.rb +25 -0
- data/test/scout/test_named_array.rb +18 -0
- data/test/scout/test_persist.rb +67 -0
- data/test/scout/test_tmpfile.rb +1 -1
- data/test/scout/test_tsv.rb +222 -3
- data/test/scout/test_work_queue.rb +21 -18
- data/test/scout/tsv/persist/test_adapter.rb +11 -1
- data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
- data/test/scout/tsv/persist/test_tokyocabinet.rb +29 -1
- data/test/scout/tsv/test_attach.rb +227 -0
- data/test/scout/tsv/test_change_id.rb +98 -0
- data/test/scout/tsv/test_dumper.rb +1 -1
- data/test/scout/tsv/test_index.rb +127 -3
- data/test/scout/tsv/test_open.rb +167 -0
- data/test/scout/tsv/test_parser.rb +45 -3
- data/test/scout/tsv/test_persist.rb +9 -0
- data/test/scout/tsv/test_transformer.rb +108 -0
- data/test/scout/tsv/test_traverse.rb +195 -3
- data/test/scout/tsv/test_util.rb +24 -0
- data/test/scout/tsv/util/test_filter.rb +188 -0
- data/test/scout/tsv/util/test_process.rb +47 -0
- data/test/scout/tsv/util/test_reorder.rb +94 -0
- data/test/scout/tsv/util/test_select.rb +58 -0
- data/test/scout/tsv/util/test_unzip.rb +112 -0
- data/test/scout/work_queue/test_socket.rb +0 -1
- data/test/scout/work_queue/test_worker.rb +63 -6
- data/test/scout/workflow/step/test_load.rb +3 -3
- data/test/scout/workflow/step/test_status.rb +31 -0
- data/test/scout/workflow/task/test_inputs.rb +14 -14
- data/test/scout/workflow/test_step.rb +13 -13
- data/test/scout/workflow/test_task.rb +168 -32
- data/test/scout/workflow/test_usage.rb +33 -6
- data/test/test_helper.rb +3 -1
- metadata +29 -2
@@ -8,6 +8,13 @@ class TestMetaExtension < Test::Unit::TestCase
|
|
8
8
|
extension_attr :code, :code2
|
9
9
|
end
|
10
10
|
|
11
|
+
module ExtensionClass2
|
12
|
+
extend MetaExtension
|
13
|
+
|
14
|
+
extension_attr :code3, :code4
|
15
|
+
end
|
16
|
+
|
17
|
+
|
11
18
|
def test_setup_annotate
|
12
19
|
str = "String"
|
13
20
|
ExtensionClass.setup(str, :code)
|
@@ -51,5 +58,23 @@ class TestMetaExtension < Test::Unit::TestCase
|
|
51
58
|
assert o.extension_attr_hash.include?(:code)
|
52
59
|
assert o.extension_attr_hash.include?(:code2)
|
53
60
|
end
|
61
|
+
|
62
|
+
def test_twice
|
63
|
+
str = "String"
|
64
|
+
|
65
|
+
ExtensionClass.setup(str, :code2 => :code)
|
66
|
+
assert_equal :code, str.code2
|
67
|
+
assert_include str.instance_variable_get(:@extension_attrs), :code
|
68
|
+
|
69
|
+
str.extend ExtensionClass2
|
70
|
+
str.code3 = :code_alt
|
71
|
+
assert_equal :code, str.code2
|
72
|
+
assert_equal :code_alt, str.code3
|
73
|
+
assert_include str.instance_variable_get(:@extension_attrs), :code
|
74
|
+
assert_include str.instance_variable_get(:@extension_attrs), :code3
|
75
|
+
|
76
|
+
assert_include str.extension_attr_hash, :code
|
77
|
+
assert_include str.extension_attr_hash, :code3
|
78
|
+
end
|
54
79
|
end
|
55
80
|
|
@@ -15,5 +15,23 @@ ValueB (Entity type)
|
|
15
15
|
assert_equal 1, NamedArray.identify_name(names, "ValueB")
|
16
16
|
assert_equal 1, NamedArray.identify_name(names, 1)
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_missing_field
|
20
|
+
a = NamedArray.setup([1,2], [:a, :b])
|
21
|
+
assert_equal 1, a[:a]
|
22
|
+
assert_equal nil, a[:c]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_zip_fields
|
26
|
+
a = [%w(a b), %w(1 1)]
|
27
|
+
assert_equal [%w(a 1), %w(b 1)], NamedArray.zip_fields(a)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_add_zipped
|
31
|
+
a = [%w(a b), %w(1 1)]
|
32
|
+
NamedArray.add_zipped a, [%w(c), %w(1)]
|
33
|
+
NamedArray.add_zipped a, [%w(d), %w(1)]
|
34
|
+
assert_equal [%w(a b c d), %w(1 1 1 1)], a
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
data/test/scout/test_persist.rb
CHANGED
@@ -95,6 +95,73 @@ class TestPersist < Test::Unit::TestCase
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def test_concurrent
|
99
|
+
num = 10
|
100
|
+
|
101
|
+
s = 0.01
|
102
|
+
10.times do
|
103
|
+
TmpFile.with_file do |file|
|
104
|
+
output1 = file + '.output1'
|
105
|
+
output2 = file + '.output2'
|
106
|
+
pid1 = Process.fork do
|
107
|
+
Open.purge_pipes
|
108
|
+
sleep rand/10.0
|
109
|
+
io = Persist.persist("test", :string, :path => file) do
|
110
|
+
Open.open_pipe do |sin|
|
111
|
+
num.times do |i|
|
112
|
+
sin.puts "line-#{i}-#{Process.pid}"
|
113
|
+
sleep s
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
if IO === io
|
118
|
+
Open.consume_stream(io, false)
|
119
|
+
else
|
120
|
+
Open.write(output1, io)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
pid2 = Process.fork do
|
124
|
+
Open.purge_pipes
|
125
|
+
sleep rand/10.0
|
126
|
+
io = Persist.persist("test", :string, :path => file) do
|
127
|
+
Open.open_pipe do |sin|
|
128
|
+
num.times do |i|
|
129
|
+
sin.puts "line-#{i}-#{Process.pid}"
|
130
|
+
sleep s
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
if IO === io
|
135
|
+
Open.consume_stream(io, false)
|
136
|
+
else
|
137
|
+
Open.write(output2, io)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
Process.wait
|
141
|
+
Process.wait
|
142
|
+
|
143
|
+
assert File.exist?(output1) || File.exist?(output2)
|
144
|
+
[pid1, pid2].zip([output2, output1]).each do |pid, found|
|
145
|
+
next unless File.exist?(found)
|
146
|
+
assert Open.read(found).include? "-#{pid}\n"
|
147
|
+
end
|
148
|
+
[pid1, pid2].zip([output1, output2]).each do |pid, found|
|
149
|
+
next unless File.exist?(found)
|
150
|
+
refute Open.read(found).include? "-#{pid}\n"
|
151
|
+
end
|
152
|
+
Open.rm file
|
153
|
+
Open.rm output1
|
154
|
+
Open.rm output2
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_path_prefix
|
160
|
+
Persist.persist('foo', :tsv, :prefix => "TSV") do |filename|
|
161
|
+
assert File.basename(filename).start_with? "TSV"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
98
165
|
def __test_speed
|
99
166
|
times = 100_000
|
100
167
|
TmpFile.with_file do |tmpfile|
|
data/test/scout/test_tmpfile.rb
CHANGED
data/test/scout/test_tsv.rb
CHANGED
@@ -22,7 +22,7 @@ row4 a a id3
|
|
22
22
|
tsv = TmpFile.with_file(content) do |filename|
|
23
23
|
TSV.open(filename, :persist => false)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
TmpFile.with_file(content2) do |filename|
|
27
27
|
TSV.open(filename, :data => tsv)
|
28
28
|
end
|
@@ -41,9 +41,14 @@ row2 a a id3
|
|
41
41
|
EOF
|
42
42
|
|
43
43
|
tsv = TmpFile.with_file(content) do |filename|
|
44
|
+
tsv = TSV.open(filename, :persist => true)
|
45
|
+
tsv.close
|
46
|
+
Persist::CONNECTIONS.clear
|
44
47
|
TSV.open(filename, :persist => true)
|
45
48
|
end
|
46
49
|
|
50
|
+
assert_equal "Id", tsv.key_field
|
51
|
+
|
47
52
|
assert tsv.respond_to?(:persistence_class)
|
48
53
|
assert_equal TokyoCabinet::HDB, tsv.persistence_class
|
49
54
|
|
@@ -61,7 +66,15 @@ row2 a a id3
|
|
61
66
|
EOF
|
62
67
|
|
63
68
|
tsv = TmpFile.with_file(content) do |filename|
|
64
|
-
TSV.open(filename, :persist =>
|
69
|
+
TSV.open(filename, :persist => false)
|
70
|
+
end
|
71
|
+
|
72
|
+
assert_include tsv.keys, 'row1'
|
73
|
+
assert_include tsv.keys, 'row2'
|
74
|
+
assert_equal %w(A a), tsv["row2"][0]
|
75
|
+
|
76
|
+
tsv = TmpFile.with_file(content) do |filename|
|
77
|
+
TSV.open(filename, :persist => true, :merge => true)
|
65
78
|
end
|
66
79
|
|
67
80
|
assert tsv.respond_to?(:persistence_class)
|
@@ -69,6 +82,212 @@ row2 a a id3
|
|
69
82
|
|
70
83
|
assert_include tsv.keys, 'row1'
|
71
84
|
assert_include tsv.keys, 'row2'
|
85
|
+
assert_equal %w(A a), tsv["row2"][0]
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_headerless_fields
|
89
|
+
content =<<-EOF
|
90
|
+
row1 a|aa|aaa b Id1|Id2
|
91
|
+
row2 A B Id3
|
92
|
+
EOF
|
93
|
+
|
94
|
+
TmpFile.with_file(content) do |filename|
|
95
|
+
tsv = TSV.open(filename, :sep => /\s+/, :fields => [1])
|
96
|
+
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
97
|
+
assert_equal :double, tsv.type
|
98
|
+
assert_equal [%w(a aa aaa)], tsv["row1"]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_tsv_field_selection
|
103
|
+
content =<<-EOF
|
104
|
+
#Id ValueA ValueB OtherID
|
105
|
+
row1 a|aa|aaa b Id1|Id2
|
106
|
+
row2 A B Id3
|
107
|
+
EOF
|
108
|
+
|
109
|
+
TmpFile.with_file(content) do |filename|
|
110
|
+
tsv = TSV.open(filename, :sep => /\s+/, :type => :single)
|
111
|
+
assert_equal ["ValueA"], tsv.fields
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_tsv_single_from_flat
|
116
|
+
content =<<-EOF
|
117
|
+
#: :type=:flat
|
118
|
+
#Id Value
|
119
|
+
row1 1 2
|
120
|
+
row2 4
|
121
|
+
EOF
|
122
|
+
|
123
|
+
TmpFile.with_file(content) do |filename|
|
124
|
+
tsv = TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value", :fields => ["Id"])
|
125
|
+
assert_equal "row1", tsv["1"]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_key_field
|
130
|
+
content =<<-EOF
|
131
|
+
#: :sep=/\\s+/#:type=:single
|
132
|
+
#Id Value
|
133
|
+
a 1
|
134
|
+
b 2
|
135
|
+
EOF
|
136
|
+
|
137
|
+
TmpFile.with_file(content) do |filename|
|
138
|
+
tsv = TSV.open(filename, :key_field => "Value")
|
139
|
+
assert_equal %w(Id), tsv.fields
|
140
|
+
assert_equal "Value", tsv.key_field
|
141
|
+
assert_equal "a", tsv["1"]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_fix
|
146
|
+
content =<<-EOF
|
147
|
+
#: :sep=/\\s+/#:type=:single
|
148
|
+
#Id Value
|
149
|
+
a 1
|
150
|
+
b 2
|
151
|
+
EOF
|
152
|
+
|
153
|
+
TmpFile.with_file(content) do |filename|
|
154
|
+
tsv = TSV.open(filename, :key_field => "Value", :fix => Proc.new{|l| if l =~ /1/;then "a 3" else l end})
|
155
|
+
assert_equal "a", tsv["3"]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_flat
|
160
|
+
content =<<-EOF
|
161
|
+
#: :type=:flat
|
162
|
+
#Id Value
|
163
|
+
row1 a|aa|aaa
|
164
|
+
row2 A|AA|AAA
|
165
|
+
EOF
|
166
|
+
|
167
|
+
TmpFile.with_file(content) do |filename|
|
168
|
+
assert TSV.open(filename, :sep => /\s+/, :type => :flat).include? "row1"
|
169
|
+
assert TSV.open(filename, :sep => /\s+/, :type => :flat)["row1"].include? "a"
|
170
|
+
assert TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "Id")["row1"].include? "a"
|
171
|
+
assert TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "Id", :fields => ["Value"])["row1"].include? "a"
|
172
|
+
end
|
72
173
|
end
|
73
|
-
end
|
74
174
|
|
175
|
+
def test_tsv_flat_double
|
176
|
+
content =<<-EOF
|
177
|
+
#Id ValueA ValueB OtherID
|
178
|
+
row1 a|aa|aaa b Id1|Id2
|
179
|
+
row2 A B Id3
|
180
|
+
EOF
|
181
|
+
|
182
|
+
TmpFile.with_file(content) do |filename|
|
183
|
+
tsv = TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "ValueA", :fields => ["OtherID"], :merge => true)
|
184
|
+
assert tsv["aaa"].include? "Id1"
|
185
|
+
assert tsv["aaa"].include? "Id2"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_flat2single
|
190
|
+
content =<<-EOF
|
191
|
+
#: :type=:flat
|
192
|
+
#Id Value
|
193
|
+
row1 a aa aaa
|
194
|
+
row2 A AA AAA
|
195
|
+
EOF
|
196
|
+
|
197
|
+
TmpFile.with_file(content) do |filename|
|
198
|
+
tsv = TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value")
|
199
|
+
assert tsv.include? "aaa"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_flat_key
|
204
|
+
content =<<-EOF
|
205
|
+
#Id ValueA
|
206
|
+
row1 a aa aaa
|
207
|
+
row2 b bbb bbbb bb aa
|
208
|
+
EOF
|
209
|
+
|
210
|
+
TmpFile.with_file(content) do |filename|
|
211
|
+
tsv = TSV.open(filename, :sep => /\s+/, :merge => true, :type => :flat, :key_field => "ValueA")
|
212
|
+
assert_equal ["row1"], tsv["a"]
|
213
|
+
assert_equal ["row1", "row2"], tsv["aa"]
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_unnamed_key
|
218
|
+
content =<<-EOF
|
219
|
+
row1 a|aa|aaa b Id1|Id2
|
220
|
+
row2 A B Id3
|
221
|
+
EOF
|
222
|
+
|
223
|
+
TmpFile.with_file(content) do |filename|
|
224
|
+
tsv = TSV.open(filename, :sep => /\s+/, :key_field => 1)
|
225
|
+
assert tsv.keys.include? "a"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_grep
|
230
|
+
content =<<-EOF
|
231
|
+
#: :sep=/\\s+/#:type=:single
|
232
|
+
#Id Value
|
233
|
+
a 1
|
234
|
+
b 2
|
235
|
+
c 3
|
236
|
+
EOF
|
237
|
+
|
238
|
+
TmpFile.with_file(content) do |filename|
|
239
|
+
tsv = TSV.open(filename, :key_field => "Value", :grep => "#\\|2")
|
240
|
+
assert_includes tsv, "2"
|
241
|
+
refute_includes tsv, "3"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def TODO_test_tsv_grep
|
246
|
+
content =<<-EOF
|
247
|
+
#: :sep=/\\s+/#:type=:single
|
248
|
+
#Id Value
|
249
|
+
a 1
|
250
|
+
b 2
|
251
|
+
b 3
|
252
|
+
d 22
|
253
|
+
EOF
|
254
|
+
|
255
|
+
TmpFile.with_file(content) do |filename|
|
256
|
+
tsv = TSV.open(filename, :key_field => "Value", :tsv_grep => "2")
|
257
|
+
assert_includes tsv, "2"
|
258
|
+
refute_includes tsv, "3"
|
259
|
+
assert(tsv.include?("2"))
|
260
|
+
assert(! tsv.include?("3"))
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_flat_with_field_header
|
265
|
+
content =<<-EOF
|
266
|
+
#: :type=:flat
|
267
|
+
#Id ValueA
|
268
|
+
row1 a aa aaa
|
269
|
+
row2 b bbb bbbb bb
|
270
|
+
EOF
|
271
|
+
|
272
|
+
TmpFile.with_file(content) do |filename|
|
273
|
+
tsv = TSV.open(filename, :sep => /\s+/, :merge => false)
|
274
|
+
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_alt_args
|
279
|
+
content =<<-EOF
|
280
|
+
#Id ValueA
|
281
|
+
row1 a aa aaa
|
282
|
+
row2 b bbb bbbb bb
|
283
|
+
EOF
|
284
|
+
|
285
|
+
TmpFile.with_file(content) do |filename|
|
286
|
+
tsv = TSV.open(filename, type: :flat, :sep => /\s+/, :merge => false)
|
287
|
+
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
288
|
+
end
|
289
|
+
|
290
|
+
tsv = TSV.str_setup("ID~ValueA,ValueB#:type=:flat", {})
|
291
|
+
assert_equal "ID", tsv.key_field
|
292
|
+
end
|
293
|
+
end
|
@@ -103,18 +103,19 @@ class TestWorkQueue < Test::Unit::TestCase
|
|
103
103
|
res << out
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
Log.with_severity 7 do
|
107
|
+
pid = Process.fork do
|
108
|
+
reps.times do |i|
|
109
|
+
q.write i
|
110
|
+
end
|
109
111
|
end
|
110
|
-
end
|
111
112
|
|
112
|
-
|
113
|
-
q.close
|
113
|
+
Process.waitpid pid
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
assert_raise ScoutException do
|
116
|
+
q.join
|
117
|
+
t.join
|
118
|
+
end
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
@@ -128,20 +129,22 @@ class TestWorkQueue < Test::Unit::TestCase
|
|
128
129
|
|
129
130
|
res = []
|
130
131
|
q.process do |out|
|
131
|
-
raise ScoutException
|
132
|
+
raise ScoutException
|
132
133
|
res << out
|
133
134
|
end
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
Log.with_severity 7 do
|
137
|
+
pid = Process.fork do
|
138
|
+
reps.times do |i|
|
139
|
+
q.write i
|
140
|
+
end
|
141
|
+
q.close
|
138
142
|
end
|
139
|
-
q.close
|
140
|
-
end
|
141
143
|
|
142
|
-
|
143
|
-
|
144
|
-
|
144
|
+
assert_raise ScoutException do
|
145
|
+
q.join
|
146
|
+
t.join
|
147
|
+
end
|
145
148
|
end
|
146
149
|
end
|
147
150
|
end
|
@@ -3,7 +3,7 @@ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1
|
|
3
3
|
|
4
4
|
require 'scout/tsv'
|
5
5
|
class TestTSVAdapter < Test::Unit::TestCase
|
6
|
-
def
|
6
|
+
def _test_get_set
|
7
7
|
tsv = TSV.setup({}, :type => :list, :key_field => "Key", :fields => %w(one two three))
|
8
8
|
tsv.type = :list
|
9
9
|
tsv.extend TSVAdapter
|
@@ -30,5 +30,15 @@ class TestTSVAdapter < Test::Unit::TestCase
|
|
30
30
|
assert_equal [["a", %w(1 2 3)], ["b", %w(11 22 33)]], tsv.sort
|
31
31
|
assert_equal [["b", %w(11 22 33)], ["a", %w(1 2 3)]], tsv.sort_by{|k,v| -v[0].to_i }
|
32
32
|
end
|
33
|
+
|
34
|
+
def test_serializer
|
35
|
+
tsv = TSV.setup({}, :type => :list, :key_field => "Key", :fields => %w(one two three))
|
36
|
+
tsv.type = :list
|
37
|
+
tsv.extend TSVAdapter
|
38
|
+
tsv.serializer = :integer_array
|
39
|
+
tsv["a"] = [1, 2, 3]
|
40
|
+
|
41
|
+
assert_equal [1, 2, 3], tsv["a"]
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
@@ -0,0 +1,134 @@
|
|
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 TestFixWidthTable < Test::Unit::TestCase
|
6
|
+
def load_data(data)
|
7
|
+
tsv = TSV.open(data, type: :list, :sep=>":", :cast => proc{|e| e =~ /(\s*)(_*)/; ($1.length..($1.length + $2.length - 1))})
|
8
|
+
tsv.add_field "Start" do |key, values|
|
9
|
+
values["Range"].first
|
10
|
+
end
|
11
|
+
tsv.add_field "End" do |key, values|
|
12
|
+
values["Range"].last
|
13
|
+
end
|
14
|
+
|
15
|
+
tsv = tsv.slice ["Start", "End"]
|
16
|
+
|
17
|
+
tsv
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_options
|
21
|
+
TmpFile.with_file do |filename|
|
22
|
+
f = FixWidthTable.new filename, 100, true
|
23
|
+
f.close
|
24
|
+
|
25
|
+
f1 = FixWidthTable.new filename, 100, false
|
26
|
+
|
27
|
+
assert_equal true, f1.range
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add
|
32
|
+
TmpFile.with_file do |filename|
|
33
|
+
f = FixWidthTable.new filename, 100, true
|
34
|
+
f.add [1,2,0], "test1"
|
35
|
+
f.add [3,4,0], "test2"
|
36
|
+
f.read
|
37
|
+
|
38
|
+
assert_equal 1, f.idx_pos(0)
|
39
|
+
assert_equal 3, f.idx_pos(1)
|
40
|
+
assert_equal 2, f.idx_pos_end(0)
|
41
|
+
assert_equal 4, f.idx_pos_end(1)
|
42
|
+
assert_equal 0, f.idx_overlap(0)
|
43
|
+
assert_equal 0, f.idx_overlap(1)
|
44
|
+
assert_equal "test1", f.idx_value(0)
|
45
|
+
assert_equal "test2", f.idx_value(1)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_point
|
52
|
+
data =<<-EOF
|
53
|
+
#: :sep=/\\s+/#:type=:single#:cast=:to_i
|
54
|
+
#ID Pos
|
55
|
+
a 1
|
56
|
+
b 10
|
57
|
+
c 20
|
58
|
+
d 12
|
59
|
+
e 26
|
60
|
+
f 11
|
61
|
+
g 25
|
62
|
+
EOF
|
63
|
+
TmpFile.with_file(data) do |datafile|
|
64
|
+
tsv = TSV.open datafile
|
65
|
+
TmpFile.with_file do |filename|
|
66
|
+
f = FixWidthTable.new filename, 100, false
|
67
|
+
f.add_point tsv
|
68
|
+
f.read
|
69
|
+
|
70
|
+
assert_equal %w(), f[0].sort
|
71
|
+
assert_equal %w(b), f[10].sort
|
72
|
+
assert_equal %w(a b c d f), f[(0..20)].sort
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_range
|
78
|
+
data =<<-EOF
|
79
|
+
##012345678901234567890
|
80
|
+
#ID:Range
|
81
|
+
a: ______
|
82
|
+
b: ______
|
83
|
+
c: _______
|
84
|
+
d: ____
|
85
|
+
e: ______
|
86
|
+
f: ___
|
87
|
+
g: ____
|
88
|
+
EOF
|
89
|
+
TmpFile.with_file(data) do |datafile|
|
90
|
+
tsv = load_data(datafile)
|
91
|
+
TmpFile.with_file do |filename|
|
92
|
+
f = FixWidthTable.new filename, 100, true
|
93
|
+
f.add_range tsv
|
94
|
+
f.read
|
95
|
+
|
96
|
+
assert_equal %w(), f[0].sort
|
97
|
+
assert_equal %w(b), f[1].sort
|
98
|
+
assert_equal %w(), f[20].sort
|
99
|
+
assert_equal %w(), f[(20..100)].sort
|
100
|
+
assert_equal %w(a b d), f[3].sort
|
101
|
+
assert_equal %w(a b c d e), f[(3..4)].sort
|
102
|
+
assert_equal %w(a c e), f[7].sort
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def test_range_pos
|
109
|
+
data =<<-EOF
|
110
|
+
##012345678901234567890
|
111
|
+
#ID:Range
|
112
|
+
a: ______
|
113
|
+
b: ______
|
114
|
+
c: _______
|
115
|
+
d: ____
|
116
|
+
e: ______
|
117
|
+
f: ___
|
118
|
+
g: ____
|
119
|
+
EOF
|
120
|
+
TmpFile.with_file(data) do |datafile|
|
121
|
+
tsv = load_data(datafile)
|
122
|
+
TmpFile.with_file do |filename|
|
123
|
+
f = FixWidthTable.new filename, 100, true
|
124
|
+
f.add_range tsv
|
125
|
+
f.read
|
126
|
+
|
127
|
+
assert_equal %w(), f.overlaps(0).sort
|
128
|
+
assert_equal %w(1:6), f.overlaps(1).sort
|
129
|
+
assert_equal %w(1:6:b), f.overlaps(1, true).sort
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
@@ -21,6 +21,11 @@ row2 a a id3
|
|
21
21
|
|
22
22
|
assert_equal %w(a aa aaa), tsv["row1"][0]
|
23
23
|
|
24
|
+
assert TSVAdapter === tsv
|
25
|
+
assert TSV === tsv
|
26
|
+
assert_include tsv.instance_variable_get(:@extension_attrs), :key_field
|
27
|
+
assert_include tsv.instance_variable_get(:@extension_attrs), :serializer
|
28
|
+
|
24
29
|
tsv_loaded = assert_nothing_raised do
|
25
30
|
TmpFile.with_file(content) do |filename|
|
26
31
|
Persist.persist(__method__, :HDB) do
|
@@ -29,6 +34,7 @@ row2 a a id3
|
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
37
|
+
|
32
38
|
assert_equal %w(a aa aaa), tsv_loaded["row1"][0]
|
33
39
|
end
|
34
40
|
|
@@ -54,7 +60,7 @@ row2 a a id3
|
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
|
-
def
|
63
|
+
def __test_speed
|
58
64
|
tsv = TSV.setup({}, :type => :double, :key_field => "Key", :fields => %w(Field1 Field2))
|
59
65
|
|
60
66
|
size = 100_000
|
@@ -88,5 +94,27 @@ row2 a a id3
|
|
88
94
|
assert_equal tc["key-#{i}"], tsv["key-#{i}"]
|
89
95
|
end
|
90
96
|
end
|
97
|
+
|
98
|
+
def test_float_array
|
99
|
+
content =<<-EOF
|
100
|
+
#Id ValueA ValueB OtherID
|
101
|
+
row1 0.2 0.3 0
|
102
|
+
row2 0.1 4.5 0
|
103
|
+
EOF
|
104
|
+
|
105
|
+
TmpFile.with_file(content) do |filename|
|
106
|
+
tsv = TSV.open(filename, :sep => /\s+/, :persist => true, :type => :list, :cast => :to_f)
|
107
|
+
tsv.save_extension_attr_hash
|
108
|
+
assert_equal [0.2, 0.3, 0], tsv["row1"]
|
109
|
+
assert_equal TSVAdapter::FloatArraySerializer, tsv.serializer
|
110
|
+
Open.cp tsv.persistence_path, tmpdir.persistence.foo
|
111
|
+
tsv2 = ScoutCabinet.open(tmpdir.persistence.foo, false)
|
112
|
+
tsv2.extend TSVAdapter
|
113
|
+
assert_equal [0.2, 0.3, 0], tsv2["row1"]
|
114
|
+
assert_equal TSVAdapter::FloatArraySerializer, tsv2.serializer
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
91
119
|
end
|
92
120
|
|