Skip to content

Commit

Permalink
add more high level tests for xml and json output
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Jun 21, 2015
1 parent 9868271 commit 85f7a96
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/commands/unipept/test_pept2lca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,30 @@ def test_run_with_fasta_multiple_batches
assert(lines.next.start_with? '>tost,AALTER,1,root,no rank')
assert_raises(StopIteration) { lines.next }
end

def test_run_with_fasta_multiple_batches_json
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2lca --host http://api.unipept.ugent.be --batch 2 --format json >test AALTER AALER >tost AALTER))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '[')
assert(output.end_with? ']')
assert(!output.include?('}{'))
assert(output.include? 'fasta_header')
end

def test_run_with_fasta_multiple_batches_xml
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2lca --host http://api.unipept.ugent.be --batch 2 --format xml >test AALTER AALER >tost AALTER))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '<results>')
assert(output.end_with? '</results>')
assert(output.include? '<fasta_header>')
end
end
end
25 changes: 25 additions & 0 deletions test/commands/unipept/test_pept2prot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,30 @@ def test_run_with_fasta_multiple_batches
assert(lines.select { |line| line.start_with? '>test,ENFVYIAK,' }.size >= 1)
assert(lines.select { |line| line.start_with? '>tost,EGGAGSSTGQR,' }.size >= 1)
end

def test_run_with_fasta_multiple_batches_json
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2prot --host http://api.unipept.ugent.be --batch 2 --format json >test EGGAGSSTGQR ENFVYIAK >tost EGGAGSSTGQR))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '[')
assert(output.end_with? ']')
assert(!output.include?('}{'))
assert(output.include? 'fasta_header')
end

def test_run_with_fasta_multiple_batches_xml
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2prot --host http://api.unipept.ugent.be --batch 2 --format xml >test EGGAGSSTGQR ENFVYIAK >tost EGGAGSSTGQR))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '<results>')
assert(output.end_with? '</results>')
assert(output.include? '<fasta_header>')
end
end
end
25 changes: 25 additions & 0 deletions test/commands/unipept/test_pept2taxa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,30 @@ def test_run_with_fasta_multiple_batches
assert(lines.select { |line| line.start_with? '>test,ENFVYIAK,' }.size >= 1)
assert(lines.select { |line| line.start_with? '>tost,EGGAGSSTGQR,' }.size >= 1)
end

def test_run_with_fasta_multiple_batches_json
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2taxa --host http://api.unipept.ugent.be --batch 2 --format json >test EGGAGSSTGQR ENFVYIAK >tost EGGAGSSTGQR))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '[')
assert(output.end_with? ']')
assert(!output.include?('}{'))
assert(output.include? 'fasta_header')
end

def test_run_with_fasta_multiple_batches_xml
out, err = capture_io_while do
Commands::Unipept.run(%w(pept2taxa --host http://api.unipept.ugent.be --batch 2 --format xml >test EGGAGSSTGQR ENFVYIAK >tost EGGAGSSTGQR))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '<results>')
assert(output.end_with? '</results>')
assert(output.include? '<fasta_header>')
end
end
end
24 changes: 24 additions & 0 deletions test/commands/unipept/test_taxa2lca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,29 @@ def test_run
assert(lines.next.start_with? 'taxon_id,taxon_name,taxon_rank')
assert(lines.next.start_with? '1678,Bifidobacterium,genus')
end

def test_run_xml
out, err = capture_io_while do
Commands::Unipept.run(%w(taxa2lca --host http://api.unipept.ugent.be --format xml 216816 1680))
end
lines = out.each_line
output = lines.to_a.join('').chomp
assert_equal('', err)
assert(output.start_with? '<results>')
assert(output.end_with? '</results>')
end

def test_run_json
out, err = capture_io_while do
Commands::Unipept.run(%w(taxa2lca --host http://api.unipept.ugent.be --format json 216816 1680))
end
lines = out.each_line
output = lines.to_a.join('').chomp
assert_equal('', err)
assert(output.start_with? '[')
assert(output.end_with? ']')
assert(!output.include?('}{'))
assert(!output.include?(']['))
end
end
end
25 changes: 25 additions & 0 deletions test/commands/unipept/test_taxonomy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,30 @@ def test_run_with_fasta_multiple_batches
assert(lines.select { |line| line.start_with? '>test,216816,' }.size >= 1)
assert(lines.select { |line| line.start_with? '>tost,1,' }.size >= 1)
end

def test_run_with_fasta_multiple_batches_json
out, err = capture_io_while do
Commands::Unipept.run(%w(taxonomy --host http://api.unipept.ugent.be --batch 2 --format json >test 1 216816 >tost 1))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '[')
assert(output.end_with? ']')
assert(!output.include?('}{'))
assert(output.include? 'fasta_header')
end

def test_run_with_fasta_multiple_batches_xml
out, err = capture_io_while do
Commands::Unipept.run(%w(taxonomy --host http://api.unipept.ugent.be --batch 2 --format xml >test 1 216816 >tost 1))
end
lines = out.each_line
assert_equal('', err)
output = lines.to_a.join('').chomp
assert(output.start_with? '<results>')
assert(output.end_with? '</results>')
assert(output.include? '<fasta_header>')
end
end
end

0 comments on commit 85f7a96

Please sign in to comment.