#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_orthoexon
----------------------------------

Tests for `orthoexon` module.
"""
import os
import pytest


@pytest.fixture
def exon_id_with_quotes():
    return "'ENSE00001229068.1'"

@pytest.fixture
def exon_id():
    return "ENSE00001229068.1"

def test_separate_with_quotes(exon_id_with_quotes):
    from orthoexon.util import separate

    test = separate(exon_id_with_quotes)
    true = "ENSE00001229068"

    assert test == true



def test_separate(exon_id):
    from orthoexon.util import separate

    test = separate(exon_id)
    true = "ENSE00001229068"

    assert test == true


@pytest.fixture
def location():
    return "chr20:10256140-10256211:+:0"

def test_splitstart(location):
    from orthoexon.util import splitstart

    test = splitstart(location)
    true = '10256140'

    assert test == true


def test_splitend(location):
    from orthoexon.util import splitend

    test = splitend(location)
    true = '10256211'

    assert test == true


@pytest.fixture
def human_gtf_filename(table_folder):
    return os.path.join(table_folder, 'humanrbfox2andfmr1andsnap25.gtf')

@pytest.fixture
def human_gtf_database(table_folder):
    return os.path.join(table_folder, 'humanrbfox2andfmr1andsnap25.gtf.db')

@pytest.fixture
def human_fasta(table_folder):
    return os.path.join(table_folder, 'GRCm38.p3.genome.fa')

def test_translate(exon_id, human_fasta, human_gtf_database):
    from orthoexon.util import translate
    from orthoexon.util import separate
    for index, species1gene in enumerate(human_gtf_database.features_of_type('gene')):
        species1gffutilsgeneid = str(species1gene['gene_id'])
        species1geneid = separate(species1gffutilsgeneid)

        for exon in human_gtf_database.children(species1geneid,
                                                featuretype='CDS',
                                                order_by='start'):
            if exon_id == exon:
                test = translate(exon, human_fasta)
            break
        break
    true = 'MAEDADMRNELEEMQRRADQLADE'
    assert test == true



# def test_getsequence(exon, human_gtf_database):
#     from orthoexon.util import getsequence
#
#     test = getsequence(exon, human_gtf_database)
#     true = 'ATGGCCGAAGACGCAGACATGCGCAATGAGCTGGAGGAGATGCAGCGAAGGGCTGACCAGTT' \
#            'GGCTGATGAG'
#
#     assert test == true

# def test_make_sequence_array(finalsequencedf):
#     from orthoexon.util import make_sequence_array
#
#     test = make_sequence_array(finalsequencedf)
#     true = ......
#
#     assert test == true
[((25, 11, 25, 40), 'orthoexon.util.separate', 'separate', ({(25, 20, 25, 39): 'exon_id_with_quotes'}, {}), '(exon_id_with_quotes)', False, 'from orthoexon.util import separate\n'), ((35, 11, 35, 28), 'orthoexon.util.separate', 'separate', ({(35, 20, 35, 27): 'exon_id'}, {}), '(exon_id)', False, 'from orthoexon.util import separate\n'), ((48, 11, 48, 31), 'orthoexon.util.splitstart', 'splitstart', ({(48, 22, 48, 30): 'location'}, {}), '(location)', False, 'from orthoexon.util import splitstart\n'), ((57, 11, 57, 29), 'orthoexon.util.splitend', 'splitend', ({(57, 20, 57, 28): 'location'}, {}), '(location)', False, 'from orthoexon.util import splitend\n'), ((65, 11, 65, 72), 'os.path.join', 'os.path.join', ({(65, 24, 65, 36): 'table_folder', (65, 38, 65, 71): '"""humanrbfox2andfmr1andsnap25.gtf"""'}, {}), "(table_folder, 'humanrbfox2andfmr1andsnap25.gtf')", False, 'import os\n'), ((69, 11, 69, 75), 'os.path.join', 'os.path.join', ({(69, 24, 69, 36): 'table_folder', (69, 38, 69, 74): '"""humanrbfox2andfmr1andsnap25.gtf.db"""'}, {}), "(table_folder, 'humanrbfox2andfmr1andsnap25.gtf.db')", False, 'import os\n'), ((73, 11, 73, 60), 'os.path.join', 'os.path.join', ({(73, 24, 73, 36): 'table_folder', (73, 38, 73, 59): '"""GRCm38.p3.genome.fa"""'}, {}), "(table_folder, 'GRCm38.p3.genome.fa')", False, 'import os\n'), ((80, 25, 80, 57), 'orthoexon.util.separate', 'separate', ({(80, 34, 80, 56): 'species1gffutilsgeneid'}, {}), '(species1gffutilsgeneid)', False, 'from orthoexon.util import separate\n'), ((86, 23, 86, 51), 'orthoexon.util.translate', 'translate', ({(86, 33, 86, 37): 'exon', (86, 39, 86, 50): 'human_fasta'}, {}), '(exon, human_fasta)', False, 'from orthoexon.util import translate\n')]