# CONFIDENTIAL. (C) 2017 OpenEye Scientific Software Inc.
# All rights reserved.
#
# ALL SOFTWARE BELOW IS PROPRIETARY AND CONFIDENTIAL TO OPENEYE
# SCIENTIFIC SOFTWARE INC., AND IS SUBJECT TO THE FULL PROTECTION OF
# COPYRIGHT AND TRADESECRET LAW.
# Copying or modifying this software is strictly prohibited and illegal.
# Using this software without a valid license from OpenEye 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 OpenEye at eyesopen.com/legal if you have any questions
# about this warning.
"""
 Test suite for GraphSim TK examples
"""

import pytest
from . import OETestCase, check_license, check_cuda_grapshim


@pytest.mark.skipif(check_license('graphsim') is False, reason='No CUDA-capable devices were detected')
class TestGraphSim(OETestCase):

    def test_fp2oeb(self):
        script = self.run_example('{0}/graphsim/FP2OEB.py'.format(self.DOCEXAMPLES_DIR),
                                  '{0}/data3d.sdf.gz'.format(self.DATA_DIR),
                                  'fp2oeb.oeb.gz')
        self.assertFalse(script.returncode)

    def test_fp_atom_typing(self):
        script = self.run_example('{0}/graphsim/FPAtomTyping.py'.format(self.DOCEXAMPLES_DIR))
        self.assertFalse(script.returncode)

    def test_fp_bit_string(self):
        script = self.run_example('{0}/graphsim/FPBitString.py'.format(self.DOCEXAMPLES_DIR))
        self.assertFalse(script.returncode)

    def test_fp_compare(self):
        script = self.run_example('{0}/graphsim/FPCompare.py'.format(self.DOCEXAMPLES_DIR))
        self.assertFalse(script.returncode)

    def test_makefastfp(self):
        script = self.run_example('{0}/graphsim/makefastfp.py'.format(self.EXAMPLES_DIR),
                                  '{0}/drugs.smi'.format(self.DATA_DIR),
                                  'drugs-tree.fpbin', expect_stderr=True)
        self.assertFalse(script.returncode)

    def test_searchfastfp_memory_mapped(self):
        script = self.run_example('{0}/graphsim/searchfastfp.py'.format(self.EXAMPLES_DIR),
                                  '-query', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-molfname', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-fpdbfname', '{0}/drugs-tree.fpbin'.format(self.DATA_DIR),
                                  '-out', 'hits.sdf',
                                  '-memorytype', 'memory-mapped', expect_stderr=True)
        self.assertFalse(script.returncode)

    def test_searchfastfp_in_memory(self):
        script = self.run_example('{0}/graphsim/searchfastfp.py'.format(self.EXAMPLES_DIR),
                                  '-query', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-molfname', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-fpdbfname', '{0}/drugs-tree.fpbin'.format(self.DATA_DIR),
                                  '-out', 'hits.sdf',
                                  '-memorytype', 'in-memory', expect_stderr=True)
        self.assertFalse(script.returncode)

    @pytest.mark.skipif(check_cuda_grapshim() is False, reason='No CUDA-capable devices were detected!')
    def test_searchfastfp_cuda(self):
        script = self.run_example('{0}/graphsim/searchfastfp.py'.format(self.EXAMPLES_DIR),
                                  '-query', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-molfname', '{0}/drugs.smi'.format(self.DATA_DIR),
                                  '-fpdbfname', '{0}/drugs-tree.fpbin'.format(self.DATA_DIR),
                                  '-out', 'hits.sdf',
                                  '-memorytype', 'CUDA', expect_stderr=True)
        self.assertFalse(script.returncode)
