From e9f640ecb6d08ec6aefc971c28d38dba3dacd087 Mon Sep 17 00:00:00 2001 From: Youhwan Seol Date: Mon, 31 Oct 2022 18:57:49 +0900 Subject: [PATCH] repackage and tidy up codes to run test Delete shebangs, follow PEP 8 import style, and use __init__.py. Please run test script at project ROOT dir (e.g., bash ./test/unit_test.sh) Issue-id: AIMLFW-9 Signed-off-by: Youhwan Seol Change-Id: I95a32b24cab38870c1fb793b14af57c5b8658975 --- kfadapter/__init__.py | 17 +++++++++++++++++ kfadapter/kfadapter_conf.py | 6 +++--- kfadapter/kfadapter_kfconnect.py | 6 +++--- kfadapter/kfadapter_main.py | 8 ++++---- kfadapter/kfadapter_util.py | 17 +++++++++-------- kfadapter/tmgr_logger.py | 6 +++--- test/__init__.py | 17 +++++++++++++++++ test/fake_kfconnect.py | 1 - test/fake_kfp.py | 3 --- test/test_kfadapter_conf.py | 6 ++---- test/test_kfadapter_kfconnect.py | 12 +++++------- test/test_kfadapter_main.py | 14 ++++++-------- test/test_kfadapter_util.py | 7 +------ test/test_tmgr_logger.py | 6 ++---- test/unit_test.sh | 2 -- 15 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 kfadapter/__init__.py create mode 100644 test/__init__.py diff --git a/kfadapter/__init__.py b/kfadapter/__init__.py new file mode 100644 index 0000000..7954d16 --- /dev/null +++ b/kfadapter/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== diff --git a/kfadapter/kfadapter_conf.py b/kfadapter/kfadapter_conf.py index e2f27ec..f4a3a50 100644 --- a/kfadapter/kfadapter_conf.py +++ b/kfadapter/kfadapter_conf.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # ================================================================================== # # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. @@ -16,7 +15,6 @@ # limitations under the License. # # ================================================================================== - """kfadapter_conf.py This module is for retrieving configuration for KfAdapter App @@ -25,9 +23,11 @@ Application configuration - Application Port and run status interval """ + from os import getenv from threading import Lock -from tmgr_logger import TMLogger + +from .tmgr_logger import TMLogger TRAINING_DICT = {} LOCK = Lock() diff --git a/kfadapter/kfadapter_kfconnect.py b/kfadapter/kfadapter_kfconnect.py index a9b1396..32f06f7 100644 --- a/kfadapter/kfadapter_kfconnect.py +++ b/kfadapter/kfadapter_kfconnect.py @@ -15,15 +15,15 @@ # limitations under the License. # # ================================================================================== - """kfadapter_kfconnect.py. This module is for interfacing and interworking with KubeFlow SDK """ import kfp -from kfadapter_util import random_suffix -from kfadapter_conf import KfConfiguration + +from .kfadapter_util import random_suffix +from .kfadapter_conf import KfConfiguration class KfConnect: """ diff --git a/kfadapter/kfadapter_main.py b/kfadapter/kfadapter_main.py index 0340558..3fe032c 100644 --- a/kfadapter/kfadapter_main.py +++ b/kfadapter/kfadapter_main.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # ================================================================================== # # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. @@ -31,12 +30,13 @@ import os import traceback import json from threading import Thread + from flask import Flask, request, jsonify from flask_api import status import kfp_server_api -from kfadapter_kfconnect import KfConnect -import kfadapter_conf -from kfadapter_util import BadRequest, wait_status_thread, keys_match, check_map + +from .kfadapter_kfconnect import KfConnect +from .kfadapter_util import BadRequest, wait_status_thread, keys_match, check_map #Handles to Config and Kubeflow KFCONNECT_CONFIG_OBJ = None diff --git a/kfadapter/kfadapter_util.py b/kfadapter/kfadapter_util.py index cde187d..baaba3a 100644 --- a/kfadapter/kfadapter_util.py +++ b/kfadapter/kfadapter_util.py @@ -1,9 +1,3 @@ -"""kfadapter_util.py. - -This module is for all the utility functions to be used -by the main and other modules - -""" # ================================================================================== # # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. @@ -21,14 +15,21 @@ by the main and other modules # limitations under the License. # # ================================================================================== -from random import choices +"""kfadapter_util.py. + +This module is for all the utility functions to be used +by the main and other modules + +""" + import traceback import string import time import json import requests +from random import choices + from flask_api import status -import kfadapter_conf class BadRequest(Exception): """ diff --git a/kfadapter/tmgr_logger.py b/kfadapter/tmgr_logger.py index 79877da..c3cc3d1 100644 --- a/kfadapter/tmgr_logger.py +++ b/kfadapter/tmgr_logger.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # ================================================================================== # # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. @@ -17,14 +16,15 @@ # # ================================================================================== """tmgr_logger.py + This module is for Initializing Logger Framework -""" +""" +import os import logging import logging.config import yaml - class TMLogger(object):# pylint: disable=too-few-public-methods """ This is a class for initiliazing logger configuration for TMLogger diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..7954d16 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== diff --git a/test/fake_kfconnect.py b/test/fake_kfconnect.py index 50136d1..1344db6 100644 --- a/test/fake_kfconnect.py +++ b/test/fake_kfconnect.py @@ -19,7 +19,6 @@ import kfp_server_api from kfp_server_api.models.api_run import ApiRun from kfp_server_api.models.api_list_runs_response import ApiListRunsResponse - from kfp_server_api.models.api_experiment import ApiExperiment from kfp_server_api.models.api_list_pipelines_response import ApiListPipelinesResponse from kfp_server_api.models.api_pipeline import ApiPipeline diff --git a/test/fake_kfp.py b/test/fake_kfp.py index 283d8e2..c80cd1a 100644 --- a/test/fake_kfp.py +++ b/test/fake_kfp.py @@ -23,9 +23,6 @@ from kfp_server_api.models.api_pipeline_version import ApiPipelineVersion from kfp_server_api.models.api_experiment import ApiExperiment from kfp_server_api.models.api_run_detail import ApiRunDetail from kfp_server_api.models.api_run import ApiRun - - - import kfp_server_api class FakeKfp: diff --git a/test/test_kfadapter_conf.py b/test/test_kfadapter_conf.py index 4727590..524244b 100644 --- a/test/test_kfadapter_conf.py +++ b/test/test_kfadapter_conf.py @@ -16,11 +16,9 @@ # # ================================================================================== -import sys import os -sys.path.append("../kfadapter") -import kfadapter_conf -import pytest + +from kfadapter import kfadapter_conf class Test_kfadapter_conf: KUBEFLOW_HOST_NAME = '127.0.0.1' diff --git a/test/test_kfadapter_kfconnect.py b/test/test_kfadapter_kfconnect.py index 2775685..d15b8d1 100644 --- a/test/test_kfadapter_kfconnect.py +++ b/test/test_kfadapter_kfconnect.py @@ -16,15 +16,13 @@ # # ================================================================================== -import sys -sys.path.append("kfadapter") -# import kfadapter_conf -from kfadapter_kfconnect import KfConnect -from fake_kfconnect import FakeKfConnect -from fake_kfp import FakeKfp -from fake_kfp import FakeNegativeKfp import kfp_server_api +from kfadapter.kfadapter_kfconnect import KfConnect + +from .fake_kfp import FakeKfp +from .fake_kfp import FakeNegativeKfp + class Test_KfConnect: def setup_method(self): self.__KFCONNECT = KfConnect() diff --git a/test/test_kfadapter_main.py b/test/test_kfadapter_main.py index efe1385..cc7c448 100644 --- a/test/test_kfadapter_main.py +++ b/test/test_kfadapter_main.py @@ -15,16 +15,14 @@ # limitations under the License. # # ================================================================================== - -import sys -sys.path.append("kfadapter") -import kfadapter_main -from tmgr_logger import TMLogger +import json from flask_api import status -import json -from fake_kfconnect import FakeKfConnect, NegativeFakeAdditionalKfConnect, NegativeFakeKfConnect, NegativeFakeNoneKfConnect -from fake_kfconf import FakeKfConf + +from kfadapter import kfadapter_main +from kfadapter.tmgr_logger import TMLogger +from .fake_kfconnect import FakeKfConnect, NegativeFakeAdditionalKfConnect, NegativeFakeKfConnect, NegativeFakeNoneKfConnect +from .fake_kfconf import FakeKfConf class Test_pipeline_id_operations: diff --git a/test/test_kfadapter_util.py b/test/test_kfadapter_util.py index 5b377e9..0e3618e 100644 --- a/test/test_kfadapter_util.py +++ b/test/test_kfadapter_util.py @@ -16,12 +16,7 @@ # # ================================================================================== -import pytest -import sys -import string -from mock import patch -sys.path.append("../kfadapter") -import kfadapter_util +from kfadapter import kfadapter_util class Test_kfadapter_util: def setup_method(self): diff --git a/test/test_tmgr_logger.py b/test/test_tmgr_logger.py index 245f0f4..11aaa8a 100644 --- a/test/test_tmgr_logger.py +++ b/test/test_tmgr_logger.py @@ -16,13 +16,11 @@ # # ================================================================================== -import sys -sys.path.append("../kfadapter") -from tmgr_logger import TMLogger +from kfadapter.tmgr_logger import TMLogger class Test_tmgr_logger: def setup_method(self): - self.TMGR_LOGGER_OBJ = TMLogger("../config/log_config.yaml") + self.TMGR_LOGGER_OBJ = TMLogger("config/log_config.yaml") def test_get_loglevel(self): ret = self.TMGR_LOGGER_OBJ.get_logLevel diff --git a/test/unit_test.sh b/test/unit_test.sh index 305141d..bdf69b5 100755 --- a/test/unit_test.sh +++ b/test/unit_test.sh @@ -1,5 +1,3 @@ -// test/unit_test.sh - # ================================================================================== # # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. -- 2.16.6