import unittest
import sys
for path in ['../', './']:
    sys.path.insert(1, path)

#####################################
### Don't include for test report ###
#####################################
try: 
    class TestCoverage(unittest.TestCase):
        def test_init_main(self):
            try:
                # python -m unittest discover
                from db.entities import Cluster


                from datetime import date, datetime
                import json

                # add modules folder to interpreter path
                import sys
                import os
                modules_path = '../../../modules/'
                if os.path.exists(modules_path):
                    sys.path.insert(1, modules_path)

                ### init logging ###
                import logging
                LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d:  %(message)s')
                logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
                LOGGER = logging.getLogger(__name__)

                #############################
                import connexion
                from security import swagger_util
                from pathlib import Path
                from env_info import is_running_locally, get_resources_path
                from flask import request
                from flask import redirect
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                import main  #error when importing main, ModuleNotFoundError: No module named 'security'
            #exec(open('main.py').read())
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_init_run_clustering(self):
            try:
                import sys
                import os
                modules_path = '../../../modules/'
                if os.path.exists(modules_path):
                    sys.path.insert(1, modules_path)

                import json
                from db.entities import Layer, Cluster
                from typing import List, Dict, Tuple, Any
                from db.repository import Repository
                from processing.clustering import Clusterer, ClusterResult
            except Exception as e:
                print ("Exception found:")
                print (e)
            
            try:
                import run_clustering
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_init_run_node(self):
            try:
                import sys
                import os
                modules_path = '../../../modules/'
                if os.path.exists(modules_path):
                    sys.path.insert(1, modules_path)

                import json
                import urllib3
                urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
            except Exception as e:
                print ("Exception found:")
                print (e)
            
            try:
                import processing.fetching.fetching as f
                import run_node_fetching
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_init_run_similarity(self):
            try:
                import processing.similarityFiles.similarityMain as SimilarityCalc
                from db.repository import Repository

                import run_similarity_calc
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_init_run_time(self):
            try:
                import sys
                import os
                modules_path = '../../../modules/'
                if os.path.exists(modules_path):
                    sys.path.insert(1, modules_path)

                import json
                from datetime import datetime, date
                from db.repository import Repository
                from db.entities import ClusterSet, Cluster, Layer, TimeSlice
                from typing import Tuple, Dict, Any, List
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                import run_time_slicing
            except Exception as e:
                print ("Exception found:")
                print (e)


    if __name__ == '__main__':
        unittest.main()
except Exception as e:
    print ("Exception found:")
    print (e)