# import Kratos
import KratosMultiphysics
import KratosMultiphysics.StructuralMechanicsApplication as StructuralMechanicsApplication
import KratosMultiphysics.CSharpWrapperApplication as CSharpWrapperApplication
import run_cpp_unit_tests

# Import Kratos "wrapper" for unittests
import KratosMultiphysics.KratosUnittest as KratosUnittest

# Import subprocess
import subprocess

# Using kratos_utilities
import KratosMultiphysics.kratos_utilities as kratos_utilities
if kratos_utilities.CheckIfApplicationsAvailable("ExternalSolversApplication"):
    has_external_solvers_application = True
else:
    has_external_solvers_application = False

# Import the tests o test_classes to create the suits
## SMALL TESTS

## NIGTHLY TESTS

## VALIDATION TESTS

def AssembleTestSuites():
    ''' Populates the test suites to run.

    Populates the test suites to run. At least, it should pupulate the suites:
    "small", "nighlty" and "all"

    Return
    ------

    suites: A dictionary of suites
        The set of suites with its test_cases added.
    '''
    suites = KratosUnittest.KratosSuites

    # Create a test suit with the selected tests (Small tests):
    smallSuite = suites['small']

    # Create a test suit with the selected tests plus all small tests
    nightlySuite = suites['nightly']

    ### BEGIN SMALL SUITE ###

    ### END SMALL SUITE ###

    ### BEGIN NIGHTLY SUITE ###

    ### END VALIDATION SUITE ###

    ### BEGIN VALIDATION SUITE ###

    # For very long tests that should not be in nighly and you can use to validate
    validationSuite = suites['validation']
    validationSuite.addTests(nightlySuite)

    ### END VALIDATION ###

    # Create a test suit that contains all the tests:
    allSuite = suites['all']
    allSuite.addTests(nightlySuite) # Already contains the smallSuite
    validationSuite.addTests(allSuite) # Validation contains all

    # Manual list for debugging
    #allSuite.addTests(
        #KratosUnittest.TestLoader().loadTestsFromTestCases([
            #### STANDALONE
            #### SMALL
            #### NIGTHLY
            #### VALIDATION
        #])
    #)

    return suites

if __name__ == '__main__':
    KratosMultiphysics.Logger.PrintInfo("Unittests", "\nRunning cpp unit tests ...")
    run_cpp_unit_tests.run()
    KratosMultiphysics.Logger.PrintInfo("Unittests", "Finished running cpp unit tests!")

    KratosMultiphysics.Logger.PrintInfo("Unittests", "\nRunning python tests ...")
    KratosUnittest.runTests(AssembleTestSuites())
    KratosMultiphysics.Logger.PrintInfo("Unittests", "Finished python tests!")

[((469, 544), 'KratosMultiphysics.kratos_utilities.CheckIfApplicationsAvailable', 'kratos_utilities.CheckIfApplicationsAvailable', (['"""ExternalSolversApplication"""'], {}), "('ExternalSolversApplication')\n", (514, 544), True, 'import KratosMultiphysics.kratos_utilities as kratos_utilities\n'), ((2172, 2259), 'KratosMultiphysics.Logger.PrintInfo', 'KratosMultiphysics.Logger.PrintInfo', (['"""Unittests"""', '"""\nRunning cpp unit tests ..."""'], {}), '(\'Unittests\',\n    """\nRunning cpp unit tests ...""")\n', (2207, 2259), False, 'import KratosMultiphysics\n'), ((2257, 2281), 'run_cpp_unit_tests.run', 'run_cpp_unit_tests.run', ([], {}), '()\n', (2279, 2281), False, 'import run_cpp_unit_tests\n'), ((2286, 2374), 'KratosMultiphysics.Logger.PrintInfo', 'KratosMultiphysics.Logger.PrintInfo', (['"""Unittests"""', '"""Finished running cpp unit tests!"""'], {}), "('Unittests',\n    'Finished running cpp unit tests!')\n", (2321, 2374), False, 'import KratosMultiphysics\n'), ((2376, 2461), 'KratosMultiphysics.Logger.PrintInfo', 'KratosMultiphysics.Logger.PrintInfo', (['"""Unittests"""', '"""\nRunning python tests ..."""'], {}), '(\'Unittests\',\n    """\nRunning python tests ...""")\n', (2411, 2461), False, 'import KratosMultiphysics\n'), ((2509, 2583), 'KratosMultiphysics.Logger.PrintInfo', 'KratosMultiphysics.Logger.PrintInfo', (['"""Unittests"""', '"""Finished python tests!"""'], {}), "('Unittests', 'Finished python tests!')\n", (2544, 2583), False, 'import KratosMultiphysics\n')]