<commit_before>#!/usr/bin/env python3

from unittest import TestCase
from exfi.build_baited_bloom_filter import \
    build_baited_bloom_filter
import tempfile
import os
import time

to_delete = ["/tmp/" + report for report in [
    "categories_multiMatch.fa",
    "categories_noMatch.fa",
    "categories_summary.fa"
]]

# print(to_delete)

class TestBuildBaitedBloomFilter(TestCase):

    @classmethod
    def test_build_empty_transcriptome(self):
        '''build_baited_bloom_filter.py: try to bait with empty transcriptome

        Note: biobloommaker fails
        '''
        filename = tempfile.mktemp(suffix=".bf")
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/empty.txt",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=filename,
            threads=1,
            reads="exfi/tests/files/empty.txt"
        )
        # os.unlink(filename)  # no file is generated

    @classmethod
    def test_build_empty_library(self):
        '''build_baited_bloom_filter.py: build a BF without reads'''
        filename = tempfile.mktemp(suffix=".bf")
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=filename,
            threads=1,
            reads=["exfi/tests/files/empty.txt"]
        )
        os.unlink(filename)

    @classmethod
    def test_build_one_library(self):
        '''build_baited_bloom_filter.py: build the BF with one library'''
        filename = tempfile.mktemp(suffix=".bf")
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=filename,
            threads=1,
            reads=["exfi/tests/files/build_baited_bloom_filter/reads_1.fq"]
        )
        os.unlink(filename)

    @classmethod
    def test_build_two_libraries(self):
        '''build_baited_bloom_filter.py: build the BF with two libraries'''
        filename = tempfile.mktemp(suffix=".bf")
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=filename,
            threads=1,
            reads=[
                "exfi/tests/files/build_baited_bloom_filter/reads_1.fq",
                "exfi/tests/files/build_baited_bloom_filter/reads_2.fq"
            ]
        )
        os.unlink(filename)
<commit_msg>Better handling of tmp files<commit_after>#!/usr/bin/env python3

from unittest import TestCase
from exfi.build_baited_bloom_filter import \
    build_baited_bloom_filter
import tempfile
import os

class TestBuildBaitedBloomFilter(TestCase):

    @classmethod
    def test_build_empty_transcriptome(self):
        '''build_baited_bloom_filter.py: try to bait with empty transcriptome

        Note: biobloommaker fails
        '''
        folder = tempfile.mkdtemp()
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/empty.txt",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=folder + "test.bf",
            threads=1,
            reads="exfi/tests/files/empty.txt"
        )
        os.rmdir(folder)

    @classmethod
    def test_build_empty_library(self):
        '''build_baited_bloom_filter.py: build a BF without reads'''
        folder = tempfile.mkdtemp()
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=folder + "test.bf",
            threads=1,
            reads=["exfi/tests/files/empty.txt"]
        )
        os.rmdir(folder)

    @classmethod
    def test_build_one_library(self):
        '''build_baited_bloom_filter.py: build the BF with one library'''
        folder = tempfile.mkdtemp()
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=folder + "test.bf",
            threads=1,
            reads=["exfi/tests/files/build_baited_bloom_filter/reads_1.fq"]
        )
        os.rmdir(folder)

    @classmethod
    def test_build_two_libraries(self):
        '''build_baited_bloom_filter.py: build the BF with two libraries'''
        folder = tempfile.mkdtemp()
        build_baited_bloom_filter(
            transcriptome="exfi/tests/files/build_baited_bloom_filter/small_transcriptome.fa",
            kmer=30,
            bloom_size="100M",
            levels=1,
            output_bloom=folder + "test.bf",
            threads=1,
            reads=[
                "exfi/tests/files/build_baited_bloom_filter/reads_1.fq",
                "exfi/tests/files/build_baited_bloom_filter/reads_2.fq"
            ]
        )
        os.rmdir(folder)

{'fraction_non_alphanumeric': 0.09735530854733615, 'fraction_numerical': 0.012265235722499043, 'mean_word_length': 2.241614906832298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649664', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1626, 'n_words': 232}