unipept 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +8 -10
  5. data/Gemfile.lock +35 -21
  6. data/README.md +6 -4
  7. data/Rakefile +11 -10
  8. data/VERSION +1 -1
  9. data/bin/peptfilter +2 -44
  10. data/bin/prot2pept +4 -49
  11. data/bin/unipept +2 -197
  12. data/bin/uniprot +4 -53
  13. data/lib/batch_iterator.rb +73 -0
  14. data/lib/batch_order.rb +20 -0
  15. data/lib/commands/peptfilter.rb +118 -0
  16. data/lib/commands/prot2pept.rb +61 -0
  17. data/lib/commands/unipept/api_runner.rb +199 -0
  18. data/lib/commands/unipept/config.rb +29 -0
  19. data/lib/commands/unipept/pept2lca.rb +12 -0
  20. data/lib/commands/unipept/pept2prot.rb +13 -0
  21. data/lib/{unipept/commands → commands/unipept}/pept2taxa.rb +7 -0
  22. data/lib/commands/unipept/taxa2lca.rb +18 -0
  23. data/lib/{unipept/commands → commands/unipept}/taxonomy.rb +3 -0
  24. data/lib/commands/unipept.rb +226 -0
  25. data/lib/commands/uniprot.rb +69 -0
  26. data/lib/commands.rb +10 -0
  27. data/lib/configuration.rb +45 -0
  28. data/lib/formatters.rb +252 -0
  29. data/lib/version.rb +3 -0
  30. data/test/commands/test_peptfilter.rb +170 -0
  31. data/test/commands/test_prot2pept.rb +82 -0
  32. data/test/commands/test_unipept.rb +37 -0
  33. data/test/commands/test_uniprot.rb +136 -0
  34. data/test/commands/unipept/test_api_runner.rb +486 -0
  35. data/test/commands/unipept/test_config.rb +64 -0
  36. data/test/commands/unipept/test_pept2lca.rb +40 -0
  37. data/test/commands/unipept/test_pept2prot.rb +39 -0
  38. data/test/commands/unipept/test_pept2taxa.rb +39 -0
  39. data/test/commands/unipept/test_taxa2lca.rb +39 -0
  40. data/test/commands/unipept/test_taxonomy.rb +37 -0
  41. data/test/helper.rb +69 -23
  42. data/test/test_bach_order.rb +57 -0
  43. data/test/test_base.rb +6 -0
  44. data/test/test_batch_iterator.rb +87 -0
  45. data/test/test_configuration.rb +43 -0
  46. data/test/test_formatters.rb +140 -0
  47. data/unipept.gemspec +55 -33
  48. metadata +62 -40
  49. data/lib/unipept/batch_order.rb +0 -28
  50. data/lib/unipept/commands/api_runner.rb +0 -239
  51. data/lib/unipept/commands/pept2lca.rb +0 -6
  52. data/lib/unipept/commands/pept2prot.rb +0 -20
  53. data/lib/unipept/commands/taxa2lca.rb +0 -12
  54. data/lib/unipept/commands.rb +0 -7
  55. data/lib/unipept/configuration.rb +0 -29
  56. data/lib/unipept/formatters.rb +0 -135
  57. data/lib/unipept/version.rb +0 -3
  58. data/lib/unipept.rb +0 -8
  59. data/test/test_unipept.rb +0 -7
