Skip to content

Commit

Permalink
run pass new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Jan 4, 2024
1 parent 5621141 commit 2cd3385
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
2 changes: 1 addition & 1 deletion scripts/run_tests_within_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export KB_AUTH_TOKEN=`cat /kb/module/work/token`
export PYTHONPATH=$script_dir/../lib:$PATH:$PYTHONPATH

# Set TEST_PATH to run a specific test. Eg: TEST_PATH=test.core.update_taxon_assignments_test
export TEST_PATH=.
export TEST_PATH=test.problematic_tests.impl_test

cd $script_dir/../test
python -m nose --with-coverage --cover-package=GenomeFileUtil --cover-html --cover-html-dir=/kb/module/work/test_coverage --cover-xml --cover-xml-file=/kb/module/work/test_coverage/coverage.xml --nocapture --nologcapture $TEST_PATH
Expand Down
58 changes: 58 additions & 0 deletions test/problematic_tests/impl_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import pytest
import traceback
import unittest

from configparser import ConfigParser

from GenomeFileUtil.GenomeFileUtilImpl import GenomeFileUtil


def assert_exception_correct(got: Exception, expected: Exception):
"""
Compare raised exception with expected exception.
Args:
got (Exception): Exception received
expected (Exception): Exception expected
"""
err = "".join(traceback.TracebackException.from_exception(got).format())
assert got.args == expected.args, err
assert type(got) == type(expected)


class ImplTest(unittest.TestCase):
def setUp(self):
config_file = os.environ["KB_DEPLOYMENT_CONFIG"]
token = os.environ.get("KB_AUTH_TOKEN", None)

self.cfg = {}
config = ConfigParser()
config.read(config_file)
for nameval in config.items("GenomeFileUtil"):
self.cfg[nameval[0]] = nameval[1]
self.cfg["KB_AUTH_TOKEN"] = token

def test_invalid_catalog_param_type(self):
MAX_THREADS = "MAX_THREADS"
THREADS_PER_CPU = "THREADS_PER_CPU"

# max_threads type check fails
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10.5"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.5"

with pytest.raises(Exception) as got:
GenomeFileUtil(self.cfg)
assert_exception_correct(
got.value, ValueError(f"{MAX_THREADS} must be of type {int.__name__}")
)

# threads_per_cpu type check fails
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.8e"

with pytest.raises(Exception) as got:
GenomeFileUtil(self.cfg)
assert_exception_correct(
got.value, ValueError(f"{THREADS_PER_CPU} must be of type {float.__name__}")
)
46 changes: 0 additions & 46 deletions test/problematic_tests/save_genome_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os # noqa: F401
import shutil
import time
import traceback
import unittest
import urllib.error
import urllib.parse
Expand All @@ -14,7 +13,6 @@
from os import environ

import requests # noqa: F401
from pytest import raises

from installed_clients.AssemblyUtilClient import AssemblyUtil
from installed_clients.DataFileUtilClient import DataFileUtil
Expand All @@ -26,19 +24,6 @@
from installed_clients.WorkspaceClient import Workspace as workspaceService


def assert_exception_correct(got: Exception, expected: Exception):
"""
Compare raised exception with expected exception.
Args:
got (Exception): Exception received
expected (Exception): Exception expected
"""
err = "".join(traceback.TracebackException.from_exception(got).format())
assert got.args == expected.args, err
assert type(got) == type(expected)


class SaveGenomeTest(unittest.TestCase):

@classmethod
Expand Down Expand Up @@ -153,9 +138,6 @@ def getImpl(self):
def getContext(self):
return self.__class__.ctx

def getCfg(self):
return self.__class__.cfg

def start_test(self):
testname = inspect.stack()[1][3]
print(('\n*** starting test: ' + testname + ' **'))
Expand Down Expand Up @@ -210,34 +192,6 @@ def test_one_genome_with_hidden(self):
ret = self.getImpl().save_one_genome(self.ctx, params)[0]
self.check_save_one_genome_output(ret, genome_name)

def test_invalid_catalog_param_type(self):
self.start_test()

MAX_THREADS = "MAX_THREADS"
THREADS_PER_CPU = "THREADS_PER_CPU"

# max_threads type check fails
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10.5"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.5"

with raises(Exception) as got:
GenomeFileUtil(self.getCfg())
assert_exception_correct(
got.value,
ValueError(f"{MAX_THREADS} must be of type {int.__name__}")
)

# threads_per_cpu type check fails
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.8e"

with raises(Exception) as got:
GenomeFileUtil(self.getCfg())
assert_exception_correct(
got.value,
ValueError(f"{THREADS_PER_CPU} must be of type {float.__name__}")
)

def test_GenomeInterface_check_dna_sequence_in_features(self):
# no feature in genome
genome = {'missing_features': 'features'}
Expand Down

0 comments on commit 2cd3385

Please sign in to comment.