rbbt-util 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rbbt-util.rb +2 -0
- data/lib/rbbt.rb +1 -0
- data/lib/rbbt/util/R.rb +24 -0
- data/lib/rbbt/util/bed.rb +325 -0
- data/lib/rbbt/util/cmd.rb +2 -1
- data/lib/rbbt/util/data_module.rb +25 -34
- data/lib/rbbt/util/excel2tsv.rb +2 -3
- data/lib/rbbt/util/log.rb +5 -0
- data/lib/rbbt/util/misc.rb +29 -1
- data/lib/rbbt/util/open.rb +1 -0
- data/lib/rbbt/util/persistence.rb +109 -0
- data/lib/rbbt/util/pkg_data.rb +114 -62
- data/lib/rbbt/util/rake.rb +78 -0
- data/lib/rbbt/util/tc_hash.rb +7 -1
- data/lib/rbbt/util/tsv.rb +582 -153
- data/lib/rbbt/util/workflow.rb +1 -2
- data/share/lib/R/util.R +89 -0
- data/test/rbbt/util/test_R.rb +9 -0
- data/test/rbbt/util/test_bed.rb +136 -0
- data/test/rbbt/util/test_data_module.rb +10 -10
- data/test/rbbt/util/test_misc.rb +1 -0
- data/test/rbbt/util/test_persistence.rb +60 -0
- data/test/rbbt/util/test_pkg_data.rb +113 -0
- data/test/rbbt/util/test_rake.rb +54 -0
- data/test/rbbt/util/test_tsv.rb +91 -46
- data/test/rbbt/util/test_workflow.rb +5 -2
- data/test/test_helper.rb +4 -0
- data/test/test_pkg.rb +0 -10
- data/test/test_rbbt.rb +3 -48
- metadata +21 -6
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
|
2
|
+
require 'rbbt/util/rake'
|
3
|
+
|
4
|
+
class TestRake < Test::Unit::TestCase
|
5
|
+
def test_run
|
6
|
+
rakefile=<<-EOF
|
7
|
+
require 'rbbt/util/rake'
|
8
|
+
|
9
|
+
file "foo" do |t|
|
10
|
+
Open.write(t.name, 'bar')
|
11
|
+
end
|
12
|
+
EOF
|
13
|
+
|
14
|
+
TmpFile.with_file(rakefile) do |f|
|
15
|
+
RakeHelper.run f, :foo
|
16
|
+
|
17
|
+
assert File.exists? "foo"
|
18
|
+
FileUtils.rm "foo"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_run_default
|
23
|
+
rakefile=<<-EOF
|
24
|
+
require 'rbbt/util/rake'
|
25
|
+
|
26
|
+
file "foo" do |t|
|
27
|
+
Open.write(t.name, 'bar')
|
28
|
+
end
|
29
|
+
EOF
|
30
|
+
|
31
|
+
TmpFile.with_file(rakefile) do |f|
|
32
|
+
RakeHelper.run f
|
33
|
+
|
34
|
+
assert File.exists? "foo"
|
35
|
+
FileUtils.rm "foo"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_files
|
41
|
+
rakefile=<<-EOF
|
42
|
+
require 'rbbt/util/rake'
|
43
|
+
|
44
|
+
file "foo" do |t|
|
45
|
+
Open.write(t.name, 'bar')
|
46
|
+
end
|
47
|
+
EOF
|
48
|
+
|
49
|
+
TmpFile.with_file(rakefile) do |f|
|
50
|
+
assert RakeHelper.files(f).include? "foo"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/test/rbbt/util/test_tsv.rb
CHANGED
@@ -12,8 +12,8 @@ row2 A B
|
|
12
12
|
|
13
13
|
TmpFile.with_file(content) do |filename|
|
14
14
|
data = {}
|
15
|
-
|
16
|
-
assert_equal ["ValueA", "ValueB", "Comment"], fields
|
15
|
+
data, extra = TSV.parse(File.open(filename), :sep => /\s+/, :keep_empty => true)
|
16
|
+
assert_equal ["ValueA", "ValueB", "Comment"], extra[:fields]
|
17
17
|
assert_equal ["c"], data["row1"][2]
|
18
18
|
assert_equal [""], data["row2"][2]
|
19
19
|
end
|
@@ -27,7 +27,7 @@ row2 A B C
|
|
27
27
|
EOF
|
28
28
|
|
29
29
|
TmpFile.with_file(content) do |filename|
|
30
|
-
tsv = TSV.new(File.open(filename), :sep => /\s/)
|
30
|
+
tsv = TSV.new(File.open(filename), :double, :sep => /\s/)
|
31
31
|
assert_equal [["a"],["c"]], tsv.reorder(:main, ["ValueA", "Comment"])["row1"]
|
32
32
|
end
|
33
33
|
end
|
@@ -64,9 +64,9 @@ row2 A B
|
|
64
64
|
|
65
65
|
TmpFile.with_file(content) do |filename|
|
66
66
|
data = {}
|
67
|
-
|
68
|
-
assert_equal "Id", key_field
|
69
|
-
assert_equal ["ValueA", "ValueB"], fields
|
67
|
+
data, extra = TSV.parse(File.open(filename), :sep => /\s+/)
|
68
|
+
assert_equal "Id", extra[:key_field]
|
69
|
+
assert_equal ["ValueA", "ValueB"], extra[:fields]
|
70
70
|
assert_equal ["a", "aa", "aaa"], data["row1"][0]
|
71
71
|
end
|
72
72
|
end
|
@@ -79,7 +79,7 @@ row2 A B Id3
|
|
79
79
|
EOF
|
80
80
|
|
81
81
|
TmpFile.with_file(content) do |filename|
|
82
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
82
|
+
tsv = TSV.new(File.open(filename), :double, :sep => /\s+/, :key => "OtherID", :large => true)
|
83
83
|
assert_equal "OtherID", tsv.key_field
|
84
84
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
85
85
|
assert_equal ["a", "aa", "aaa"], tsv["Id2"][1]
|
@@ -94,7 +94,7 @@ row2 A B Id3
|
|
94
94
|
EOF
|
95
95
|
|
96
96
|
TmpFile.with_file(content) do |filename|
|
97
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
97
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID")
|
98
98
|
assert_equal "OtherID", tsv.key_field
|
99
99
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
100
100
|
assert_equal ["a", "aa", "aaa"], tsv["Id1"][1]
|
@@ -111,7 +111,7 @@ row3 a C Id4
|
|
111
111
|
EOF
|
112
112
|
|
113
113
|
TmpFile.with_file(content) do |filename|
|
114
|
-
tsv = TSV.open_file(filename + '#:sep=/\s+/#:
|
114
|
+
tsv = TSV.open_file(filename + '#:sep=/\s+/#:key=OtherID')
|
115
115
|
assert_equal "OtherID", tsv.key_field
|
116
116
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
117
117
|
assert_equal ["a", "aa", "aaa"], tsv["Id1"][1]
|
@@ -129,9 +129,9 @@ row2 A B Id3
|
|
129
129
|
EOF
|
130
130
|
|
131
131
|
TmpFile.with_file(content) do |filename|
|
132
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
132
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :others => 2)
|
133
133
|
assert_equal ["b"], tsv["Id2"][0]
|
134
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
134
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :others => 'ValueB')
|
135
135
|
assert_equal ["b"], tsv["Id2"][0]
|
136
136
|
end
|
137
137
|
end
|
@@ -144,7 +144,7 @@ row2 A B Id3
|
|
144
144
|
EOF
|
145
145
|
|
146
146
|
TmpFile.with_file(content) do |filename|
|
147
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
147
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :case_insensitive => true)
|
148
148
|
assert_equal "OtherID", tsv.key_field
|
149
149
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
150
150
|
assert_equal ["a", "aa", "aaa"], tsv["id1"][1]
|
@@ -160,15 +160,16 @@ row2 A B Id3
|
|
160
160
|
EOF
|
161
161
|
|
162
162
|
TmpFile.with_file(content) do |filename|
|
163
|
-
tsv = TSV.new(filename, :sep => /\s+/, :
|
163
|
+
tsv = TSV.new(filename, :sep => /\s+/, :key => "OtherID", :persistence => true)
|
164
164
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
165
165
|
tsv['Id4'] = [["row3"],["aA"],["bB","bbBB"]]
|
166
166
|
assert_equal ["aA"], tsv["Id4"][1]
|
167
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
167
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :persistence => true)
|
168
168
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
169
|
+
|
169
170
|
assert_equal ["aA"], tsv["Id4"][1]
|
170
171
|
assert_equal [["b"],["B"]], tsv.values_at("Id1", "Id3").collect{|values| values[2]}
|
171
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
172
|
+
tsv = TSV.new(File.open(filename), :flat, :sep => /\s+/, :key => "OtherID", :persistence => false)
|
172
173
|
assert(tsv["Id3"].include? "A")
|
173
174
|
end
|
174
175
|
end
|
@@ -181,7 +182,7 @@ row2 A B Id3
|
|
181
182
|
|
182
183
|
TmpFile.with_file(content) do |filename|
|
183
184
|
tsv = TSV.new(File.open(filename), :sep => /\s+/)
|
184
|
-
index = tsv.index(:case_insensitive => true, :
|
185
|
+
index = tsv.index(:case_insensitive => true, :target => 2)
|
185
186
|
assert index["row1"].include? "Id1"
|
186
187
|
end
|
187
188
|
end
|
@@ -195,14 +196,14 @@ row2 A B Id3
|
|
195
196
|
EOF
|
196
197
|
|
197
198
|
TmpFile.with_file(content) do |filename|
|
198
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
199
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :persistence => false)
|
199
200
|
index = tsv.index(:case_insensitive => true)
|
200
201
|
assert index["row1"].include? "Id1"
|
201
202
|
assert_equal "OtherID", index.key_field
|
202
203
|
end
|
203
204
|
|
204
205
|
TmpFile.with_file(content) do |filename|
|
205
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
206
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID")
|
206
207
|
index = tsv.index(:case_insensitive => true)
|
207
208
|
assert index["row1"].include? "Id1"
|
208
209
|
assert_equal "OtherID", index.key_field
|
@@ -217,7 +218,7 @@ row2 A a|B Id3
|
|
217
218
|
EOF
|
218
219
|
|
219
220
|
TmpFile.with_file(content) do |filename|
|
220
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
221
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :persistence => true)
|
221
222
|
index = tsv.index(:case_insensitive => false, :order => true)
|
222
223
|
assert_equal "Id1", index['a'].first
|
223
224
|
assert_equal "Id3", index['A'].first
|
@@ -225,7 +226,7 @@ row2 A a|B Id3
|
|
225
226
|
end
|
226
227
|
|
227
228
|
TmpFile.with_file(content) do |filename|
|
228
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
229
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID")
|
229
230
|
index = tsv.index(:case_insensitive => true)
|
230
231
|
assert index["row1"].include? "Id1"
|
231
232
|
assert_equal "OtherID", index.key_field
|
@@ -240,7 +241,7 @@ row2 A B Id3
|
|
240
241
|
EOF
|
241
242
|
|
242
243
|
TmpFile.with_file(content) do |filename|
|
243
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
244
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :persistence => true)
|
244
245
|
index = tsv.index(:case_insensitive => true)
|
245
246
|
assert index.values_at(*["row1"]).first.include? "Id1"
|
246
247
|
end
|
@@ -254,7 +255,7 @@ row2 A B Id3
|
|
254
255
|
EOF
|
255
256
|
|
256
257
|
TmpFile.with_file(content) do |filename|
|
257
|
-
tsv = TSV.new(File.open(filename), :sep => /\s+/, :
|
258
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :key => "OtherID", :case_insensitive => true)
|
258
259
|
assert_equal "OtherID", tsv.key_field
|
259
260
|
assert_equal ["Id", "ValueA", "ValueB"], tsv.fields
|
260
261
|
assert_equal ["a", "aa", "aaa"], tsv["id1"][1]
|
@@ -273,16 +274,31 @@ row2 A B Id3
|
|
273
274
|
require 'rbbt/sources/organism'
|
274
275
|
filename = File.join(Organism.datadir('Sce'), 'identifiers')
|
275
276
|
missing = true
|
276
|
-
index = TSV.index(filename, :persistence => true, :
|
277
|
+
index = TSV.index(filename, :persistence => true, :key => "Associated Gene Name")
|
277
278
|
assert index['1020'].include? 'CDK5'
|
278
|
-
index = TSV.index(filename, :persistence => true, :
|
279
|
+
index = TSV.index(filename, :persistence => true, :key => "Associated Gene Name")
|
279
280
|
assert index[[nil,'1020']].include? 'CDK5'
|
280
|
-
index = TSV.index(filename, :persistence => true, :
|
281
|
+
index = TSV.index(filename, :persistence => true, :key => "Associated Gene Name")
|
281
282
|
assert index[['MISSING','1020']].include? 'CDK5'
|
282
283
|
rescue Exception
|
283
284
|
end
|
284
285
|
end
|
285
286
|
|
287
|
+
def test_grep
|
288
|
+
content =<<-EOF
|
289
|
+
#Id ValueA ValueB OtherID
|
290
|
+
row1 a|aa|aaa b Id1|Id2
|
291
|
+
row2 A B Id3
|
292
|
+
EOF
|
293
|
+
|
294
|
+
TmpFile.with_file(content) do |filename|
|
295
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :grep => %w(row1))
|
296
|
+
assert tsv.keys.include? "row1"
|
297
|
+
assert( ! tsv.keys.include?("row2"))
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
|
286
302
|
|
287
303
|
def test_sort
|
288
304
|
content =<<-EOF
|
@@ -316,6 +332,27 @@ row2 A B Id3
|
|
316
332
|
end
|
317
333
|
end
|
318
334
|
|
335
|
+
def test_to_s_ordered
|
336
|
+
content =<<-EOF
|
337
|
+
#Id ValueA ValueB OtherID
|
338
|
+
row1 a|aa|aaa b Id1|Id2
|
339
|
+
row2 A B Id3
|
340
|
+
EOF
|
341
|
+
|
342
|
+
content2 =<<-EOF
|
343
|
+
#Id ValueA ValueB OtherID
|
344
|
+
row2 A B Id3
|
345
|
+
row1 a|aa|aaa b Id1|Id2
|
346
|
+
EOF
|
347
|
+
|
348
|
+
|
349
|
+
TmpFile.with_file(content) do |filename|
|
350
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/)
|
351
|
+
assert_equal content, tsv.to_s(%w(row1 row2))
|
352
|
+
assert_not_equal content, tsv.to_s(%w(row2 row1))
|
353
|
+
assert_equal content2, tsv.to_s(%w(row2 row1))
|
354
|
+
end
|
355
|
+
end
|
319
356
|
|
320
357
|
def test_smart_merge_single
|
321
358
|
content1 =<<-EOF
|
@@ -332,11 +369,11 @@ C B Id3
|
|
332
369
|
|
333
370
|
tsv1 = tsv2 = nil
|
334
371
|
TmpFile.with_file(content1) do |filename|
|
335
|
-
tsv1 = TSV.new(File.open(filename), :sep => /\s
|
372
|
+
tsv1 = TSV.new(File.open(filename), :list, :sep => /\s+/)
|
336
373
|
end
|
337
374
|
|
338
375
|
TmpFile.with_file(content2) do |filename|
|
339
|
-
tsv2 = TSV.new(File.open(filename), :sep => /\s
|
376
|
+
tsv2 = TSV.new(File.open(filename), :list, :sep => /\s+/)
|
340
377
|
end
|
341
378
|
|
342
379
|
tsv1.smart_merge tsv2, "ValueB"
|
@@ -490,6 +527,7 @@ B BB
|
|
490
527
|
|
491
528
|
assert_equal %w(a aa aaa aaaa), tsv1["row1"]["ValueA"]
|
492
529
|
end
|
530
|
+
|
493
531
|
def test_smart_merge_common_fields
|
494
532
|
content1 =<<-EOF
|
495
533
|
#Id ValueA ValueB
|
@@ -649,6 +687,20 @@ row3 a C Id4
|
|
649
687
|
end
|
650
688
|
end
|
651
689
|
|
690
|
+
def test_break_with_fix
|
691
|
+
content =<<-EOF
|
692
|
+
#Id ValueA ValueB OtherID
|
693
|
+
row1 a|aa|aaa b Id1|Id2
|
694
|
+
row2 A B Id3
|
695
|
+
row3 a C Id4
|
696
|
+
EOF
|
697
|
+
|
698
|
+
TmpFile.with_file(content) do |filename|
|
699
|
+
tsv = TSV.new(File.open(filename), :sep => /\s+/, :fix => proc{|l| l =~ /^row2/? nil : l})
|
700
|
+
assert_equal %w(row1), tsv.keys
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
652
704
|
def test_open_stringoptions
|
653
705
|
content =<<-EOF
|
654
706
|
#Id ValueA ValueB OtherID
|
@@ -678,7 +730,7 @@ row3 a C Id4
|
|
678
730
|
|
679
731
|
TmpFile.with_file(content) do |filename|
|
680
732
|
tsv = TSV.new(filename + '#:sep=/\s+/')
|
681
|
-
assert tsv.
|
733
|
+
assert tsv.type == :double
|
682
734
|
|
683
735
|
new = tsv.select %w(b Id4)
|
684
736
|
assert_equal %w(row1 row3).sort, new.keys
|
@@ -692,8 +744,8 @@ row3 a C Id4
|
|
692
744
|
new = tsv.select "ValueB" => /b|Id4/
|
693
745
|
assert_equal %w(row1).sort, new.keys
|
694
746
|
|
695
|
-
tsv = TSV.new(filename + '#:sep=/\s+/#:
|
696
|
-
assert
|
747
|
+
tsv = TSV.new(filename + '#:sep=/\s+/#:type=:flat')
|
748
|
+
assert tsv.type != :double
|
697
749
|
|
698
750
|
new = tsv.select %w(b Id4)
|
699
751
|
end
|
@@ -727,15 +779,14 @@ row3 a C Id4
|
|
727
779
|
tsv.add_field "Str length" do |k,v|
|
728
780
|
(v.flatten * " ").length
|
729
781
|
end
|
730
|
-
|
731
782
|
|
732
783
|
assert tsv.fields.include?("Str length")
|
733
784
|
end
|
734
785
|
|
735
786
|
end
|
736
787
|
|
737
|
-
def
|
738
|
-
|
788
|
+
def test_cast
|
789
|
+
content =<<-EOF
|
739
790
|
#Id LetterValue#ValueA LetterValue#ValueB OtherID
|
740
791
|
row1 a|aa|aaa b Id1|Id2
|
741
792
|
row2 A B Id3
|
@@ -743,20 +794,14 @@ row3 a C Id4
|
|
743
794
|
EOF
|
744
795
|
|
745
796
|
TmpFile.with_file(content) do |filename|
|
746
|
-
tsv =
|
747
|
-
|
748
|
-
|
749
|
-
tsv
|
750
|
-
|
751
|
-
tsv1 = CacheHelper.tsv_cache('test_tsv_cache', filename) do
|
752
|
-
assert false
|
753
|
-
end
|
797
|
+
tsv = TSV.new(filename + '#:sep=/\s+/#:cast="to_sym"')
|
798
|
+
assert tsv['row1']["OtherID"].include?(:Id1)
|
799
|
+
assert ! tsv['row1']["OtherID"].include?("Id1")
|
754
800
|
|
755
|
-
|
756
|
-
|
757
|
-
|
801
|
+
tsv = TSV.new(filename + '#:sep=/\s+/')
|
802
|
+
assert tsv['row1']["OtherID"].include?("Id1")
|
803
|
+
assert ! tsv['row1']["OtherID"].include?(:Id1)
|
758
804
|
end
|
759
|
-
|
760
|
-
end
|
805
|
+
end
|
761
806
|
end
|
762
807
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
require 'rbbt'
|
2
3
|
require 'rbbt/util/tsv'
|
3
4
|
require 'rbbt/util/tmpfile'
|
5
|
+
require 'rbbt/util/workflow'
|
4
6
|
|
5
|
-
class
|
7
|
+
class TestWorkflow < Test::Unit::TestCase
|
6
8
|
|
7
|
-
def
|
9
|
+
def test_true
|
10
|
+
assert true
|
8
11
|
end
|
9
12
|
|
10
13
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
require 'rbbt/util/tmpfile'
|
5
|
+
require 'rbbt/util/log'
|
6
|
+
require 'fileutils'
|
4
7
|
|
5
8
|
class Test::Unit::TestCase
|
9
|
+
include FileUtils
|
6
10
|
def test_datafile(file)
|
7
11
|
File.join(File.dirname(__FILE__), 'data', file)
|
8
12
|
end
|
data/test/test_pkg.rb
CHANGED
@@ -19,16 +19,6 @@ module B
|
|
19
19
|
self.load_cfg(%w(datadir), {"datadir" => "/tmp/B"}.to_yaml)
|
20
20
|
end
|
21
21
|
|
22
|
-
module DA
|
23
|
-
PKG=A
|
24
|
-
extend DataModule
|
25
|
-
end
|
26
|
-
|
27
|
-
module DB
|
28
|
-
PKG=B
|
29
|
-
extend DataModule
|
30
|
-
end
|
31
|
-
|
32
22
|
class TestPKG < Test::Unit::TestCase
|
33
23
|
def test_datadir
|
34
24
|
assert_equal "/tmp/A", A.datadir
|
data/test/test_rbbt.rb
CHANGED
@@ -5,54 +5,9 @@ require 'rbbt/util/open'
|
|
5
5
|
|
6
6
|
class TestRbbt < Test::Unit::TestCase
|
7
7
|
def test_url
|
8
|
-
Rbbt.
|
9
|
-
assert
|
10
|
-
FileUtils.
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_proc
|
14
|
-
Rbbt.add_datafiles :test => ['test', proc{'test'}]
|
15
|
-
assert(Open.read(Rbbt.find_datafile('test')) == 'test')
|
16
|
-
FileUtils.rm_rf File.dirname(Rbbt.find_datafile('test'))
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_Rakefile
|
20
|
-
sharedir = PKGData.sharedir_for_file(__FILE__)
|
21
|
-
|
22
|
-
FileUtils.rmtree File.join(Rbbt.datadir, 'rake')
|
23
|
-
FileUtils.mkdir_p File.join(sharedir, 'install', 'rake')
|
24
|
-
File.open(File.join(sharedir, 'install', 'rake', 'Rakefile'), 'w') do |f|
|
25
|
-
f.puts "task :default do File.open('foo', 'w') do |f| f.puts 'bar' end end"
|
26
|
-
end
|
27
|
-
|
28
|
-
Rbbt.add_datafiles :rake => ['', 'rake']
|
29
|
-
|
30
|
-
assert_equal 'bar', Open.read(File.join(Rbbt.datadir, 'rake', 'foo')).chomp
|
31
|
-
|
32
|
-
FileUtils.rmtree File.join(sharedir, 'install', 'rake')
|
33
|
-
FileUtils.rmtree File.join(Rbbt.datadir, 'rake')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_Rakefile_with_file
|
37
|
-
sharedir = PKGData.sharedir_for_file(__FILE__)
|
38
|
-
|
39
|
-
FileUtils.mkdir_p File.join(sharedir, 'install', 'rake')
|
40
|
-
File.open(File.join(sharedir, 'install', 'rake', 'Rakefile'), 'w') do |f|
|
41
|
-
f.puts "\
|
42
|
-
task :default do File.open('foo', 'w') do |f| f.puts 'bar' end end
|
43
|
-
task 'file1' do |t| File.open(t.name, 'w') do |f| f.puts 'file 1' end end
|
44
|
-
"
|
45
|
-
end
|
46
|
-
|
47
|
-
Rbbt.add_datafiles 'rake/file1' => ['', 'rake']
|
48
|
-
|
49
|
-
assert(! File.exists?(File.join(Rbbt.datadir, 'rake', 'foo')))
|
50
|
-
assert(File.exists?(File.join(Rbbt.datadir, 'rake', 'file1')))
|
51
|
-
assert_equal('file 1', Open.read(File.join(Rbbt.datadir, 'rake', 'file1')).chomp)
|
52
|
-
assert_equal('file 1', Open.read(Rbbt.find_datafile('rake/file1')).chomp)
|
53
|
-
|
54
|
-
FileUtils.rm_rf File.join(sharedir, 'install', 'rake')
|
55
|
-
FileUtils.rm_rf File.join(Rbbt.datadir, 'rake')
|
8
|
+
Rbbt.claim :test_url, 'http://google.com'
|
9
|
+
assert Rbbt.files.test_url.read =~ /html/
|
10
|
+
FileUtils.rm Rbbt.files.test_url
|
56
11
|
end
|
57
12
|
|
58
13
|
def test_xclip
|