Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerun 551481e #206

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5810798
Run save_genome_test only
Xiangs18 Nov 21, 2023
3e517db
fix test_token2 missing prob
Xiangs18 Nov 21, 2023
af8ba9a
temp remove user_token2
Xiangs18 Nov 21, 2023
fdec6c8
skip problem test
Xiangs18 Dec 7, 2023
0732ea7
add catalog params check helper functionin GenomeFileUtilImp.py
Xiangs18 Dec 7, 2023
9361255
revert back
Xiangs18 Dec 7, 2023
4a862b3
remove skip
Xiangs18 Dec 7, 2023
0a7b4d3
import MAX_THREADS and THREADS_PER_CPU
Xiangs18 Dec 7, 2023
4026e71
update catalog params default name and type check func
Xiangs18 Dec 14, 2023
c98e356
change var name
Xiangs18 Dec 14, 2023
2d0f54b
simplify value error message
Xiangs18 Dec 14, 2023
e76b00d
add test for catalog param type check
Xiangs18 Dec 20, 2023
5d4c485
add pytest lib in dockerfile
Xiangs18 Dec 20, 2023
55d993b
fix import
Xiangs18 Dec 21, 2023
25a066f
relocate assert_exception_correct func
Xiangs18 Dec 21, 2023
5621141
run pass test_invalid_catalog_param_type test
Xiangs18 Dec 21, 2023
2cd3385
run pass new test
Xiangs18 Jan 4, 2024
0ef839c
Merge branch 'master' into dev-parallel
Xiangs18 Jan 4, 2024
bc3b1f8
run all tests
Xiangs18 Jan 4, 2024
d01329c
run on new tests
Xiangs18 Jan 5, 2024
f74f65f
fix name
Xiangs18 Jan 5, 2024
5c5c1e6
run all tests
Xiangs18 Jan 5, 2024
ed0defa
rerun new test
Xiangs18 Jan 5, 2024
58b1644
fix error
Xiangs18 Jan 5, 2024
1f35e4f
rerun all tests
Xiangs18 Jan 5, 2024
d03a9f2
add new test logic
Xiangs18 Jan 8, 2024
13d5af9
rm path var
Xiangs18 Jan 8, 2024
6868780
clean up && rerun all tests
Xiangs18 Jan 8, 2024
551481e
relocate impl_test.py
Xiangs18 Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ MAINTAINER KBase Developer
RUN pip install --upgrade --extra-index-url=https://pypi.anaconda.org/kbase/simple \
pip \
biopython==1.70 \
releng-client==0.0.1
releng-client==0.0.1 \
pytest==7.0.1

COPY ./ /kb/module
RUN mkdir -p /kb/module/work
Expand Down
27 changes: 26 additions & 1 deletion lib/GenomeFileUtil/GenomeFileUtilImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from GenomeFileUtil.core.FastaGFFToGenome import FastaGFFToGenome
from GenomeFileUtil.core.GenbankToGenome import GenbankToGenome
from GenomeFileUtil.core.GenomeFeaturesToFasta import GenomeFeaturesToFasta
from GenomeFileUtil.core.GenomeInterface import GenomeInterface
from GenomeFileUtil.core.GenomeInterface import (
GenomeInterface,
MAX_THREADS_DEFAULT,
THREADS_PER_CPU_DEFAULT,
)
from GenomeFileUtil.core.GenomeToGFF import GenomeToGFF
from GenomeFileUtil.core.GenomeToGenbank import GenomeToGenbank
from installed_clients.AssemblyUtilClient import AssemblyUtil
Expand All @@ -32,6 +36,18 @@ def __init__(self, config):
self.re_api_url = config['re-api-url']
self.raw = config


def _validate_catalog_param_type(threads_count, var_name, default_val, expected_type):
"""Helper function to validate catalog params type"""
if threads_count is None:
print(f"Cannot retrieve {var_name} from the catalog, set {var_name}={default_val}")
return default_val
print(f"Successfully retrieved {var_name} from the catalog!")
try:
threads_count = expected_type(threads_count)
except ValueError as e:
raise ValueError(f"{var_name} must be of type {expected_type.__name__}") from e
return threads_count
#END_HEADER


