# 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 FastROCS TK examples
"""

import pytest
from tempfile import NamedTemporaryFile
from . import OETestCase, check_license, check_fastrocs

# Order of skipif is not clearly defined so the check_license() may
# fail first and give a misleading reason because it tries the import also

@pytest.mark.skipif(check_fastrocs() == 0 and not check_license('fastrocs'),
                    reason='FastROCS license not found')
@pytest.mark.skipif(check_fastrocs() == 35,
                    reason='Insufficient NVIDIA Driver! Please update.')
@pytest.mark.skipif(check_fastrocs() == 1,
                    reason='No device found!')
@pytest.mark.skipif(check_fastrocs() == 3,
                    reason='CUDA driver and runtime could not be initialized!')
@pytest.mark.skipif(check_fastrocs() == 38,
                    reason='No CUDA-capable devices were detected!')
@pytest.mark.skipif(check_fastrocs() == 100,
                    reason='No CUDA-capable devices were detected!')
@pytest.mark.skipif(check_fastrocs() == 800,
                    reason='Attempted operation is not permitted!')
@pytest.mark.skipif(check_fastrocs() == -1,
                    reason='FastROCS is not supported on this platform!')
@pytest.mark.skipif(check_fastrocs() == 999,
                    reason='FastROCS is not available! Unknown error.')

class TestFastROCS(OETestCase):
    def test_simple_fastrocs_search(self):
        outfile = NamedTemporaryFile(prefix="fastrocs_", suffix='.oeb', delete=True)
        script = self.run_example(
            '{0}/fastrocs/SimpleFastROCSSearch.py'.format(self.EXAMPLES_DIR),
            '{0}/drugs.sdf'.format(self.DATA_DIR),
            '{0}/4std_lig.oeb.gz'.format(self.DATA_DIR),
            outfile.name,
            expect_stderr=True)
        if "No supported GPU available!" in script.stderr:
            pytest.skip('No supported GPU available!')
        self.assertFalse(script.returncode)
