Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Jan 18, 2017
1 parent 3b92810 commit 129881f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/commands/unipept/test_pept2prot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ def test_required_fields
assert_equal(['peptide'], pept2prot.required_fields)
end

def test_meganize_options
command = Cri::Command.define { name 'pept2prot' }
pept2prot = Commands::Pept2prot.new({ meganize: true, host: 'http://api.unipept.ugent.be' }, [], command)
assert(pept2prot.options[:all])
assert_equal(['peptide,refseq_protein_ids'], pept2prot.options[:select])
assert_equal('blast', pept2prot.options[:format])
end

def test_meganize_options_overridecommand
command = Cri::Command.define { name 'pept2prot' }
pept2prot = Commands::Pept2prot.new({ meganize: true, format: 'xml', all: false, select: ['something'], host: 'http://api.unipept.ugent.be' }, [], command)
assert(pept2prot.options[:all])
assert_equal(['peptide,refseq_protein_ids'], pept2prot.options[:select])
assert_equal('blast', pept2prot.options[:format])
end

def test_help
out, _err = capture_io_while do
assert_raises SystemExit do
Expand Down
29 changes: 29 additions & 0 deletions test/test_formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_available_formatters
assert(formatters.include?('json'))
assert(formatters.include?('csv'))
assert(formatters.include?('xml'))
assert(formatters.include?('blast'))
end

def test_default_formatter
Expand All @@ -29,6 +30,9 @@ def test_new_for_format
formatter = Formatter.new_for_format('csv')
assert_equal('csv', formatter.type)

formatter = Formatter.new_for_format('blast')
assert_equal('blast', formatter.type)

formatter = Formatter.new_for_format('blah')
assert_equal('csv', formatter.type)
end
Expand Down Expand Up @@ -121,6 +125,31 @@ def test_format_with_fasta
end
end

class BlastFormatterTestCase < Unipept::TestCase
def formatter
Formatter.new_for_format('blast')
end

def test_header
assert_equal('', formatter.header(nil, nil))
end

def test_footer
assert_equal('', formatter.footer)
end

def test_type
assert_equal('blast', formatter.type)
end

def test_convert
object = [{ 'peptide' => 'MDGTEYIIVK', 'refseq_protein_ids' => 'WP_008705701.1' }, { 'peptide' => 'ISVAQGASK', 'refseq_protein_ids' => 'NP_003881.2 XP_011547112.1 XP_011547113.1' }, { 'peptide' => 'ISVAQGASK', 'refseq_protein_ids' => '' }]
output = "MDGTEYIIVK\tref|WP_008705701.1|\t100\t10\t0\t0\t0\t10\t0\t10\t1e-100\t100\nISVAQGASK\tref|NP_003881.2 XP_011547112.1 XP_011547113.1|\t100\t10\t0\t0\t0\t10\t0\t10\t1e-100\t100\n"
assert_equal(output, formatter.convert(object, true))
assert_equal(output, formatter.convert(object, false))
end
end

class CSVFormatterTestCase < Unipept::TestCase
def formatter
Formatter.new_for_format('csv')
Expand Down

0 comments on commit 129881f

Please sign in to comment.