rbbt-util 3.2.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +65 -0
- data/bin/run_workflow.rb +142 -69
- data/lib/rbbt-util.rb +3 -3
- data/lib/rbbt.rb +12 -3
- data/lib/rbbt/annotations.rb +215 -0
- data/lib/rbbt/{util/fix_width_table.rb → fix_width_table.rb} +17 -13
- data/lib/rbbt/persist.rb +164 -0
- data/lib/rbbt/persist/tsv.rb +135 -0
- data/lib/rbbt/resource.rb +100 -0
- data/lib/rbbt/resource/path.rb +180 -0
- data/lib/rbbt/resource/rake.rb +48 -0
- data/lib/rbbt/resource/util.rb +111 -0
- data/lib/rbbt/resource/with_key.rb +28 -0
- data/lib/rbbt/tsv.rb +134 -0
- data/lib/rbbt/tsv/accessor.rb +345 -0
- data/lib/rbbt/tsv/attach.rb +183 -0
- data/lib/rbbt/tsv/attach/util.rb +277 -0
- data/lib/rbbt/{util/tsv/filters.rb → tsv/filter.rb} +76 -37
- data/lib/rbbt/tsv/index.rb +453 -0
- data/lib/rbbt/tsv/manipulate.rb +361 -0
- data/lib/rbbt/tsv/parser.rb +231 -0
- data/lib/rbbt/tsv/serializers.rb +79 -0
- data/lib/rbbt/tsv/util.rb +67 -0
- data/lib/rbbt/util/R.rb +3 -3
- data/lib/rbbt/util/chain_methods.rb +64 -0
- data/lib/rbbt/util/cmd.rb +17 -13
- data/lib/rbbt/util/excel2tsv.rb +4 -3
- data/lib/rbbt/util/log.rb +1 -0
- data/lib/rbbt/util/misc.rb +296 -285
- data/lib/rbbt/util/open.rb +9 -2
- data/lib/rbbt/util/persistence.rb +1 -1
- data/lib/rbbt/util/task/job.rb +3 -1
- data/lib/rbbt/workflow.rb +193 -0
- data/lib/rbbt/workflow/accessor.rb +249 -0
- data/lib/rbbt/workflow/annotate.rb +60 -0
- data/lib/rbbt/workflow/soap.rb +100 -0
- data/lib/rbbt/workflow/step.rb +102 -0
- data/lib/rbbt/workflow/task.rb +76 -0
- data/test/rbbt/resource/test_path.rb +12 -0
- data/test/rbbt/test_annotations.rb +106 -0
- data/test/rbbt/{util/test_fix_width_table.rb → test_fix_width_table.rb} +8 -9
- data/test/rbbt/test_resource.rb +66 -0
- data/test/rbbt/test_tsv.rb +332 -0
- data/test/rbbt/test_workflow.rb +102 -0
- data/test/rbbt/tsv/test_accessor.rb +163 -0
- data/test/rbbt/{util/tsv → tsv}/test_attach.rb +86 -43
- data/test/rbbt/{util/tsv/test_filters.rb → tsv/test_filter.rb} +31 -13
- data/test/rbbt/tsv/test_index.rb +284 -0
- data/test/rbbt/{util/tsv → tsv}/test_manipulate.rb +35 -105
- data/test/rbbt/util/test_R.rb +1 -1
- data/test/rbbt/util/test_chain_methods.rb +22 -0
- data/test/rbbt/util/test_filecache.rb +0 -1
- data/test/rbbt/util/test_misc.rb +97 -79
- data/test/rbbt/util/test_open.rb +1 -0
- data/test/rbbt/util/test_tmpfile.rb +1 -1
- data/test/rbbt/workflow/test_soap.rb +103 -0
- data/test/rbbt/workflow/test_step.rb +142 -0
- data/test/rbbt/workflow/test_task.rb +84 -0
- data/test/test_helper.rb +7 -7
- metadata +80 -54
- data/lib/rbbt/util/rake.rb +0 -176
- data/lib/rbbt/util/resource.rb +0 -355
- data/lib/rbbt/util/task.rb +0 -183
- data/lib/rbbt/util/tc_hash.rb +0 -324
- data/lib/rbbt/util/tsv.rb +0 -236
- data/lib/rbbt/util/tsv/accessor.rb +0 -312
- data/lib/rbbt/util/tsv/attach.rb +0 -416
- data/lib/rbbt/util/tsv/index.rb +0 -419
- data/lib/rbbt/util/tsv/manipulate.rb +0 -300
- data/lib/rbbt/util/tsv/misc.rb +0 -41
- data/lib/rbbt/util/tsv/parse.rb +0 -324
- data/lib/rbbt/util/tsv/resource.rb +0 -88
- data/lib/rbbt/util/workflow.rb +0 -135
- data/lib/rbbt/util/workflow/soap.rb +0 -116
- data/test/rbbt/util/test_persistence.rb +0 -201
- data/test/rbbt/util/test_rake.rb +0 -54
- data/test/rbbt/util/test_resource.rb +0 -77
- data/test/rbbt/util/test_task.rb +0 -133
- data/test/rbbt/util/test_tc_hash.rb +0 -144
- data/test/rbbt/util/test_tsv.rb +0 -221
- data/test/rbbt/util/test_workflow.rb +0 -135
- data/test/rbbt/util/tsv/test_accessor.rb +0 -150
- data/test/rbbt/util/tsv/test_index.rb +0 -241
- data/test/rbbt/util/tsv/test_parse.rb +0 -87
- data/test/rbbt/util/tsv/test_resource.rb +0 -9
@@ -0,0 +1,163 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
require 'rbbt/tsv'
|
3
|
+
require 'rbbt/util/tmpfile'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestTSV < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def _test_tsv
|
9
|
+
content =<<-EOF
|
10
|
+
#Id ValueA ValueB OtherID
|
11
|
+
row1 a|aa|aaa b Id1|Id2
|
12
|
+
row2 A B Id3
|
13
|
+
EOF
|
14
|
+
|
15
|
+
TmpFile.with_file(content) do |filename|
|
16
|
+
tsv = TSV.open(filename, :sep => /\s+/)
|
17
|
+
assert_equal 2, tsv.keys.length
|
18
|
+
assert_equal 2, tsv.values.length
|
19
|
+
assert_equal 2, tsv.collect.length
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def _test_named_values
|
24
|
+
content =<<-EOF
|
25
|
+
#Id ValueA ValueB OtherID
|
26
|
+
row1 a|aa|aaa b Id1|Id2
|
27
|
+
row2 A B Id3
|
28
|
+
EOF
|
29
|
+
|
30
|
+
TmpFile.with_file(content) do |filename|
|
31
|
+
tsv = TSV.open(filename, :sep => /\s+/)
|
32
|
+
assert_equal ["A"], tsv["row2"]["ValueA"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def _test_to_s
|
37
|
+
content =<<-EOF
|
38
|
+
#Id ValueA ValueB OtherID
|
39
|
+
row1 a|aa|aaa b Id1|Id2
|
40
|
+
row2 A B Id3
|
41
|
+
EOF
|
42
|
+
|
43
|
+
TmpFile.with_file(content) do |filename|
|
44
|
+
tsv = TSV.open(filename, :sep => /\s+/)
|
45
|
+
assert tsv.to_s =~ /row1\ta|aa|aaa/
|
46
|
+
assert tsv.to_s =~ /:type=:double/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def _test_entries
|
51
|
+
content =<<-EOF
|
52
|
+
#Id ValueA ValueB OtherID
|
53
|
+
row1 a|aa|aaa b Id1|Id2
|
54
|
+
row2 A B Id3
|
55
|
+
EOF
|
56
|
+
|
57
|
+
TmpFile.with_file(content) do |filename|
|
58
|
+
tsv = TSV.open(filename, :sep => /\s+/)
|
59
|
+
assert_equal filename, tsv.options[:filename]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def _test_marshal
|
65
|
+
content =<<-EOF
|
66
|
+
#Id ValueA ValueB OtherID
|
67
|
+
row1 a|aa|aaa b Id1|Id2
|
68
|
+
row2 A B Id3
|
69
|
+
EOF
|
70
|
+
|
71
|
+
TmpFile.with_file(content) do |filename|
|
72
|
+
tsv = TSV.open(filename, :sep => /\s+/, :persist_serializer => :marshal, :persist => true)
|
73
|
+
assert_equal filename, tsv.options[:filename]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def _test_zip_fields
|
78
|
+
a = [%w(1 2), %w(a b)]
|
79
|
+
assert_equal a, TSV.zip_fields(TSV.zip_fields(a))
|
80
|
+
end
|
81
|
+
|
82
|
+
def _test_indentify_fields
|
83
|
+
content =<<-EOF
|
84
|
+
#ID ValueA ValueB Comment
|
85
|
+
row1 a b c
|
86
|
+
row2 A B C
|
87
|
+
EOF
|
88
|
+
|
89
|
+
TmpFile.with_file(content) do |filename|
|
90
|
+
tsv = TSV.open(File.open(filename), :double, :sep => /\s/)
|
91
|
+
assert_equal :key, tsv.identify_field("ID")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def _test_sort
|
96
|
+
content =<<-EOF
|
97
|
+
#ID ValueA ValueB Comment
|
98
|
+
row1 a B c
|
99
|
+
row2 A b C
|
100
|
+
EOF
|
101
|
+
|
102
|
+
TmpFile.with_file(content) do |filename|
|
103
|
+
tsv = TSV.open(File.open(filename), :double, :sep => /\s/)
|
104
|
+
assert_equal %w(row2 row1), tsv.sort{|a,b|
|
105
|
+
a[1]["ValueA"] <=> b[1]["ValueA"]
|
106
|
+
}.collect{|k,v| k}
|
107
|
+
assert_equal %w(row1 row2), tsv.sort{|a,b|
|
108
|
+
a[1]["ValueB"] <=> b[1]["ValueB"]
|
109
|
+
}.collect{|k,v| k}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def _test_sort_by
|
114
|
+
content =<<-EOF
|
115
|
+
#ID ValueA ValueB Comment
|
116
|
+
row1 a B c
|
117
|
+
row2 A b C
|
118
|
+
EOF
|
119
|
+
|
120
|
+
TmpFile.with_file(content) do |filename|
|
121
|
+
tsv = TSV.open(File.open(filename), :list, :sep => /\s/)
|
122
|
+
assert_equal %w(row2 row1), tsv.sort_by("ValueA").collect{|k,v| k}
|
123
|
+
assert_equal %w(row1 row2), tsv.sort_by("ValueB").collect{|k,v| k}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def test_page
|
129
|
+
content =<<-EOF
|
130
|
+
#ID ValueA ValueB Comment
|
131
|
+
row1 a B f
|
132
|
+
row2 A b e
|
133
|
+
row3 A b d
|
134
|
+
row4 A b c
|
135
|
+
row5 A b b
|
136
|
+
row6 A b a
|
137
|
+
EOF
|
138
|
+
|
139
|
+
TmpFile.with_file(content) do |filename|
|
140
|
+
tsv = TSV.open(File.open(filename), :list, :sep => /\s/)
|
141
|
+
assert_equal 3, tsv.page(1,3).size
|
142
|
+
assert_equal %w(row1 row2 row3).sort, tsv.page(1,3).keys.sort
|
143
|
+
assert_equal %w(row6 row5 row4).sort, tsv.page(1,3, "Comment").keys.sort
|
144
|
+
assert_equal %w(row4 row3).sort, tsv.page(2,2, "Comment").keys.sort
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def _test_sort_by_with_proc
|
150
|
+
content =<<-EOF
|
151
|
+
#Id ValueA ValueB OtherID Pos
|
152
|
+
row1 a|aa|aaa b Id1|Id2 2
|
153
|
+
row2 aA B Id3 1
|
154
|
+
row3 A|AA|AAA|AAA B Id3 3
|
155
|
+
EOF
|
156
|
+
|
157
|
+
TmpFile.with_file(content) do |filename|
|
158
|
+
tsv = TSV.open(File.open(filename), :sep => /\s+/)
|
159
|
+
assert_equal %w(row3 row1 row2), (tsv.sort_by("ValueA") do |key, value| value.length end).collect{|k,v| k}.reverse
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), '
|
2
|
-
require 'rbbt/
|
3
|
-
require 'rbbt/
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
|
2
|
+
require 'rbbt/tsv'
|
3
|
+
require 'rbbt/tsv/attach'
|
4
4
|
require 'rbbt'
|
5
5
|
|
6
6
|
class TestAttach < Test::Unit::TestCase
|
@@ -19,11 +19,11 @@ row3 B Id3
|
|
19
19
|
|
20
20
|
tsv1 = tsv2 = nil
|
21
21
|
TmpFile.with_file(content1) do |filename|
|
22
|
-
tsv1 = TSV.
|
22
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
23
23
|
end
|
24
24
|
|
25
25
|
TmpFile.with_file(content2) do |filename|
|
26
|
-
tsv2 = TSV.
|
26
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
27
27
|
end
|
28
28
|
|
29
29
|
tsv1.attach_same_key tsv2, "OtherID"
|
@@ -32,7 +32,7 @@ row3 B Id3
|
|
32
32
|
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
33
33
|
|
34
34
|
TmpFile.with_file(content1) do |filename|
|
35
|
-
tsv1 = TSV.
|
35
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
36
36
|
end
|
37
37
|
|
38
38
|
tsv1.attach_same_key tsv2
|
@@ -41,11 +41,11 @@ row3 B Id3
|
|
41
41
|
|
42
42
|
tsv1 = tsv2 = nil
|
43
43
|
TmpFile.with_file(content1) do |filename|
|
44
|
-
tsv1 = TSV.
|
44
|
+
tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
|
45
45
|
end
|
46
46
|
|
47
47
|
TmpFile.with_file(content2) do |filename|
|
48
|
-
tsv2 = TSV.
|
48
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
49
49
|
end
|
50
50
|
|
51
51
|
tsv1.attach_same_key tsv2, "OtherID"
|
@@ -69,11 +69,11 @@ B Id3
|
|
69
69
|
|
70
70
|
tsv1 = tsv2 = nil
|
71
71
|
TmpFile.with_file(content1) do |filename|
|
72
|
-
tsv1 = TSV.
|
72
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
73
73
|
end
|
74
74
|
|
75
75
|
TmpFile.with_file(content2) do |filename|
|
76
|
-
tsv2 = TSV.
|
76
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
77
77
|
end
|
78
78
|
|
79
79
|
tsv1.attach_source_key tsv2, "ValueB"
|
@@ -82,7 +82,7 @@ B Id3
|
|
82
82
|
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
83
83
|
|
84
84
|
TmpFile.with_file(content1) do |filename|
|
85
|
-
tsv1 = TSV.
|
85
|
+
tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
|
86
86
|
end
|
87
87
|
|
88
88
|
tsv1.attach_source_key tsv2, "ValueB"
|
@@ -113,15 +113,15 @@ row2 E
|
|
113
113
|
|
114
114
|
tsv1 = tsv2 = index = nil
|
115
115
|
TmpFile.with_file(content1) do |filename|
|
116
|
-
tsv1 = TSV.
|
116
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
117
117
|
end
|
118
118
|
|
119
119
|
TmpFile.with_file(content2) do |filename|
|
120
|
-
tsv2 = TSV.
|
120
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
121
121
|
end
|
122
122
|
|
123
123
|
TmpFile.with_file(content_index) do |filename|
|
124
|
-
index = TSV.
|
124
|
+
index = TSV.open(File.open(filename), :flat, :sep => /\s+/)
|
125
125
|
end
|
126
126
|
|
127
127
|
tsv1.attach_index tsv2, index
|
@@ -130,7 +130,7 @@ row2 E
|
|
130
130
|
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
131
131
|
|
132
132
|
TmpFile.with_file(content1) do |filename|
|
133
|
-
tsv1 = TSV.
|
133
|
+
tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
|
134
134
|
end
|
135
135
|
|
136
136
|
tsv1.attach_index tsv2, index
|
@@ -159,15 +159,15 @@ B Id3
|
|
159
159
|
EOF
|
160
160
|
tsv1 = tsv2 = tsv3 = nil
|
161
161
|
TmpFile.with_file(content1) do |filename|
|
162
|
-
tsv1 = TSV.
|
162
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
163
163
|
end
|
164
164
|
|
165
165
|
TmpFile.with_file(content2) do |filename|
|
166
|
-
tsv2 = TSV.
|
166
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
167
167
|
end
|
168
168
|
|
169
169
|
TmpFile.with_file(content3) do |filename|
|
170
|
-
tsv3 = TSV.
|
170
|
+
tsv3 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
171
171
|
end
|
172
172
|
|
173
173
|
tsv1.attach tsv2, "OtherID"
|
@@ -176,7 +176,7 @@ B Id3
|
|
176
176
|
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
177
177
|
|
178
178
|
TmpFile.with_file(content1) do |filename|
|
179
|
-
tsv1 = TSV.
|
179
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
180
180
|
end
|
181
181
|
|
182
182
|
tsv1.attach tsv3
|
@@ -188,12 +188,14 @@ B Id3
|
|
188
188
|
|
189
189
|
def test_attach_using_index
|
190
190
|
content1 =<<-EOF
|
191
|
+
#: :sep=/\\s+/
|
191
192
|
#Id ValueA ValueB
|
192
193
|
row1 a|aa|aaa b
|
193
194
|
row2 A B
|
194
195
|
EOF
|
195
196
|
|
196
197
|
content2 =<<-EOF
|
198
|
+
#: :sep=/\\s+/
|
197
199
|
#ValueE OtherID
|
198
200
|
e Id1|Id2
|
199
201
|
E Id3
|
@@ -206,19 +208,19 @@ row1 e
|
|
206
208
|
row2 E
|
207
209
|
EOF
|
208
210
|
|
209
|
-
Rbbt.tmp.test.test1.data
|
210
|
-
Rbbt.tmp.test.test2.data
|
211
|
-
Rbbt.tmp.test.test2.identifiers
|
211
|
+
Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
|
212
|
+
Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
|
213
|
+
Rbbt.claim Rbbt.tmp.test.test2.identifiers, :string, content_index
|
212
214
|
|
213
215
|
tsv1 = tsv2 = nil
|
214
216
|
|
215
217
|
tsv1 = Rbbt.tmp.test.test1.data.tsv :double, :sep => /\s+/
|
216
218
|
tsv2 = Rbbt.tmp.test.test2.data.tsv :double, :sep => /\s+/
|
217
219
|
|
218
|
-
tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce
|
219
|
-
|
220
|
-
tsv1.attach tsv2, "OtherID", :in_namespace => false
|
220
|
+
tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce.find.to_s
|
221
221
|
|
222
|
+
tsv1.attach tsv2, :fields => ["OtherID"], :persist_input => true
|
223
|
+
|
222
224
|
assert_equal tsv1.fields,%w(ValueA ValueB OtherID)
|
223
225
|
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
224
226
|
end
|
@@ -247,24 +249,25 @@ row2 E
|
|
247
249
|
|
248
250
|
tsv1 = tsv2 = identifiers = nil
|
249
251
|
TmpFile.with_file(content1) do |filename|
|
250
|
-
tsv1 = TSV.
|
252
|
+
tsv1 = TSV.open(Path.setup(filename), :key => "Id")
|
251
253
|
end
|
252
254
|
|
253
255
|
TmpFile.with_file(content2) do |filename|
|
254
|
-
tsv2 = TSV.
|
256
|
+
tsv2 = TSV.open(Path.setup(filename), :double)
|
255
257
|
end
|
256
258
|
|
257
259
|
TmpFile.with_file(content_identifiers) do |filename|
|
258
|
-
identifiers = TSV.
|
260
|
+
identifiers = TSV.open(Path.setup(filename), :flat, :sep => /\s+/)
|
259
261
|
end
|
260
262
|
|
261
263
|
tsv1.identifiers = identifiers
|
264
|
+
|
262
265
|
tsv1.attach tsv2
|
263
266
|
|
264
267
|
assert_equal %w(ValueA ValueB ValueE), tsv1.fields
|
265
268
|
end
|
266
269
|
|
267
|
-
def
|
270
|
+
def test_merge_different_rows
|
268
271
|
file1 =<<-EOF
|
269
272
|
row6 dd dd ee
|
270
273
|
row1 a b c
|
@@ -287,12 +290,12 @@ row6 dd dd ee
|
|
287
290
|
EOF
|
288
291
|
|
289
292
|
TmpFile.with_file do |f|
|
290
|
-
TSV.
|
293
|
+
TSV.merge_different_fields(StringIO.new(file1), StringIO.new(file2), f, " ")
|
291
294
|
assert_equal result, Open.read(f)
|
292
295
|
end
|
293
296
|
end
|
294
297
|
|
295
|
-
def
|
298
|
+
def test_merge_different_rows_tsv
|
296
299
|
file1 =<<-EOF
|
297
300
|
row6 dd dd ee
|
298
301
|
row1 a b c
|
@@ -315,14 +318,14 @@ row6 dd dd ee
|
|
315
318
|
EOF
|
316
319
|
|
317
320
|
TmpFile.with_file do |f|
|
318
|
-
tsv1 = TSV.
|
319
|
-
tsv2 = TSV.
|
320
|
-
tsv_r = tsv1.
|
321
|
+
tsv1 = TSV.open StringIO.new(file1), :sep => " "
|
322
|
+
tsv2 = TSV.open StringIO.new(file2), :sep => " "
|
323
|
+
tsv_r = tsv1.merge_different_fields tsv2
|
321
324
|
assert_equal result, tsv_r.to_s(tsv_r.keys.sort, true).gsub(/\t/,' ')
|
322
325
|
end
|
323
326
|
end
|
324
327
|
|
325
|
-
def
|
328
|
+
def test_merge_different_rows_split_lines
|
326
329
|
file1 =<<-EOF
|
327
330
|
row6,dd,dd,ee
|
328
331
|
row1,a,b,c
|
@@ -336,23 +339,34 @@ row1,d,e
|
|
336
339
|
row2,D,E
|
337
340
|
row4,x,y
|
338
341
|
EOF
|
339
|
-
|
342
|
+
|
343
|
+
# Might be slightly different ...
|
344
|
+
result1 =<<-EOF
|
340
345
|
row1,aa|a,bb|b,cc|c,d,e
|
341
346
|
row2,A,B,C,D,E
|
342
347
|
row20,,,,rr,rr
|
343
348
|
row3,1,2,3,,
|
344
349
|
row4,,,,x,y
|
350
|
+
row6,dd,dd,ee,,
|
351
|
+
EOF
|
352
|
+
result2 =<<-EOF
|
353
|
+
row1,a|aa,b|bb,c|cc,d,e
|
354
|
+
row2,A,B,C,D,E
|
355
|
+
row20,,,,rr,rr
|
356
|
+
row3,1,2,3,,
|
357
|
+
row4,,,,x,y
|
345
358
|
row6,dd,dd,ee,,
|
346
359
|
EOF
|
347
360
|
|
348
361
|
TmpFile.with_file do |f|
|
349
|
-
TSV.
|
362
|
+
TSV.merge_different_fields StringIO.new(file1), StringIO.new(file2), f, ','
|
350
363
|
|
351
|
-
|
364
|
+
# ... so check for either
|
365
|
+
assert(Open.read(f) == result1 || Open.read(f) == result2)
|
352
366
|
end
|
353
367
|
end
|
354
368
|
|
355
|
-
def
|
369
|
+
def test_merge_different_rows_split_lines_tsv
|
356
370
|
file1 =<<-EOF
|
357
371
|
row6,dd,dd,ee
|
358
372
|
row1,a,b,c
|
@@ -376,9 +390,9 @@ row6,dd,dd,ee,,
|
|
376
390
|
EOF
|
377
391
|
|
378
392
|
TmpFile.with_file do |f|
|
379
|
-
data1 = TSV.
|
380
|
-
data2 = TSV.
|
381
|
-
data3 = data1.
|
393
|
+
data1 = TSV.open StringIO.new(file1), :sep => ',', :merge => true
|
394
|
+
data2 = TSV.open StringIO.new(file2), :sep => ',', :merge => true
|
395
|
+
data3 = data1.merge_different_fields(data2)
|
382
396
|
data3.each do |key, list|
|
383
397
|
list.each do |l| l.replace l.sort_by{|v| v.length}.reverse end
|
384
398
|
end
|
@@ -396,12 +410,41 @@ row3,1,2,3
|
|
396
410
|
EOF
|
397
411
|
TmpFile.with_file(file1) do |input|
|
398
412
|
TmpFile.with_file() do |output|
|
399
|
-
TSV.
|
413
|
+
TSV.merge_row_fields Open.open(input), output
|
400
414
|
assert Open.read(output) =~ /a|aa/
|
401
415
|
end
|
402
416
|
end
|
403
417
|
|
404
418
|
|
405
419
|
end
|
420
|
+
|
421
|
+
def test_one2one
|
422
|
+
content1 =<<-EOF
|
423
|
+
#Id ValueA ValueB
|
424
|
+
row1 a|aa|aaa b
|
425
|
+
row2 A B
|
426
|
+
row3 A b|bb
|
427
|
+
EOF
|
428
|
+
|
429
|
+
content2 =<<-EOF
|
430
|
+
#ValueB OtherID
|
431
|
+
b Id1|Id2
|
432
|
+
B Id3
|
433
|
+
bb Id4
|
434
|
+
EOF
|
435
|
+
tsv1 = tsv2 = nil
|
436
|
+
TmpFile.with_file(content1) do |filename|
|
437
|
+
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
438
|
+
end
|
439
|
+
|
440
|
+
TmpFile.with_file(content2) do |filename|
|
441
|
+
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
442
|
+
end
|
443
|
+
|
444
|
+
tsv1.attach tsv2, :one2one => true
|
445
|
+
|
446
|
+
assert_equal %w(ValueA ValueB OtherID), tsv1.fields
|
447
|
+
assert_equal %w(Id1 Id4), tsv1["row3"]["OtherID"]
|
448
|
+
end
|
406
449
|
end
|
407
450
|
|