From: martinahansen Date: Fri, 28 May 2010 15:11:44 +0000 (+0000) Subject: trouble with list of list and class Cast X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c3b369e63898705c2cf1feba0c99fffe53b21522;p=biopieces.git trouble with list of list and class Cast git-svn-id: http://biopieces.googlecode.com/svn/trunk@979 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index 2459394..f1a448e 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -28,10 +28,9 @@ class Biopieces # and finally checking the options according to the casts. Returns nil if # argv is empty, otherwise an options hash. def parse(argv,cast_list=[],script_path=$0) - casts = Casts.new(cast_list) + casts = Casts.new(cast_list) - pp casts.class - pp casts.methods + pp casts @script_path = script_path @@ -465,18 +464,19 @@ class Casts < Array TYPES = %w[flag string list int uint float file file! files files! dir dir! genome] MANDATORY = %w[long short type mandatory default allowed disallowed] - def initialize(casts=[]) - @casts = casts + def initialize(cast_list=[]) + @cast_list = cast_list ubiquitous check + self << @cast_list end # Add ubiquitous options casts. def ubiquitous - @casts << {:long => 'help', :short => '?', :type => 'flag', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} - @casts << {:long => 'stream_in', :short => 'I', :type => 'files!', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} - @casts << {:long => 'stream_out', :short => 'O', :type => 'file', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} - @casts << {:long => 'verbose', :short => 'v', :type => 'flag', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} + @cast_list << {:long => 'help', :short => '?', :type => 'flag', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} + @cast_list << {:long => 'stream_in', :short => 'I', :type => 'files!', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} + @cast_list << {:long => 'stream_out', :short => 'O', :type => 'file', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} + @cast_list << {:long => 'verbose', :short => 'v', :type => 'flag', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil} end # Check integrity of the casts. @@ -488,7 +488,7 @@ class Casts < Array # Check if all mandatory keys are present in casts and raise if not. def check_keys - @casts.each do |cast| + @cast_list.each do |cast| MANDATORY.each do |mandatory| raise CastError, "Missing symbol in cast: '#{mandatory.to_sym}'" unless cast.has_key? mandatory.to_sym end @@ -497,7 +497,7 @@ class Casts < Array # Check if all values in casts are valid. def check_values - @casts.each do |cast| + @cast_list.each do |cast| check_val_long(cast) check_val_short(cast) check_val_type(cast) @@ -568,7 +568,7 @@ class Casts < Array # Check cast for duplicate long or short options names. def check_duplicates check_hash = {} - @casts.each do |cast| + @cast_list.each do |cast| raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash.has_key? cast[:long] raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash.has_key? cast[:short] check_hash[cast[:long]] = true diff --git a/code_ruby/Maasha/test/test_biopieces.rb b/code_ruby/Maasha/test/test_biopieces.rb index 1baa8e3..d007d35 100755 --- a/code_ruby/Maasha/test/test_biopieces.rb +++ b/code_ruby/Maasha/test/test_biopieces.rb @@ -341,14 +341,4 @@ class OptionTest < Test::Unit::TestCase assert_nothing_raised(ArgumentError) { @bp.parse(argv, casts, SCRIPT_PATH) } end end - - test "Biopieces#puts outputs correctly" do - argv = [] - casts = [] - @bp.expects(:print_usage_and_exit).with() - options = @bp.parse(argv, casts, SCRIPT_PATH) - record = {"foo" => "bar"} - - assert_equal("foo: bar\n---\n", @bp.puts(record)) - end end