Expand Down Expand Up @@ -64,6 +80,15 @@ def __init__(self, config):
self.cfg = SDKConfig(config)
logging.basicConfig(format='%(created)s %(levelname)s: %(message)s',
level=logging.INFO)

max_threads = os.environ.get("KBASE_SECURE_CONFIG_PARAM_MAX_THREADS")
threads_per_cpu = os.environ.get("KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU")
self.max_threads = _validate_catalog_param_type(
max_threads, "MAX_THREADS", MAX_THREADS_DEFAULT, int
)
self.threads_per_cpu = _validate_catalog_param_type(
threads_per_cpu, "THREADS_PER_CPU", THREADS_PER_CPU_DEFAULT, float
)
#END_CONSTRUCTOR
pass

Expand Down
4 changes: 4 additions & 0 deletions lib/GenomeFileUtil/core/GenomeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

MAX_GENOME_SIZE = 2**30

# catalog params
MAX_THREADS_DEFAULT = 10
THREADS_PER_CPU_DEFAULT = 1


class GenomeInterface:
def __init__(self, config):
Expand Down
3 changes: 2 additions & 1 deletion scripts/run_tests_within_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
script_dir=$(dirname "$(readlink -f "$0")")
export KB_DEPLOYMENT_CONFIG=$script_dir/../deploy.cfg
export KB_AUTH_TOKEN=`cat /kb/module/work/token`
export PYTHONPATH=$script_dir/../lib:$PATH:$PYTHONPATH
export PYTHONPATH=$script_dir/../lib:$PYTHONPATH
export PYTHONPATH=$script_dir/../test:$PYTHONPATH

# Set TEST_PATH to run a specific test. Eg: TEST_PATH=test.core.update_taxon_assignments_test
export TEST_PATH=.
Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import traceback


def assert_exception_correct(got: Exception, expected: Exception):
err = "".join(traceback.TracebackException.from_exception(got).format())
assert got.args == expected.args, err
assert type(got) == type(expected)
Empty file added test/genome_tests/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions test/genome_tests/impl_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import pytest
import unittest

from GenomeFileUtil.GenomeFileUtilImpl import GenomeFileUtil
from conftest import assert_exception_correct


class ImplTest(unittest.TestCase):
def setUp(self):
self.cfg = {}
self.cfg["workspace-url"] = "https://ci.kbase.us/services/ws"
self.cfg["shock-url"] = "https://ci.kbase.us/services/shock-api"
self.cfg["handle-service-url"] = "https://ci.kbase.us/services/handle_service"
self.cfg["scratch"] = "/kb/module/work/tmp"
self.cfg["srv-wiz-url"] = "https://ci.kbase.us/services/service_wizard"
self.cfg["auth-service-url"] = "https://ci.kbase.us/services/auth/api/legacy/KBase/Sessions/Login"
self.cfg["re-api-url"] = "https://ci.kbase.us/services/relation_engine_api"

def tearDown(self):
for kbase_secure_param in (
"KBASE_SECURE_CONFIG_PARAM_MAX_THREADS",
"KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU",
):
os.environ.pop(kbase_secure_param, None)

def _run_test_fail(self, cfg, error_message):
with pytest.raises(Exception) as got:
GenomeFileUtil(cfg)
assert_exception_correct(got.value, ValueError(error_message))

def test_valid_catalog_param_type(self):
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "16"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.5"
gfu = GenomeFileUtil(self.cfg)
self.assertEqual(gfu.max_threads, 16)
self.assertEqual(gfu.threads_per_cpu, 2.5)

def test_valid_default_catalog_param_type(self):
gfu = GenomeFileUtil(self.cfg)
self.assertEqual(gfu.max_threads, 10)
self.assertEqual(gfu.threads_per_cpu, 1)

def test_invalid_max_threads(self):
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10.5"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.5"
self._run_test_fail(self.cfg, "MAX_THREADS must be of type int")

def test_invalid_threads_per_cpu(self):
os.environ["KBASE_SECURE_CONFIG_PARAM_MAX_THREADS"] = "10"
os.environ["KBASE_SECURE_CONFIG_PARAM_THREADS_PER_CPU"] = "2.8e"
self._run_test_fail(self.cfg, "THREADS_PER_CPU must be of type float")
Loading