Skip to content

Commit

Permalink
add more info and warnings checks in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Sep 17, 2024
1 parent 0cbe155 commit 52e280d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/GenomeFileUtil/core/GenomeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _save_genome_mass(self, params, validate_genome=True):

# retrive required params
name = input_params['name']
data = input_params['data']
data = dict(input_params['data'])

# XXX there is no `workspace_datatype` param in the spec
# NOTE: This allows a user to specify any arbitrary workspace type which could cause,
Expand Down
40 changes: 33 additions & 7 deletions test/problematic_tests/save_genome_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import urllib.request
from configparser import ConfigParser
from os import environ
from datetime import datetime

import requests # noqa: F401

Expand All @@ -24,8 +25,17 @@
from GenomeFileUtil.core.GenomeInterface import GenomeInterface
from installed_clients.WorkspaceClient import Workspace as workspaceService

KBASE_GENOME = "KBaseGenomes.Genome"
KBASE_METAGENOME = "KBaseMetagenomes.AnnotatedMetagenomeAssembly"
_KBASE_GENOME = "KBaseGenomes.Genome"
_KBASE_METAGENOME = "KBaseMetagenomes.AnnotatedMetagenomeAssembly"

_GENOME_FILE_WARNINGS = [
'For prokaryotes, CDS array should generally be the same length as the Features array.',
'Genome molecule_type Unknown is not expected for domain Bacteria.',
'Unable to determine organism taxonomy'
]
_METAGENOME_FILE_WARNINGS = [
'SUSPECT: This genome has 20 genes that needed to be spoofed for existing parentless CDS.'
]


class SaveGenomeTest(unittest.TestCase):
Expand Down Expand Up @@ -212,13 +222,27 @@ def fail_save_genome(self, params, error, exception=ValueError, contains=False,
else:
self.assertEqual(error, str(context.exception))

def check_save_one_genome_output(self, ret, genome_name, data_type=KBASE_GENOME):
def check_save_one_genome_output(
self,
ret,
genome_name,
data_type=_KBASE_GENOME,
warnings=_GENOME_FILE_WARNINGS
):
self.assertTrue('info' in ret)
self.assertTrue('warnings' in ret)

# Check info
genome_info = ret['info']
self.assertEqual(genome_info[1], genome_name)
self.assertEqual(genome_info[2].split('-')[0], data_type)
self.assertTrue(datetime.strptime(genome_info[3], '%Y-%m-%dT%H:%M:%S+%f'))
self.assertEqual(genome_info[5], self.user_id)
self.assertEqual(genome_info[6], self.wsID)
self.assertEqual(genome_info[7], self.wsName)

# Check warnings
self.assertEqual(ret['warnings'], warnings)

def test_bad_one_genome_params(self):
self.start_test()
Expand Down Expand Up @@ -274,13 +298,15 @@ def test_genomes_with_upgrade(self):
{
'name': genome_name,
'data': self.test_metagenome_data,
'workspace_datatype': KBASE_METAGENOME,
'workspace_datatype': _KBASE_METAGENOME,
'upgrade': True,
}
]
params = {'workspace_id': self.wsID, 'inputs': inputs}
ret = self.genome_interface.save_genome_mass(params)[0]
self.check_save_one_genome_output(ret, genome_name, data_type=KBASE_METAGENOME)
self.check_save_one_genome_output(
ret, genome_name, data_type=_KBASE_METAGENOME, warnings=_METAGENOME_FILE_WARNINGS
)

def test_genomes_with_hidden(self):
self.start_test()
Expand All @@ -294,7 +320,7 @@ def test_genomes_with_hidden(self):
]
params = {'workspace_id': self.wsID, 'inputs': inputs}
ret = self.genome_interface.save_genome_mass(params)[0]
self.check_save_one_genome_output(ret, genome_name)
self.check_save_one_genome_output(ret, genome_name, warnings=[])

inputs = [
{
Expand All @@ -305,7 +331,7 @@ def test_genomes_with_hidden(self):
]
params = {'workspace_id': self.wsID, 'inputs': inputs}
ret = self.genome_interface.save_genome_mass(params)[0]
self.check_save_one_genome_output(ret, genome_name)
self.check_save_one_genome_output(ret, genome_name, warnings=[])

def test_bad_genomes_params_missing_parameter(self):
self.start_test()
Expand Down

0 comments on commit 52e280d

Please sign in to comment.