@@ -0,0 +1,486 @@
1
+ require_relative '../../../lib/commands/unipept/api_runner'
2
+
3
+ module Unipept
4
+ # make methods public to test them
5
+ class Commands::ApiRunner
6
+ public :glob_to_regex, :handle_response, :error_file_path, :filter_result
7
+ end
8
+
9
+ class UnipeptAPIRunnerTestCase < Unipept::TestCase
10
+ def test_init
11
+ runner = new_runner('test', { host: 'test_host' }, %w(a b c))
12
+ assert_equal('test', runner.command.name)
13
+ assert_equal('test_host', runner.options[:host])
14
+ assert_equal(%w(a b c), runner.arguments)
15
+ assert(!runner.configuration.nil?)
16
+ assert_equal('http://test_host/api/v1/test.json', runner.url)
17
+ assert_equal('http://test_host/api/v1/messages.json', runner.message_url)
18
+ assert(/Unipept CLI - unipept [0-9]\.[0-9]\.[0-9]/.match runner.user_agent)
19
+ end
20
+
21
+ def test_config_host
22
+ runner = new_runner('test', { host: 'http://param_host' }, %w(a b c))
23
+ runner.options.delete(:host)
24
+ runner.configuration['host'] = 'http://config_host'
25
+ host = runner.host
26
+ assert_equal('http://config_host', host)
27
+ end
28
+
29
+ def test_param_host
30
+ runner = new_runner('test', { host: 'http://param_host' }, %w(a b c))
31
+ runner.configuration.delete('host')
32
+ host = runner.host
33
+ assert_equal('http://param_host', host)
34
+ end
35
+
36
+ def test_no_host
37
+ runner = new_runner('test', { host: 'param_host' }, %w(a b c))
38
+ runner.configuration.delete('host')
39
+ runner.options.delete(:host)
40
+ _out, err = capture_io_while do
41
+ assert_raises SystemExit do
42
+ runner.host
43
+ end
44
+ end
45
+ assert(err.start_with? 'WARNING: no host has been set')
46
+ end
47
+
48
+ def test_host_priority
49
+ runner = new_runner('test', { host: 'http://param_host' }, %w(a b c))
50
+ runner.configuration['host'] = 'http://config_host'
51
+ host = runner.host
52
+ assert_equal('http://param_host', host)
53
+ end
54
+
55
+ def test_http_host
56
+ runner = new_runner('test', { host: 'param_host' }, %w(a b c))
57
+ host = runner.host
58
+ assert_equal('http://param_host', host)
59
+ end
60
+
61
+ def test_https_host
62
+ runner = new_runner('test', { host: 'https://param_host' }, %w(a b c))
63
+ host = runner.host
64
+ assert_equal('https://param_host', host)
65
+ end
66
+
67
+ def test_input_iterator_args
68
+ runner = new_runner('test', { host: 'https://param_host' }, %w(a b c))
69
+ output = []
70
+ runner.input_iterator.each { |el| output << el.chomp }
71
+ assert_equal(%w(a b c), output)
72
+ end
73
+
74
+ def test_input_iterator_file
75
+ File.open('input_file', 'w') { |file| file.write(%w(a b c).join("\n")) }
76
+ runner = new_runner('test', host: 'https://param_host', input: 'input_file')
77
+ output = []
78
+ runner.input_iterator.each { |el| output << el.chomp }
79
+ assert_equal(%w(a b c), output)
80
+ end
81
+
82
+ def test_input_iterator_stdin
83
+ runner = new_runner('test', host: 'https://param_host')
84
+ output = []
85
+ _out, _err = capture_io_with_input(%w(a b c)) do
86
+ runner.input_iterator.each { |el| output << el.chomp }
87
+ end
88
+ assert_equal(%w(a b c), output)
89
+ end
90
+
91
+ def test_input_iterator_arguments_priority
92
+ File.open('input_file', 'w') { |file| file.write(%w(1 2 3).join("\n")) }
93
+ runner = new_runner('test', { host: 'https://param_host', input: 'input_file' }, %w(a b c))
94
+ output = []
95
+ _out, _err = capture_io_with_input(%w(1 2 3)) do
96
+ runner.input_iterator.each { |el| output << el.chomp }
97
+ end
98
+ assert_equal(%w(a b c), output)
99
+ end
100
+
101
+ def test_input_iterator_file_priority
102
+ File.open('input_file', 'w') { |file| file.write(%w(a b c).join("\n")) }
103
+ runner = new_runner('test', host: 'https://param_host', input: 'input_file')
104
+ output = []
105
+ _out, _err = capture_io_with_input(%w(1 2 3)) do
106
+ runner.input_iterator.each { |el| output << el.chomp }
107
+ end
108
+ assert_equal(%w(a b c), output)
109
+ end
110
+
111
+ def test_batch_size
112
+ assert_equal(100, new_runner.batch_size)
113
+ end
114
+
115
+ def test_default_formatter
116
+ runner = new_runner
117
+ assert_equal('csv', runner.formatter.type)
118
+ end
119
+
120
+ def test_param_formatter
121
+ runner = new_runner('test', host: 'http://param_host', format: 'json')
122
+ assert_equal('json', runner.formatter.type)
123
+ end
124
+
125
+ def test_no_selected_fields
126
+ runner = new_runner
127
+ assert_equal([], runner.selected_fields)
128
+ end
129
+
130
+ def test_single_selected_fields
131
+ runner = new_runner('test', host: 'http://param_host', select: 'field')
132
+ assert_equal([/^field$/], runner.selected_fields)
133
+ end
134
+
135
+ def test_comma_selected_fields
136
+ runner = new_runner('test', host: 'http://param_host', select: 'field1,field2')
137
+ assert_equal([/^field1$/, /^field2$/], runner.selected_fields)
138
+ end
139
+
140
+ def test_multiple_selected_fields
141
+ runner = new_runner('test', host: 'http://param_host', select: %w(field1 field2))
142
+ assert_equal([/^field1$/, /^field2$/], runner.selected_fields)
143
+ end
144
+
145
+ def test_combined_selected_fields
146
+ runner = new_runner('test', host: 'http://param_host', select: ['field1', 'field2,field3'])
147
+ assert_equal([/^field1$/, /^field2$/, /^field3$/], runner.selected_fields)
148
+ end
149
+
150
+ def test_wildcard_selected_fields
151
+ runner = new_runner('test', host: 'http://param_host', select: 'field*')
152
+ assert_equal([/^field.*$/], runner.selected_fields)
153
+ end
154
+
155
+ def test_never_recently_fetched
156
+ runner = new_runner
157
+ runner.configuration.delete('last_fetch_date')
158
+ assert(!runner.recently_fetched?)
159
+ end
160
+
161
+ def test_old_recently_fetched
162
+ runner = new_runner
163
+ runner.configuration['last_fetch_date'] = Time.now - 60 * 60 * 25
164
+ assert(!runner.recently_fetched?)
165
+ end
166
+
167
+ def test_recently_recently_fetched
168
+ runner = new_runner
169
+ runner.configuration['last_fetch_date'] = Time.now - 60 * 60 * 1
170
+ assert(runner.recently_fetched?)
171
+ end
172
+
173
+ def test_basic_construct_request_body
174
+ runner = new_runner('test', host: 'http://param_host')
175
+ body = runner.construct_request_body('test')
176
+ assert_equal('test', body[:input])
177
+ assert_equal(false, body[:equate_il])
178
+ assert_equal(false, body[:extra])
179
+ assert_equal(false, body[:names])
180
+ end
181
+
182
+ def test_equate_construct_request_body
183
+ runner = new_runner('test', host: 'http://param_host', equate: true)
184
+ body = runner.construct_request_body('test')
185
+ assert_equal('test', body[:input])
186
+ assert_equal(true, body[:equate_il])
187
+ assert_equal(false, body[:extra])
188
+ assert_equal(false, body[:names])
189
+ end
190
+
191
+ def test_all_no_select_construct_request_body
192
+ runner = new_runner('test', host: 'http://param_host', all: true)
193
+ body = runner.construct_request_body('test')
194
+ assert_equal('test', body[:input])
195
+ assert_equal(false, body[:equate_il])
196
+ assert_equal(true, body[:extra])
197
+ assert_equal(true, body[:names])
198
+ end
199
+
200
+ def test_all_names_select_construct_request_body
201
+ runner = new_runner('test', host: 'http://param_host', all: true, select: 'test,names')
202
+ body = runner.construct_request_body('test')
203
+ assert_equal('test', body[:input])
204
+ assert_equal(false, body[:equate_il])
205
+ assert_equal(true, body[:extra])
206
+ assert_equal(true, body[:names])
207
+ end
208
+
209
+ def test_all_no_names_select_construct_request_body
210
+ runner = new_runner('test', host: 'http://param_host', all: true, select: 'test')
211
+ body = runner.construct_request_body('test')
212
+ assert_equal('test', body[:input])
213
+ assert_equal(false, body[:equate_il])
214
+ assert_equal(true, body[:extra])
215
+ assert_equal(false, body[:names])
216
+ end
217
+
218
+ def test_print_server_message
219
+ runner = new_runner
220
+ runner.stub(:recently_fetched?, false) do
221
+ runner.stub(:fetch_server_message, 'message') do
222
+ out, _err = capture_io_while do
223
+ def $stdout.tty?
224
+ true
225
+ end
226
+ runner.print_server_message
227
+ end
228
+ assert_equal('message', out.chomp)
229
+ end
230
+ end
231
+ end
232
+
233
+ def test_quiet_print_server_message
234
+ runner = new_runner('test', host: 'bla', quiet: true)
235
+ runner.stub(:recently_fetched?, false) do
236
+ runner.stub(:fetch_server_message, 'message') do
237
+ out, _err = capture_io_while do
238
+ def $stdout.tty?
239
+ true
240
+ end
241
+ $stdout.tty?
242
+ runner.print_server_message
243
+ end
244
+ assert_equal('', out)
245
+ end
246
+ end
247
+ end
248
+
249
+ def test_no_tty_print_server_message
250
+ runner = new_runner
251
+ runner.stub(:recently_fetched?, false) do
252
+ runner.stub(:fetch_server_message, 'message') do
253
+ out, _err = capture_io_while do
254
+ def $stdout.tty?
255
+ false
256
+ end
257
+ runner.print_server_message
258
+ end
259
+ assert_equal('', out)
260
+ end
261
+ end
262
+ end
263
+
264
+ def test_recent_print_server_message
265
+ runner = new_runner
266
+ runner.stub(:recently_fetched?, true) do
267
+ runner.stub(:fetch_server_message, 'message') do
268
+ out, _err = capture_io_while do
269
+ def $stdout.tty?
270
+ true
271
+ end
272
+ runner.print_server_message
273
+ end
274
+ assert_equal('', out)
275
+ end
276
+ end
277
+ end
278
+
279
+ def test_empty_print_server_message
280
+ runner = new_runner
281
+ runner.stub(:recently_fetched?, false) do
282
+ runner.stub(:fetch_server_message, '') do
283
+ out, _err = capture_io_while do
284
+ def $stdout.tty?
285
+ true
286
+ end
287
+ runner.print_server_message
288
+ end
289
+ assert_equal('', out)
290
+ end
291
+ end
292
+ end
293
+
294
+ def test_fetch_server_message
295
+ runner = new_runner('test', host: 'http://api.unipept.ugent.be')
296
+ assert(!runner.fetch_server_message.nil?)
297
+ end
298
+
299
+ def test_stdout_write_to_output
300
+ runner = new_runner
301
+ out, _err = capture_io_while do
302
+ runner.write_to_output('hello world')
303
+ end
304
+ assert_equal('hello world', out.chomp)
305
+ end
306
+
307
+ def test_file_write_to_output
308
+ runner = new_runner('test', host: 'test', output: 'output_file')
309
+ out, _err = capture_io_while do
310
+ runner.write_to_output('hello world')
311
+ end
312
+ assert_equal('', out)
313
+ assert_equal('hello world', IO.foreach('output_file').next.chomp)
314
+ end
315
+
316
+ def test_glob_to_regex
317
+ runner = new_runner
318
+ assert(/^simple$/, runner.glob_to_regex('simple'))
319
+ assert(/^.*simple.*$/, runner.glob_to_regex('*simple*'))
320
+ end
321
+
322
+ def test_save_error
323
+ runner = new_runner
324
+ runner.stub(:error_file_path, 'errordir/error.log') do
325
+ _out, err = capture_io_while do
326
+ runner.save_error('error message')
327
+ end
328
+ assert(err.start_with? 'API request failed! log can be found in')
329
+ assert_equal('error message', IO.foreach('errordir/error.log').next.chomp)
330
+ end
331
+ end
332
+
333
+ def test_error_file_path
334
+ runner = new_runner
335
+ assert(runner.error_file_path.include? '/.unipept/')
336
+ end
337
+
338
+ def test_invalid_filter_result
339
+ runner = new_runner
340
+ assert_equal([], runner.filter_result('{"key":"value'))
341
+ end
342
+
343
+ def test_array_wrap_filter_result
344
+ runner = new_runner
345
+ assert_equal([{ 'key' => 'value' }], runner.filter_result('{"key":"value"}'))
346
+ end
347
+
348
+ def test_filter_filter_result
349
+ runner = new_runner('test', host: 'test', select: 'key1')
350
+ result = runner.filter_result('[{"key1":"value1","key2":"value1"},{"key1":"value2","key2":"value2"}]')
351
+ assert_equal([{ 'key1' => 'value1' }, { 'key1' => 'value2' }], result)
352
+ end
353
+
354
+ def test_success_header_handle_response
355
+ runner = new_runner
356
+ response = new_response(success: true, response_body: '[{"key1":"value1","key2":"value1"},{"key1":"value2","key2":"value2"}]')
357
+ lambda = runner.handle_response(response, 0, nil)
358
+ assert(lambda.lambda?)
359
+ out, err = capture_io_while(&lambda)
360
+ lines = out.each_line
361
+ assert_equal('', err)
362
+ assert_equal('key1,key2', lines.next.chomp)
363
+ assert_equal('value1,value1', lines.next.chomp)
364
+ assert_equal('value2,value2', lines.next.chomp)
365
+ end
366
+
367
+ def test_success_no_header_handle_response
368
+ runner = new_runner
369
+ response = new_response(success: true, response_body: '[{"key1":"value1","key2":"value1"},{"key1":"value2","key2":"value2"}]')
370
+ lambda = runner.handle_response(response, 1, nil)
371
+ assert(lambda.lambda?)
372
+ out, err = capture_io_while(&lambda)
373
+ lines = out.each_line
374
+ assert_equal('', err)
375
+ assert_equal('value1,value1', lines.next.chomp)
376
+ assert_equal('value2,value2', lines.next.chomp)
377
+ end
378
+
379
+ def test_time_out_handle_response
380
+ runner = new_runner
381
+ response = new_response(success: false, timed_out: true)
382
+ lambda = runner.handle_response(response, 0, nil)
383
+ assert(lambda.lambda?)
384
+ def runner.save_error(input)
385
+ $stderr.puts(input)
386
+ end
387
+ out, err = capture_io_while(&lambda)
388
+ assert_equal('', out)
389
+ assert(err.chomp.start_with? 'request timed out')
390
+ end
391
+
392
+ def test_code_0_handle_response
393
+ runner = new_runner
394
+ response = new_response(success: false, timed_out: false, code: 0)
395
+ lambda = runner.handle_response(response, 0, nil)
396
+ assert(lambda.lambda?)
397
+ def runner.save_error(input)
398
+ $stderr.puts(input)
399
+ end
400
+ out, err = capture_io_while(&lambda)
401
+ assert_equal('', out)
402
+ assert(err.chomp.start_with? 'could not get an http')
403
+ end
404
+
405
+ def test_failed_handle_response
406
+ runner = new_runner
407
+ response = new_response(success: false, timed_out: false, code: 10)
408
+ lambda = runner.handle_response(response, 0, nil)
409
+ assert(lambda.lambda?)
410
+ def runner.save_error(input)
411
+ $stderr.puts(input)
412
+ end
413
+ out, err = capture_io_while(&lambda)
414
+ assert_equal('', out)
415
+ assert(err.chomp.start_with? 'Got 10')
416
+ end
417
+
418
+ def test_run
419
+ runner = new_runner('taxonomy', host: 'http://api.unipept.ugent.be')
420
+ out, err = capture_io_while do
421
+ def runner.print_server_message
422
+ puts 'server message'
423
+ end
424
+ def runner.input_iterator
425
+ %w(0 1 2).each
426
+ end
427
+ def runner.batch_size
428
+ 2
429
+ end
430
+ runner.run
431
+ end
432
+ lines = out.each_line
433
+ assert_equal('', err)
434
+ assert_equal('server message', lines.next.chomp)
435
+ assert(lines.next.start_with? 'taxon_id')
436
+ assert(lines.next.start_with? '1,root')
437
+ assert(lines.next.start_with? '2,Bacteria')
438
+ assert_raises(StopIteration) { lines.next }
439
+ end
440
+
441
+ def new_runner(command_name = 'test', options = { host: 'http://param_host' }, arguments = [])
442
+ command = Cri::Command.define { name command_name }
443
+ Commands::ApiRunner.new(options, arguments, command)
444
+ end
445
+
446
+ def new_response(values)
447
+ response = Class.new do
448
+ def initialize(values)
449
+ @values = values
450
+ end
451
+
452
+ def success?
453
+ @values[:success]
454
+ end
455
+
456
+ def timed_out?
457
+ @values[:timed_out]
458
+ end
459
+
460
+ def code
461
+ @values[:code]
462
+ end
463
+
464
+ def response_body
465
+ @values[:response_body]
466
+ end
467
+
468
+ def return_message
469
+ ''
470
+ end
471
+
472
+ def request
473
+ o = Object.new
474
+ def o.options
475
+ ''
476
+ end
477
+ def o.encoded_body
478
+ ''
479
+ end
480
+ o
481
+ end
482
+ end
483
+ response.new(values)
484
+ end
485
+ end
486
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../../../lib/commands'
2
+
3
+ module Unipept
4
+ class UnipeptConfigTestCase < Unipept::TestCase
5
+ def test_help
6
+ out, _err = capture_io_while do
7
+ assert_raises SystemExit do
8
+ Commands::Unipept.run(%w(config -h))
9
+ end
10
+ end
11
+ assert(out.include? 'show help for this command')
12
+
13
+ out, _err = capture_io_while do
14
+ assert_raises SystemExit do
15
+ Commands::Unipept.run(%w(config --help))
16
+ end
17
+ end
18
+ assert(out.include? 'show help for this command')
19
+ end
20
+
21
+ def test_no_args
22
+ _out, err = capture_io_while do
23
+ assert_raises SystemExit do
24
+ Commands::Unipept.run(%w(config))
25
+ end
26
+ end
27
+ assert(err.include? 'show help for this command')
28
+ end
29
+
30
+ def test_too_many_args
31
+ _out, err = capture_io_while do
32
+ assert_raises SystemExit do
33
+ Commands::Unipept.run(%w(config a b c))
34
+ end
35
+ end
36
+ assert(err.include? 'show help for this command')
37
+ end
38
+
39
+ def test_setting_config
40
+ value = Random.rand.to_s
41
+ config = Unipept::Configuration.new
42
+ config.delete('test')
43
+ config.save
44
+ out, _err = capture_io_while do
45
+ Commands::Unipept.run(['config', 'test', value])
46
+ end
47
+ assert_equal('test was set to ' + value, out.chomp)
48
+ assert_equal(value, Unipept::Configuration.new['test'])
49
+ end
50
+
51
+ def test_getting_config
52
+ value = Random.rand.to_s
53
+ config = Unipept::Configuration.new
54
+ config['test'] = value
55
+ config.save
56
+ out, _err = capture_io_while do
57
+ Commands::Unipept.run(%w(config test))
58
+ end
59
+ config.delete('test')
60
+ config.save
61
+ assert_equal(value, out.chomp)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../../../lib/commands'
2
+
3
+ module Unipept
4
+ class UnipeptPept2lcaTestCase < Unipept::TestCase
5
+ def test_batch_size
6
+ command = Cri::Command.define { name 'pept2lca' }
7
+ pept2lca = Commands::Pept2lca.new({ host: 'http://api.unipept.ugent.be' }, [], command)
8
+ assert_equal(1000, pept2lca.batch_size)
9
+ pept2lca.options[:all] = true
10
+ assert_equal(100, pept2lca.batch_size)
11
+ end
12
+
13
+ def test_help
14
+ out, _err = capture_io_while do
15
+ assert_raises SystemExit do
16
+ Commands::Unipept.run(%w(pept2lca -h))
17
+ end
18
+ end
19
+ assert(out.include? 'show help for this command')
20
+
21
+ out, _err = capture_io_while do
22
+ assert_raises SystemExit do
23
+ Commands::Unipept.run(%w(pept2lca --help))
24
+ end
25
+ end
26
+ assert(out.include? 'show help for this command')
27
+ end
28
+
29
+ def test_run
30
+ out, err = capture_io_while do
31
+ Commands::Unipept.run(%w(pept2lca --host http://api.unipept.ugent.be AALTER))
32
+ end
33
+ lines = out.each_line
34
+ assert_equal('', err)
35
+ assert(lines.next.start_with? 'peptide,taxon_id')
36
+ assert(lines.next.start_with? 'AALTER,1,root,no rank')
37
+ assert_raises(StopIteration) { lines.next }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../../../lib/commands'
2
+
3
+ module Unipept
4
+ class UnipeptPept2protTestCase < Unipept::TestCase
5
+ def test_batch_size
6
+ command = Cri::Command.define { name 'pept2prot' }
7
+ pept2prot = Commands::Pept2prot.new({ host: 'http://api.unipept.ugent.be' }, [], command)
8
+ assert_equal(10, pept2prot.batch_size)
9
+ pept2prot.options[:all] = true
10
+ assert_equal(5, pept2prot.batch_size)
11
+ end
12
+
13
+ def test_help
14
+ out, _err = capture_io_while do
15
+ assert_raises SystemExit do
16
+ Commands::Unipept.run(%w(pept2prot -h))
17
+ end
18
+ end
19
+ assert(out.include? 'show help for this command')
20
+
21
+ out, _err = capture_io_while do
22
+ assert_raises SystemExit do
23
+ Commands::Unipept.run(%w(pept2prot --help))
24
+ end
25
+ end
26
+ assert(out.include? 'show help for this command')
27
+ end
28
+
29
+ def test_run
30
+ out, err = capture_io_while do
31
+ Commands::Unipept.run(%w(pept2prot --host http://api.unipept.ugent.be ENFVYIAK))
32
+ end
33
+ lines = out.each_line
34
+ assert_equal('', err)
35
+ assert(lines.next.start_with? 'peptide,uniprot_id,taxon_id')
36
+ assert(lines.next.start_with? 'ENFVYIAK,')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../../../lib/commands'
2
+
3
+ module Unipept
4
+ class UnipeptPept2taxaTestCase < Unipept::TestCase
5
+ def test_batch_size
6
+ command = Cri::Command.define { name 'pept2taxa' }
7
+ pept2taxa = Commands::Pept2taxa.new({ host: 'http://api.unipept.ugent.be' }, [], command)
8
+ assert_equal(10, pept2taxa.batch_size)
9
+ pept2taxa.options[:all] = true
10
+ assert_equal(5, pept2taxa.batch_size)
11
+ end
12
+
13
+ def test_help
14
+ out, _err = capture_io_while do
15
+ assert_raises SystemExit do
16
+ Commands::Unipept.run(%w(pept2taxa -h))
17
+ end
18
+ end
19
+ assert(out.include? 'show help for this command')
20
+
21
+ out, _err = capture_io_while do
22
+ assert_raises SystemExit do
23
+ Commands::Unipept.run(%w(pept2taxa --help))
24
+ end
25
+ end
26
+ assert(out.include? 'show help for this command')
27
+ end
28
+
29
+ def test_run
30
+ out, err = capture_io_while do
31
+ Commands::Unipept.run(%w(pept2taxa --host http://api.unipept.ugent.be ENFVYIAK))
32
+ end
33
+ lines = out.each_line
34
+ assert_equal('', err)
35
+ assert(lines.next.start_with? 'peptide,taxon_id,taxon_name,taxon_rank')
36
+ assert(lines.next.start_with? 'ENFVYIAK,')
37
+ end
38
+ end
39
+ end