def parse_fasta(filepath):
    """
    Parse a fasta file returning a generator yielding tuples of fasta headers to sequences.

    Note:
        This function should give equivalent results to SeqIO from BioPython

        .. code-block:: python

            from Bio import SeqIO
            # biopython to dict of header-seq
            hseqs_bio = {r.description:str(r.seq) for r in SeqIO.parse(fasta_path, 'fasta')}
            # this func to dict of header-seq
            hseqs = {header:seq for header, seq in parse_fasta(fasta_path)}
            # both methods should return the same dict
            assert hseqs == hseqs_bio

    Args:
        filepath (str): Fasta file path

    Returns:
        generator: yields tuples of (<fasta header>, <fasta sequence>)
    """
    with open(filepath, 'r') as f:
        seqs = []
        header = ''
        for line in f:
            line = line.strip()
            if line == '':
                continue
            if line[0] == '>':
                if header == '':
                    header = line.replace('>', '')
                else:
                    yield header, ''.join(seqs)
                    seqs = []
                    header = line.replace('>', '')
            else:
                seqs.append(line)
        yield header, ''.join(seqs)
