From: martinahansen Date: Fri, 13 Aug 2010 08:51:56 +0000 (+0000) Subject: fixed type bug in ruby code X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=98ca97c89b4541bb155d16dcdf02c6c19d4f3a0d;p=biopieces.git fixed type bug in ruby code git-svn-id: http://biopieces.googlecode.com/svn/trunk@1057 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/swapcase_seq b/bp_bin/swapcase_seq index 9681ae2..4831f2a 100755 --- a/bp_bin/swapcase_seq +++ b/bp_bin/swapcase_seq @@ -35,7 +35,7 @@ casts = [] bp = Biopieces.new -options = bp.parse(ARGV,casts) +options = bp.parse(ARGV, casts) bp.each_record do |record| record["SEQ"].swapcase! if record.has_key? "SEQ" diff --git a/code_python/Cjung/Args.pyc b/code_python/Cjung/Args.pyc index 795e1a5..4c39c4a 100644 Binary files a/code_python/Cjung/Args.pyc and b/code_python/Cjung/Args.pyc differ diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index 4dc51b1..3bc2cc2 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -61,6 +61,7 @@ class Biopieces # records in the stream. def each_record @in = Stream::open(@options, mode="r", @input) unless @in.is_a? IO + return if @in.nil? record = {} @@ -448,9 +449,9 @@ class OptionHandler def options_check_allowed(cast) if cast[:allowed] and @options.has_key? cast[:long] allowed_hash = {} - cast[:allowed].split(',').each { |a| allowed_hash[a] = 1 } + cast[:allowed].split(',').each { |a| allowed_hash[a.to_s] = 1 } - raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash.has_key? @options[cast[:long]] + raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash.has_key? @options[cast[:long]].to_s end end @@ -458,7 +459,7 @@ class OptionHandler def options_check_disallowed(cast) if cast[:disallowed] and @options.has_key? cast[:long] cast[:disallowed].split(',').each do |val| - raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed" if val == @options[cast[:long]] + raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed" if val.to_s == @options[cast[:long]].to_s end end end @@ -550,6 +551,7 @@ class Stream < IO # Opens a reads stream to a list of files. def self.read(files) + return if files.nil? #TODO case/when self.zipped?(files) ? self.zread(files) : self.nread(files) end diff --git a/code_ruby/Maasha/test/test_biopieces.rb b/code_ruby/Maasha/test/test_biopieces.rb index 0f97107..9770bc3 100755 --- a/code_ruby/Maasha/test/test_biopieces.rb +++ b/code_ruby/Maasha/test/test_biopieces.rb @@ -1,6 +1,30 @@ #!/usr/bin/env ruby # $:.unshift File.join(File.dirname(__FILE__),'..','lib') +# Copyright (C) 2007-2010 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# This software is part of the Biopieces framework (www.biopieces.org). + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + require 'test/unit' require 'mocha' require 'biopieces' @@ -115,7 +139,7 @@ class OptionTest < Test::Unit::TestCase end test "Biopieces#parse with legal allowed cast values don't raise" do - ["foo,bar",nil].each do |allowed| + ["foo,bar,0",nil].each do |allowed| argv = [] casts = [{:long=>"foo", :short=>"f", :type=>"int", :mandatory=>false, :default=>nil, :allowed=>allowed, :disallowed=>nil}] assert_nothing_raised(CastError) { @bp.parse(argv, casts, SCRIPT_PATH) } @@ -131,7 +155,7 @@ class OptionTest < Test::Unit::TestCase end test "Biopieces#parse with legal disallowed cast values don't raise" do - ["foo,bar",nil].each do |disallowed| + ["foo,bar,0",nil].each do |disallowed| argv = [] casts = [{:long=>"foo", :short=>"f", :type=>"int", :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>disallowed}] assert_nothing_raised(CastError) { @bp.parse(argv, casts, SCRIPT_PATH) }