rbbt-util 1.0.1 → 1.1.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/lib/rbbt/util/cmd.rb +39 -11
- data/lib/rbbt/util/data_module.rb +1 -0
- data/lib/rbbt/util/excel2tsv.rb +2 -1
- data/lib/rbbt/util/log.rb +2 -2
- data/lib/rbbt/util/misc.rb +26 -0
- data/lib/rbbt/util/open.rb +19 -3
- data/lib/rbbt/util/pkg_software.rb +2 -1
- data/lib/rbbt/util/tc_hash.rb +10 -10
- data/lib/rbbt/util/tsv.rb +691 -582
- data/lib/rbbt/util/workflow.rb +4 -0
- data/test/rbbt/util/test_cmd.rb +14 -0
- data/test/rbbt/util/test_misc.rb +12 -0
- data/test/rbbt/util/test_tc_hash.rb +1 -1
- data/test/rbbt/util/test_tsv.rb +110 -0
- data/test/rbbt/util/test_workflow.rb +11 -0
- metadata +7 -4
data/test/rbbt/util/test_cmd.rb
CHANGED
@@ -27,4 +27,18 @@ class TestCmd < Test::Unit::TestCase
|
|
27
27
|
assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => '" "', :in => "test1 test2", :pipe => true).read)
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_error
|
31
|
+
assert_raise CMD::CMDError do CMD.cmd('fake-command') end
|
32
|
+
assert_raise CMD::CMDError do CMD.cmd('ls -fake_option') end
|
33
|
+
|
34
|
+
assert_raise CMD::CMDError do CMD.cmd('fake-command', :stderr => true) end
|
35
|
+
assert_raise CMD::CMDError do CMD.cmd('ls -fake_option', :stderr => true) end
|
36
|
+
|
37
|
+
assert_nothing_raised CMD::CMDError do CMD.cmd('fake-command', :stderr => false, :pipe => true) end
|
38
|
+
assert_nothing_raised CMD::CMDError do CMD.cmd('ls -fake_option', :stderr => false, :pipe => true) end
|
39
|
+
|
40
|
+
assert_raise CMD::CMDError do CMD.cmd('fake-command', :stderr => true, :pipe => true).read end
|
41
|
+
assert_raise CMD::CMDError do CMD.cmd('ls -fake_option', :stderr => true, :pipe => true).read end
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -4,6 +4,18 @@ require 'test/unit'
|
|
4
4
|
|
5
5
|
class TestMisc < Test::Unit::TestCase
|
6
6
|
|
7
|
+
def test_pdf2text_example
|
8
|
+
assert PDF2Text.pdf2text(test_datafile('example.pdf')).read =~ /An Example Paper/i
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_pdf2text_EPAR
|
12
|
+
assert PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB/document_library/EPAR_-_Scientific_Discussion/human/000402/WC500033103.pdf").read =~ /Tamiflu/i
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_pdf2text_wrong
|
16
|
+
assert_raise CMD::CMDError do PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB#") end
|
17
|
+
end
|
18
|
+
|
7
19
|
def test_string2hash
|
8
20
|
assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
|
9
21
|
assert(Misc.string2hash(":true")[:true] == true)
|
data/test/rbbt/util/test_tsv.rb
CHANGED
@@ -648,5 +648,115 @@ row3 a C Id4
|
|
648
648
|
assert_equal ["Pref:A"], tsv["row2"]["ValueA"]
|
649
649
|
end
|
650
650
|
end
|
651
|
+
|
652
|
+
def test_open_stringoptions
|
653
|
+
content =<<-EOF
|
654
|
+
#Id ValueA ValueB OtherID
|
655
|
+
row1 a|aa|aaa b Id1|Id2
|
656
|
+
row2 A B Id3
|
657
|
+
row3 a C Id4
|
658
|
+
EOF
|
659
|
+
|
660
|
+
TmpFile.with_file(content) do |filename|
|
661
|
+
tsv = TSV.new(filename + '#:sep=/\s+/')
|
662
|
+
|
663
|
+
tsv.process "ValueA" do |field_values,key,values|
|
664
|
+
field_values.collect{|v| "Pref:#{v}"}
|
665
|
+
end
|
666
|
+
|
667
|
+
assert_equal ["Pref:A"], tsv["row2"]["ValueA"]
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
def test_select
|
672
|
+
content =<<-EOF
|
673
|
+
#Id ValueA ValueB OtherID
|
674
|
+
row1 a|aa|aaa b Id1|Id2
|
675
|
+
row2 A B Id3
|
676
|
+
row3 a C Id4
|
677
|
+
EOF
|
678
|
+
|
679
|
+
TmpFile.with_file(content) do |filename|
|
680
|
+
tsv = TSV.new(filename + '#:sep=/\s+/')
|
681
|
+
assert tsv.list
|
682
|
+
|
683
|
+
new = tsv.select %w(b Id4)
|
684
|
+
assert_equal %w(row1 row3).sort, new.keys
|
685
|
+
|
686
|
+
new = tsv.select "ValueB" => %w(b Id4)
|
687
|
+
assert_equal %w(row1).sort, new.keys
|
688
|
+
|
689
|
+
new = tsv.select /b|Id4/
|
690
|
+
assert_equal %w(row1 row3).sort, new.keys
|
691
|
+
|
692
|
+
new = tsv.select "ValueB" => /b|Id4/
|
693
|
+
assert_equal %w(row1).sort, new.keys
|
694
|
+
|
695
|
+
tsv = TSV.new(filename + '#:sep=/\s+/#:unique')
|
696
|
+
assert ! tsv.list
|
697
|
+
|
698
|
+
new = tsv.select %w(b Id4)
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
def test_field_compare
|
703
|
+
content =<<-EOF
|
704
|
+
#Id LetterValue#ValueA LetterValue#ValueB OtherID
|
705
|
+
row1 a|aa|aaa b Id1|Id2
|
706
|
+
row2 A B Id3
|
707
|
+
row3 a C Id4
|
708
|
+
EOF
|
709
|
+
|
710
|
+
TmpFile.with_file(content) do |filename|
|
711
|
+
tsv = TSV.new(filename + '#:sep=/\s+/')
|
712
|
+
|
713
|
+
assert tsv.fields.include?("LetterValue")
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_add_field
|
718
|
+
content =<<-EOF
|
719
|
+
#Id LetterValue#ValueA LetterValue#ValueB OtherID
|
720
|
+
row1 a|aa|aaa b Id1|Id2
|
721
|
+
row2 A B Id3
|
722
|
+
row3 a C Id4
|
723
|
+
EOF
|
724
|
+
|
725
|
+
TmpFile.with_file(content) do |filename|
|
726
|
+
tsv = TSV.new(filename + '#:sep=/\s+/')
|
727
|
+
tsv.add_field "Str length" do |k,v|
|
728
|
+
(v.flatten * " ").length
|
729
|
+
end
|
730
|
+
|
731
|
+
|
732
|
+
assert tsv.fields.include?("Str length")
|
733
|
+
end
|
734
|
+
|
735
|
+
end
|
736
|
+
|
737
|
+
def test_tsv_cache
|
738
|
+
content =<<-EOF
|
739
|
+
#Id LetterValue#ValueA LetterValue#ValueB OtherID
|
740
|
+
row1 a|aa|aaa b Id1|Id2
|
741
|
+
row2 A B Id3
|
742
|
+
row3 a C Id4
|
743
|
+
EOF
|
744
|
+
|
745
|
+
TmpFile.with_file(content) do |filename|
|
746
|
+
tsv = CacheHelper.tsv_cache('test_tsv_cache', filename) do
|
747
|
+
TSV.new(filename + '#:sep=/\s+/')
|
748
|
+
end
|
749
|
+
tsv
|
750
|
+
|
751
|
+
tsv1 = CacheHelper.tsv_cache('test_tsv_cache', filename) do
|
752
|
+
assert false
|
753
|
+
end
|
754
|
+
|
755
|
+
assert_equal tsv.fields, tsv1.fields
|
756
|
+
|
757
|
+
CacheHelper.clean 'test_tsv_cache'
|
758
|
+
end
|
759
|
+
|
760
|
+
end
|
651
761
|
end
|
652
762
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Miguel Vazquez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-20 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/rbbt/util/tc_hash.rb
|
118
118
|
- lib/rbbt/util/tmpfile.rb
|
119
119
|
- lib/rbbt/util/tsv.rb
|
120
|
+
- lib/rbbt/util/workflow.rb
|
120
121
|
- share/install/software/lib/install_helpers
|
121
122
|
- test/rbbt/util/test_cmd.rb
|
122
123
|
- test/rbbt/util/test_data_module.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- test/rbbt/util/test_tc_hash.rb
|
130
131
|
- test/rbbt/util/test_tmpfile.rb
|
131
132
|
- test/rbbt/util/test_tsv.rb
|
133
|
+
- test/rbbt/util/test_workflow.rb
|
132
134
|
- test/test_helper.rb
|
133
135
|
- test/test_pkg.rb
|
134
136
|
- test/test_rbbt.rb
|
@@ -180,6 +182,7 @@ test_files:
|
|
180
182
|
- test/rbbt/util/test_tc_hash.rb
|
181
183
|
- test/rbbt/util/test_tmpfile.rb
|
182
184
|
- test/rbbt/util/test_tsv.rb
|
185
|
+
- test/rbbt/util/test_workflow.rb
|
183
186
|
- test/test_helper.rb
|
184
187
|
- test/test_pkg.rb
|
185
188
|
- test/test_rbbt.rb
|