test/test_scaffolder.rb in scaffolder-0.2.6 vs test/test_scaffolder.rb in scaffolder-0.4.0
- old
+ new
@@ -1,85 +1,116 @@
require 'helper'
class TestScaffolder < Test::Unit::TestCase
context Scaffolder do
-
+
+ Scaffolder::Region::Mock = Class.new(Scaffolder::Region)
+
setup do
- @sequence = File.join(File.dirname(__FILE__),'data','sequences.fna')
- @assembly = [ {"sequence" => { "source" => "sequence1" } } ]
- @expect = {:name => 'sequence1', :start => nil, :end => nil,
- :sequence => 'ATGCCAGATAACTGACTAGCATG', :reverse => nil}
+ @sequence = nil
+ @data = [{'mock' => Hash.new}]
end
- context "when parsing a sequence tag" do
+ context 'parsing a scaffold file' do
- should "create sequence" do
- mock(Scaffolder::Sequence).new(@expect)
- Scaffolder.new @assembly, @sequence
+ setup do
+ Bio::FlatFile.stubs(:auto).with(@sequence).returns({})
end
- should "create sequence with coordinates" do
- @assembly.first['sequence'].update('start' => 2, 'end' => 5)
- mock(Scaffolder::Sequence).new(@expect.update({:start => 2, :end => 5 }))
- Scaffolder.new @assembly, @sequence
+ should "fetch correct region class type" do
+ Scaffolder::Region.expects(:'[]').with('mock').returns(Scaffolder::Region::Mock)
+ Scaffolder.new(@data,@sequence)
end
- should "create sequence with reverse" do
- @assembly.first['sequence'].update('reverse' => true)
- mock(Scaffolder::Sequence).new(@expect.update({:reverse => true }))
- Scaffolder.new @assembly, @sequence
+ should "pass data to region object" do
+ Scaffolder::Region::Mock.expects(:generate).with(@data.first['mock'])
+ Scaffolder.new(@data,@sequence)
end
- should "throw an error when source doesn't have a matching sequence" do
- @assembly.first['sequence'].update('source' => 'sequence3')
- assert_raise(ArgumentError){ Scaffolder.new @assembly, @sequence }
- end
end
- context "parsing an assembly with sequence inserts" do
+ context 'parsing a scaffold file with a source keyword' do
setup do
- @assembly.first['sequence'].update({"inserts" => [{
- "source" => "insert1", "start" => 5, "stop" => 10, "reverse" => true
- }]})
+ Bio::FlatFile.stubs(:auto).with(@sequence).returns([
+ stub(:definition => 'seq1', :seq => 'ATGC')])
end
- should "pass inserts to sequence object" do
- params = {:start => 5, :stop => 10,
- :sequence => 'GGTAGTA', :reverse => true}
+ should "should also pass raw_sequence from flat file" do
+ @data.first['mock']['source'] = 'seq1'
+ Scaffolder::Region::Mock.any_instance.expects(:source).with('seq1')
+ Scaffolder::Region::Mock.any_instance.expects(:raw_sequence).with('ATGC')
+ Scaffolder.new(@data,@sequence)
+ end
- insert = Scaffolder::Insert.new(params)
+ end
- mock.instance_of(Scaffolder::Sequence).add_inserts([insert])
- mock(Scaffolder::Insert).new(params){insert}
+ context 'updating each data hash with raw_sequence attributes' do
- Scaffolder.new @assembly, @sequence
+ setup do
+ @seqs = {'seq1' => 'AAA'}
+ @expected = {'source' => 'seq1', 'raw_sequence' => @seqs['seq1']}
end
- should "throw and error when insert does not have a matching sequence" do
- @assembly.first['sequence']['inserts'].first.update({
- "source" => "missing"})
- assert_raise(ArgumentError){ Scaffolder.new @assembly, @sequence }
+ should "do nothing when no source keyword" do
+ test = {'something' => 'nothing'}
+ assert_equal(test,Scaffolder.update_with_sequence(test,@seqs))
end
- end
+ should "add raw_sequence to simple hash" do
+ test = {'source' => 'seq1'}
+ assert_equal(@expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
- context "when parsing an assembly with an unresolved region" do
+ should "add raw_sequence to a nested hash" do
+ test = {'something' => {'source' => 'seq1'}}
+ expected = {'something' => @expected}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
- setup{ @assembly = [ {"unresolved" => { "length" => 5 } } ] }
+ should "add raw_sequence to a twice nested hash" do
+ test = {'something' => {'other' => {'source' => 'seq1'}}}
+ expected = {'something' => {'other' => @expected}}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
- should 'create an unresolved region' do
- mock(Scaffolder::Region).new(:unresolved,'N'*5)
- Scaffolder.new @assembly, @sequence
+ should "add raw_sequence to simple hash inside an array" do
+ test = [{'source' => 'seq1'}]
+ expected = [@expected]
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
end
- end
+ should "add raw_sequence to a nested hash inside an array" do
+ test = {'something' => [{'source' => 'seq1'}]}
+ expected = {'something' => [@expected]}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
- context "when parsing an unknown tag" do
- setup{ @assembly = [{'non_standard_tag' => []}] }
- should "throw an argument error" do
- assert_raise(ArgumentError){ Scaffolder.new @assembly, @sequence }
+ should "add raw_sequence to two nested hashes inside an array" do
+ test = {'something' => [{'source' => 'seq1'},{'source' => 'seq1'}]}
+ expected = {'something' => [@expected,@expected]}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
end
+
+ should "add raw_sequence to a hash inside a hash inside an array" do
+ test = {'something' => [{'else' => {'source' => 'seq1'}}]}
+ expected = {'something' => [{'else' => @expected}]}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
+
+ should "add raw_sequence to a twice nested (hash inside an array)" do
+ test = {'something' => [{'else' => [{'source' => 'seq1'}]}]}
+ expected = {'something' => [{'else' => [@expected]}]}
+ assert_equal(expected,Scaffolder.update_with_sequence(test,@seqs))
+ end
+
+ should "throw an UnknownSequenceError when no matching sequence" do
+ test = {'source' => 'non_existent_sequence'}
+ assert_raise(Scaffolder::Errors::UnknownSequenceError) do
+ Scaffolder.update_with_sequence(test,@seqs)
+ end
+ end
+
end
end
end