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

import pytest
from . import OETestCase, check_license


@pytest.mark.skipif(check_license('medchem') is False,
                    reason='MEDCHEM license not found')
class TestMedChem(OETestCase):

    def test_frag_ring_chain(self):
        script = self.run_example('{0}/medchem/FragRingChain.py'.format(self.DOCEXAMPLES_DIR))
        self.assertFalse(script.returncode)

    def test_oemedchem_info(self):
        script = self.run_example('{0}/medchem/OEMedChemInfo.py'.format(self.EXAMPLES_DIR))
        self.assertFalse(script.returncode)

    def test_bemis_murcko_perception(self):
        script = self.run_example(
            '{0}/medchem/BemisMurckoPerception.py'.format(self.EXAMPLES_DIR),
            '{0}/data.smi'.format(self.DATA_DIR),
            'bemismurcko.sdf')
        self.assertFalse(script.returncode)

    def test_chembl_solubility(self):
        script = self.run_example(
            '{0}/medchem/ChEMBLsolubility.py'.format(self.EXAMPLES_DIR),
            '{0}/fit.sdf'.format(self.DATA_DIR),
            'chemblsolubility.smi')
        self.assertFalse(script.returncode)

    def test_matched_pair_transform(self):
        script = self.run_example(
            '{0}/medchem/CreateMMPIndex.py'.format(self.EXAMPLES_DIR),
            '-input', '{0}/data.smi'.format(self.DATA_DIR),
            '-output', 'data.smi.mmpidx',
            '-fragge', '20', '-fragle', '100', expect_stderr=True)
        self.assertFalse(script.returncode)
        script = self.run_example(
            '{0}/medchem/MatchedPairTransform.py'.format(self.EXAMPLES_DIR),
            '-mmpindex', 'data.smi.mmpidx',
            '-input', '{0}/data.smi'.format(self.DATA_DIR),
            '-output', 'matchedpairtransform.smi')
        self.assertFalse(script.returncode)

    def test_matched_pair_transform_list(self):
        script = self.run_example(
            '{0}/medchem/CreateMMPIndex.py'.format(self.EXAMPLES_DIR),
            '-input', '{0}/data.smi'.format(self.DATA_DIR),
            '-output', 'data.smi.mmpidx',
            '-fragge', '20', '-fragle', '100', expect_stderr=True)
        self.assertFalse(script.returncode)
        script = self.run_example(
            '{0}/medchem/MatchedPairTransformList.py'.format(self.EXAMPLES_DIR),
            '-mmpindex', 'data.smi.mmpidx', '-printlist', '1')
        self.assertFalse(script.returncode)

    def test_matched_pair_transform_probe(self):
        script = self.run_example(
            '{0}/medchem/CreateMMPIndex.py'.format(self.EXAMPLES_DIR),
            '-input', '{0}/data.smi'.format(self.DATA_DIR),
            '-output', 'data.smi.mmpidx',
            '-fragge', '20', '-fragle', '100', expect_stderr=True)
        self.assertFalse(script.returncode)
        script = self.run_example(
            '{0}/medchem/MatchedPairTransformProbe.py'.format(self.EXAMPLES_DIR),
            '-mmpindex', 'data.smi.mmpidx',
            '-input', '{0}/data.smi'.format(self.DATA_DIR),
            '-printlist', '1')
        self.assertFalse(script.returncode)
