Commit cba246df authored by Bogdan's avatar Bogdan

Exception Handling on tests

parent 3d79e088
...@@ -35,14 +35,16 @@ try: ...@@ -35,14 +35,16 @@ try:
from env_info import is_running_locally, get_resources_path from env_info import is_running_locally, get_resources_path
from flask import request from flask import request
from flask import redirect from flask import redirect
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
import main #error when importing main, ModuleNotFoundError: No module named 'security' import main #error when importing main, ModuleNotFoundError: No module named 'security'
#exec(open('main.py').read()) #exec(open('main.py').read())
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_init_run_clustering(self): def test_init_run_clustering(self):
try: try:
...@@ -57,13 +59,15 @@ try: ...@@ -57,13 +59,15 @@ try:
from typing import List, Dict, Tuple, Any from typing import List, Dict, Tuple, Any
from db.repository import Repository from db.repository import Repository
from processing.clustering import Clusterer, ClusterResult from processing.clustering import Clusterer, ClusterResult
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
import run_clustering import run_clustering
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_init_run_node(self): def test_init_run_node(self):
try: try:
...@@ -76,14 +80,16 @@ try: ...@@ -76,14 +80,16 @@ try:
import json import json
import urllib3 import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
import processing.fetching.fetching as f import processing.fetching.fetching as f
import run_node_fetching import run_node_fetching
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_init_run_similarity(self): def test_init_run_similarity(self):
try: try:
...@@ -91,8 +97,9 @@ try: ...@@ -91,8 +97,9 @@ try:
from db.repository import Repository from db.repository import Repository
import run_similarity_calc import run_similarity_calc
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_init_run_time(self): def test_init_run_time(self):
try: try:
...@@ -107,16 +114,19 @@ try: ...@@ -107,16 +114,19 @@ try:
from db.repository import Repository from db.repository import Repository
from db.entities import ClusterSet, Cluster, Layer, TimeSlice from db.entities import ClusterSet, Cluster, Layer, TimeSlice
from typing import Tuple, Dict, Any, List from typing import Tuple, Dict, Any, List
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
import run_time_slicing import run_time_slicing
except: except Exception as e:
pass print ("Exception found:")
print (e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except: except Exception as e:
pass print ("Exception found:")
\ No newline at end of file print (e)
\ No newline at end of file
...@@ -12,13 +12,15 @@ import json ...@@ -12,13 +12,15 @@ import json
class TestCluster(unittest.TestCase): class TestCluster(unittest.TestCase):
def test_init_Cluster(self): def test_init_Cluster(self):
c = Cluster('debug', 'debug-table1', 'layer1', 1, [1, 2, 3]) try:
c = Cluster('debug', 'debug-table1', 'layer1', 1, [1, 2, 3])
self.assertEqual('debug', c.use_case)
self.assertEqual('debug-table1', c.use_case_table)
self.assertEqual(1, c.cluster_label)
self.assertEqual([1, 2, 3], c.nodes)
self.assertEqual('debug', c.use_case)
self.assertEqual('debug-table1', c.use_case_table)
self.assertEqual(1, c.cluster_label)
self.assertEqual([1, 2, 3], c.nodes)
except Exception as e:
print(e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -11,51 +11,74 @@ class TestClusterResult(unittest.TestCase): ...@@ -11,51 +11,74 @@ class TestClusterResult(unittest.TestCase):
converter:ClusterResultConverter = None converter:ClusterResultConverter = None
def setUp(self): def setUp(self):
self.converter = ClusterResultConverter() try:
self.converter = ClusterResultConverter()
except Exception as e:
print (e)
def test_result_undefined_feature(self): def test_result_undefined_feature(self):
cluster_groups = self._get_some_cluster_groups_1d() try:
cluster_res = self.converter.convert_to_cluster_results( cluster_groups = self._get_some_cluster_groups_1d()
cluster_groups=cluster_groups, cluster_res = self.converter.convert_to_cluster_results(
features=[] cluster_groups=cluster_groups,
) features=[]
)
self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels(['n.a.','n.a.','n.a.'], cluster_res) self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels(['n.a.','n.a.','n.a.'], cluster_res)
except Exception as e:
print (e)
def test_result_1d_feature(self): def test_result_1d_feature(self):
cluster_groups = self._get_some_cluster_groups_1d() try:
cluster_res = self.converter.convert_to_cluster_results( cluster_groups = self._get_some_cluster_groups_1d()
cluster_groups=cluster_groups, cluster_res = self.converter.convert_to_cluster_results(
features=['v'] cluster_groups=cluster_groups,
) features=['v']
)
self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels(['-1.0 -- 1.0','10.0 -- 11.0','2.0 -- 2.0'], cluster_res)
self.assert_correct_cluster_result_len(cluster_groups, cluster_res) except Exception as e:
self.assert_correct_cluster_result_labels(['-1.0 -- 1.0','10.0 -- 11.0','2.0 -- 2.0'], cluster_res) print (e)
def test_result_2d_features(self): def test_result_2d_features(self):
cluster_groups = self._get_some_cluster_groups_2d()
cluster_res = self.converter.convert_to_cluster_results( try:
cluster_groups=cluster_groups, cluster_groups = self._get_some_cluster_groups_2d()
features=['v', 'u'] cluster_res = self.converter.convert_to_cluster_results(
) cluster_groups=cluster_groups,
features=['v', 'u']
self.assert_correct_cluster_result_len(cluster_groups, cluster_res) )
self.assert_correct_cluster_result_labels([str((0.0,0.0)), str((10.5,10.5)), str((2.0,2.0)), str((3.0,6.0))], cluster_res)
self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels([str((0.0,0.0)), str((10.5,10.5)), str((2.0,2.0)), str((3.0,6.0))], cluster_res)
except Exception as e:
print (e)
#region Custom Assertions #region Custom Assertions
def assert_correct_cluster_result_len(self, expected: 'original dict of lists', actual: Dict[Any, ClusterResult]): def assert_correct_cluster_result_len(self, expected: 'original dict of lists', actual: Dict[Any, ClusterResult]):
self.assertEqual(len(expected), len(actual)) try:
for i in range(len(expected)): self.assertEqual(len(expected), len(actual))
self.assertEqual(len(expected[i]), len(actual[i].nodes)) for i in range(len(expected)):
self.assertEqual(expected[i], actual[i].nodes) self.assertEqual(len(expected[i]), len(actual[i].nodes))
self.assertEqual(expected[i], actual[i].nodes)
except Exception as e:
print (e)
def assert_correct_cluster_result_labels(self, expected: List[str], actual: Dict[Any, ClusterResult]): def assert_correct_cluster_result_labels(self, expected: List[str], actual: Dict[Any, ClusterResult]):
self.assertEqual(len(expected), len(actual)) try:
for i in range(len(expected)): self.assertEqual(len(expected), len(actual))
self.assertEqual(expected[i], actual[i].label) for i in range(len(expected)):
self.assertEqual(expected[i], actual[i].label)
except Exception as e:
print (e)
#endregion Custom Assertions #endregion Custom Assertions
......
...@@ -6,8 +6,8 @@ for path in ['../', './']: ...@@ -6,8 +6,8 @@ for path in ['../', './']:
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
try: def test_init_main(self):
def test_init_main(self): try:
# add modules folder to interpreter path # add modules folder to interpreter path
import sys import sys
import os import os
...@@ -34,30 +34,35 @@ try: ...@@ -34,30 +34,35 @@ try:
# init message handler # init message handler
from db.repository import Repository from db.repository import Repository
try: except Exception as e:
print ("Exception found:")
print (e)
try:
import main import main
except: except Exception as e:
pass print ("Exception found:")
except: print (e)
pass
def test_routes(self): def test_routes(self):
try: try:
from routes import debug from routes import debug
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from routes import layers from routes import layers
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from routes import nodes from routes import nodes
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_messaging(self): def test_messaging(self):
try: try:
...@@ -71,12 +76,14 @@ try: ...@@ -71,12 +76,14 @@ try:
from threading import Thread from threading import Thread
import logging import logging
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from messaging import MessageHandler from messaging import MessageHandler
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_db(self): def test_db(self):
try: try:
...@@ -90,16 +97,19 @@ try: ...@@ -90,16 +97,19 @@ try:
# init logging to file # init logging to file
import logging import logging
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from db import repository from db import repository
from db.entities import layer from db.entities import layer
except: except Exception as e:
pass print ("Exception found:")
print (e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except: except Exception as e:
pass print ("Exception found:")
\ No newline at end of file print (e)
\ No newline at end of file
...@@ -29,13 +29,15 @@ try: ...@@ -29,13 +29,15 @@ try:
app = connexion.App(__name__, specification_dir='configs/') app = connexion.App(__name__, specification_dir='configs/')
from db.entities.layer_adapter import LayerAdapter from db.entities.layer_adapter import LayerAdapter
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
import main import main
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_db_main(self): def test_db_main(self):
try: try:
...@@ -48,36 +50,42 @@ try: ...@@ -48,36 +50,42 @@ try:
import pymongo import pymongo
import json import json
from typing import List, Dict from typing import List, Dict
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from db import repository from db import repository
from db import table_repository from db import table_repository
from db import use_case_repository from db import use_case_repository
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_routes(self): def test_routes(self):
try: try:
from routes import layer from routes import layer
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from routes import tables from routes import tables
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from routes import use_case from routes import use_case
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_services(self): def test_services(self):
try: try:
from services import layer_adapter_service from services import layer_adapter_service
except: except Exception as e:
pass print ("Exception found:")
print (e)
def test_use_case_scripts(self): def test_use_case_scripts(self):
try: try:
...@@ -86,8 +94,9 @@ try: ...@@ -86,8 +94,9 @@ try:
import requests import requests
from typing import List from typing import List
from _add_use_case_scripts import requestPost from _add_use_case_scripts import requestPost
except: except Exception as e:
pass print ("Exception found:")
print (e)
####### #######
#from _add_use_case_scripts.bank-app import add_bank_app_schema ##eror not importing? invalid folder name? #from _add_use_case_scripts.bank-app import add_bank_app_schema ##eror not importing? invalid folder name?
...@@ -100,8 +109,9 @@ try: ...@@ -100,8 +109,9 @@ try:
from _add_use_case_scripts.car_sharing.tables import add_publication from _add_use_case_scripts.car_sharing.tables import add_publication
from _add_use_case_scripts.car_sharing.tables import add_travel from _add_use_case_scripts.car_sharing.tables import add_travel
from _add_use_case_scripts.car_sharing.tables import add_user from _add_use_case_scripts.car_sharing.tables import add_user
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from _add_use_case_scripts.crowd_journalism import add_crowdjournalism_schema from _add_use_case_scripts.crowd_journalism import add_crowdjournalism_schema
...@@ -110,14 +120,16 @@ try: ...@@ -110,14 +120,16 @@ try:
from _add_use_case_scripts.crowd_journalism.tables import add_purchase from _add_use_case_scripts.crowd_journalism.tables import add_purchase
from _add_use_case_scripts.crowd_journalism.tables import add_tag from _add_use_case_scripts.crowd_journalism.tables import add_tag
from _add_use_case_scripts.crowd_journalism.tables import add_video from _add_use_case_scripts.crowd_journalism.tables import add_video
except: except Exception as e:
pass print ("Exception found:")
print (e)
try: try:
from _add_use_case_scripts.debug import add_debug_schema from _add_use_case_scripts.debug import add_debug_schema
from _add_use_case_scripts.debug.tables import add_pizza_table from _add_use_case_scripts.debug.tables import add_pizza_table
except: except Exception as e:
pass print ("Exception found:")
print (e)
#from _add_use_case_scripts.smart-energy import add_smart_energy_schema #from _add_use_case_scripts.smart-energy import add_smart_energy_schema
#from _add_use_case_scripts.smart-energy.tables import add_smart_energy #from _add_use_case_scripts.smart-energy.tables import add_smart_energy
...@@ -125,10 +137,12 @@ try: ...@@ -125,10 +137,12 @@ try:
from _add_use_case_scripts.vialog import add_vialog_schema from _add_use_case_scripts.vialog import add_vialog_schema
from _add_use_case_scripts.vialog.tables import add_user from _add_use_case_scripts.vialog.tables import add_user
from _add_use_case_scripts.vialog.tables import add_video from _add_use_case_scripts.vialog.tables import add_video
except: except Exception as e:
pass print ("Exception found:")
print (e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except: except Exception as e:
pass print ("Exception found:")
\ No newline at end of file print (e)
\ No newline at end of file
...@@ -24,8 +24,9 @@ try: ...@@ -24,8 +24,9 @@ try:
LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d: %(message)s') LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d: %(message)s')
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
except: except Exception as e:
pass print ("Exception found:")
print (e)
################################# #################################
try: try:
import connexion import connexion
...@@ -33,10 +34,14 @@ try: ...@@ -33,10 +34,14 @@ try:
from env_info import is_running_locally, get_resources_path from env_info import is_running_locally, get_resources_path
from flask import request from flask import request
from flask import redirect from flask import redirect
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
import main #something in main is causing an infinite loop (probably an async task/ listener) import main #something in main is causing an infinite loop (probably an async task/ listener)
except: pass except Exception as e:
print ("Exception found:")
print (e)
print("Finished test main") print("Finished test main")
def test_database(self): def test_database(self):
...@@ -49,11 +54,15 @@ try: ...@@ -49,11 +54,15 @@ try:
import json import json
from db.entities.user import User from db.entities.user import User
from typing import List from typing import List
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from db import repository from db import repository
except: pass except Exception as e:
print ("Exception found:")
print (e)
print("Finished test db") print("Finished test db")
...@@ -73,18 +82,26 @@ try: ...@@ -73,18 +82,26 @@ try:
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Dict from typing import Dict
import bcrypt import bcrypt
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from services import login_wrapper from services import login_wrapper
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from services import token_service from services import token_service
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from services import user_service from services import user_service
except: pass except Exception as e:
print ("Exception found:")
print (e)
print("Finished test services") print("Finished test services")
def test_routes(self): def test_routes(self):
...@@ -101,17 +118,23 @@ try: ...@@ -101,17 +118,23 @@ try:
from services.token_service import TokenService from services.token_service import TokenService
import bcrypt import bcrypt
import jwt import jwt
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from routes import user from routes import user
except: pass except Exception as e:
print ("Exception found:")
print (e)
#from routes import blockchain_trace #message_sender in blockchain_trace is causing an infinite loop (probabily an async task//listener) #from routes import blockchain_trace #message_sender in blockchain_trace is causing an infinite loop (probabily an async task//listener)
try: try:
from routes import debug from routes import debug
except: pass except Exception as e:
print ("Exception found:")
print (e)
print("Finished test routes") print("Finished test routes")
def test_add_users(self): def test_add_users(self):
...@@ -131,16 +154,21 @@ try: ...@@ -131,16 +154,21 @@ try:
from services.user_service import UserService from services.user_service import UserService
from env_info import is_running_locally, get_resources_path from env_info import is_running_locally, get_resources_path
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
import add_users import add_users
except: pass except Exception as e:
print ("Exception found:")
print (e)
print("Finished test users") print("Finished test users")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except: except Exception as e:
pass print ("Exception found:")
\ No newline at end of file print (e)
\ No newline at end of file
...@@ -23,35 +23,49 @@ try: ...@@ -23,35 +23,49 @@ try:
LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d: %(message)s') LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d: %(message)s')
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
except: pass except Exception as e:
print ("Exception found:")
print (e)
############################# #############################
try: try:
import connexion import connexion
from security import swagger_util from security import swagger_util
from env_info import is_running_locally, get_resources_path from env_info import is_running_locally, get_resources_path
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from database.repository import Repository from database.repository import Repository
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from messaging.MessageHandler import MessageHandler from messaging.MessageHandler import MessageHandler
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from messaging.ReconnectingMessageManager import ReconnectingMessageManager from messaging.ReconnectingMessageManager import ReconnectingMessageManager
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from messaging.rest_fetcher import RestFetcher from messaging.rest_fetcher import RestFetcher
from flask import request from flask import request
from flask import redirect from flask import redirect
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
import main import main
except: pass except Exception as e:
print ("Exception found:")
print (e)
def test_database(self): def test_database(self):
# global imports (dont't worry, red is normal) # global imports (dont't worry, red is normal)
...@@ -64,10 +78,14 @@ try: ...@@ -64,10 +78,14 @@ try:
import pymongo import pymongo
import json import json
import time import time
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from database import repository from database import repository
except: pass except Exception as e:
print ("Exception found:")
print (e)
def test_messaging(self): def test_messaging(self):
try: try:
...@@ -84,33 +102,47 @@ try: ...@@ -84,33 +102,47 @@ try:
from typing import Dict from typing import Dict
from typing import List from typing import List
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from messaging import MessageHandler from messaging import MessageHandler
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from messaging import rest_fetcher from messaging import rest_fetcher
except: pass except Exception as e:
print ("Exception found:")
print (e)
def test_routes(self): def test_routes(self):
#global imports #global imports
try: try:
from database.entities.transaction import Transaction from database.entities.transaction import Transaction
from database.repository import Repository from database.repository import Repository
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
import json import json
from flask import Response, request from flask import Response, request
except: pass except Exception as e:
print ("Exception found:")
print (e)
try: try:
from routes import transactions from routes import transactions
except: pass except Exception as e:
print ("Exception found:")
print (e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except: pass except Exception as e:
\ No newline at end of file print ("Exception found:")
print (e)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment