# Path: alfpy/utils/fasta.py
# class FastaRecord():
#     def __init__(self, seq, seqid, description=False):
#     def __iter__(self):
#     def __contains__(self, char):
#     def __str__(self):
#     def __len__(self):
#     def format(self, wrap=70):
# def parse(handle):
# def read(handle):
# def to_dict(sequences):


import os
import unittest
from alfpy.utils import fasta
from . import utils

    def test_to_dict(self):
        fh = open(utils.get_test_data('pep.fa'))
        d = fasta.to_dict(fasta.parse(fh))
        fh.close()
        self.assertEqual(len(d), 4)

    def test_to_dict_value_error(self):
        h = ['>seq1\n', 'ATG\n', '>seq1\n', 'ATGC']
        with self.assertRaises(ValueError) as context:
            d = fasta.to_dict(fasta.parse(h))
        self.assertIn('Duplicate key', str(context.exception))
        

    def test_parse_fasta_missing_sequences(self):
        ids = ['seq1', 'seq2']
        seqs = ['ATGC', '']
        l = ['>{}\n'.format(ids[0]),
             '{}\n\n\n'.format(seqs[0]),
             '>{}\n'.format(ids[1]),
             '{}\n'.format(seqs[1])
             ]
        for i, fasta_record in enumerate(fasta.parse(l)):
            self.assertIsInstance(fasta_record, fasta.FastaRecord)
            self.assertEqual(fasta_record.seq, seqs[i])

    def test_fasta_format(self, wrap=70):
        l = ['>seq1 seq1 desc\n',
             'A' * wrap + '\n',
             'B' * wrap]

# Path: alfpy/utils/fasta.py
# class FastaRecord():
#     def __init__(self, seq, seqid, description=False):
#     def __iter__(self):
#     def __contains__(self, char):
#     def __str__(self):
#     def __len__(self):
#     def format(self, wrap=70):
# def parse(handle):
# def read(handle):
# def to_dict(sequences):


# Path: tests/test_fasta.py
import os
import unittest
from alfpy.utils import fasta
from . import utils


    def test_to_dict(self):
        fh = open(utils.get_test_data('pep.fa'))
        d = fasta.to_dict(fasta.parse(fh))
        fh.close()
        self.assertEqual(len(d), 4)

    def test_to_dict_value_error(self):
        h = ['>seq1\n', 'ATG\n', '>seq1\n', 'ATGC']
        with self.assertRaises(ValueError) as context:
            d = fasta.to_dict(fasta.parse(h))
        self.assertIn('Duplicate key', str(context.exception))
        

    def test_parse_fasta_missing_sequences(self):
        ids = ['seq1', 'seq2']
        seqs = ['ATGC', '']
        l = ['>{}\n'.format(ids[0]),
             '{}\n\n\n'.format(seqs[0]),
             '>{}\n'.format(ids[1]),
             '{}\n'.format(seqs[1])
             ]
        for i, fasta_record in enumerate(fasta.parse(l)):
            self.assertIsInstance(fasta_record, fasta.FastaRecord)
            self.assertEqual(fasta_record.seq, seqs[i])

    def test_fasta_format(self, wrap=70):
        l = ['>seq1 seq1 desc\n',
             'A' * wrap + '\n',
             'B' * wrap]

        r = fasta.read(l)