# CONFIDENTIAL. (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# ALL SOFTWARE BELOW IS PROPRIETARY AND CONFIDENTIAL TO CADENCE
# AND IS SUBJECT TO THE FULL PROTECTION OF COPYRIGHT AND TRADE SECRET LAW.
# Copying or modifying this software is strictly prohibited and illegal.
# Using this software without a valid license from Cadence is strictly
# prohibited and illegal.  De-obfuscating, de-minimizing, or any other
# attempt to reverse engineer or discover the workings of this software,
# is strictly prohibited. Even if software is exposed or visible, it is
# still proprietary and confidential and the above prohibitions apply.
# This software is NOT "Sample Code". For purposes of customization or
# interoperation with other software you must use Sample Code
# specifically labeled as such.
# Please contact Cadence at eyesopen.com/legal if you have any questions
# about this warning.
"""
 Test suite for OpenEye Toolkits
"""

import os
import sys
import unittest
from scripttest import TestFileEnvironment


class OETestCase(unittest.TestCase):
    """
    Base class for all tests
    """

    def setUp(self):

        import openeye.tests
        import openeye.examples
        import openeye.docexamples

        self.env = TestFileEnvironment('./test-output')

        self.DATA_DIR = '{0}/data'.format(os.path.dirname(openeye.tests.__file__))
        self.EXAMPLES_DIR = '{0}'.format(os.path.dirname(openeye.examples.__file__))
        self.DOCEXAMPLES_DIR = '{0}'.format(os.path.dirname(openeye.docexamples.__file__))

    def run_example(self, *args, **kwargs):
        return self.env.run(sys.executable, *args, **kwargs)


def check_fastrocs():
    try:
        from openeye.oefastrocs import OEFastROCSGPUStatus
        return OEFastROCSGPUStatus()
    except ImportError:
        return -1

def check_cuda_grapshim():
    from openeye import oegraphsim
    return oegraphsim.OEGraphsimIsGPUReady()

def check_fastomega():
    from openeye import oeomega
    return oeomega.OEOmegaIsGPUReady()

def check_license(license_code):
    """
    Check the toolkit license
    :param: license_code
    """

    from openeye.oemedchem import OEMedChemIsLicensed
    from openeye.oechem import OEChemIsLicensed
    from openeye.oedepict import OEDepictIsLicensed
    from openeye.oedocking import OEDockingIsLicensed
    from openeye.oegrapheme import OEGraphemeIsLicensed
    from openeye.oegraphsim import OEGraphSimIsLicensed
    from openeye.oeiupac import OEIUPACIsLicensed
    from openeye.oemolprop import OEMolPropIsLicensed
    from openeye.oeomega import OEOmegaIsLicensed
    from openeye.oequacpac import OEQuacPacIsLicensed
    from openeye.oeshape import OEShapeIsLicensed
    from openeye.oespicoli import OESpicoliIsLicensed
    from openeye.oespruce import OESpruceIsLicensed
    from openeye.oeszybki import OESzybkiIsLicensed
    from openeye.oeszmap import OESzmapIsLicensed
    from openeye.oezap import OEZapIsLicensed

    license_status = {
        'medchem': OEMedChemIsLicensed(),
        'oechem': OEChemIsLicensed(),
        'depict': OEDepictIsLicensed(),
        'docking': OEDockingIsLicensed(),
        'grapheme': OEGraphemeIsLicensed(),
        'graphsim': OEGraphSimIsLicensed(),
        'lexichem': OEIUPACIsLicensed(),
        'molprop': OEMolPropIsLicensed(),
        'omega': OEOmegaIsLicensed(),
        'quacpac': OEQuacPacIsLicensed(),
        'shape': OEShapeIsLicensed(),
        'spruce': OESpruceIsLicensed(),
        'spicoli': OESpicoliIsLicensed(),
        'szmap': OESzmapIsLicensed(),
        'szybki': OESzybkiIsLicensed(),
        'zap': OEZapIsLicensed()
    }

    try:
        from openeye.oefastrocs import OEFastROCSIsLicensed
        license_status["fastrocs"] = OEFastROCSIsLicensed()
    except ImportError:
        print("Fastrocs is not available in this package... skipping")
        license_status["fastrocs"] = False

    return license_status[license_code]
