<commit_before>import os
from pyfaidx import Fasta
from tempfile import NamedTemporaryFile

path = os.path.dirname(__file__)
os.chdir(path)

class TestMutableFastaRecord:
    def __init__(self):
        self.genes = os.path.join(path, 'data/genes.fasta')
        self.fasta = Fasta(self.genes)

    def setup(self):
        self.genes_copy = NamedTemporaryFile(mode='wb', delete=False)
        self.genes_copy.write(open(self.genes, 'rb').read())
        dup_name = self.genes_copy.name
        self.genes_copy.close()
        self.mutable_fasta = Fasta(self.genes_copy.name, mutable=True)

    def teardown(self):
        os.remove(self.mutable_fasta.filename)  # deletes temporary file

    def test_mutate_fasta_to_same(self):
        chunk = self.fasta['KF435150.1'][0:100]
        self.mutable_fasta['KF435150.1'][0:100] = chunk.seq
        assert str(self.fasta['KF435150.1']) == str(self.mutable_fasta['KF435150.1'])

    def test_mutate_fasta_to_N(self):
        chunk = 100 * 'N'
        self.mutable_fasta['KF435150.1'][0:100] = chunk
        assert self.mutable_fasta['KF435150.1'][0:100].seq == chunk
<commit_msg>Close the Faidx instance. #38<commit_after>import os
from pyfaidx import Fasta
from tempfile import NamedTemporaryFile

path = os.path.dirname(__file__)
os.chdir(path)

class TestMutableFastaRecord:
    def __init__(self):
        self.genes = os.path.join(path, 'data/genes.fasta')
        self.fasta = Fasta(self.genes)

    def setup(self):
        self.genes_copy = NamedTemporaryFile(mode='wb', delete=False)
        self.genes_copy.write(open(self.genes, 'rb').read())
        self.genes_copy.close()
        self.mutable_fasta = Fasta(self.genes_copy.name, mutable=True)

    def teardown(self):
        self.mutable_fasta.__exit__()
        os.remove(self.mutable_fasta.filename)  # deletes temporary file

    def test_mutate_fasta_to_same(self):
        chunk = self.fasta['KF435150.1'][0:100]
        self.mutable_fasta['KF435150.1'][0:100] = chunk.seq
        assert str(self.fasta['KF435150.1']) == str(self.mutable_fasta['KF435150.1'])

    def test_mutate_fasta_to_N(self):
        chunk = 100 * 'N'
        self.mutable_fasta['KF435150.1'][0:100] = chunk
        assert self.mutable_fasta['KF435150.1'][0:100].seq == chunk

{'fraction_non_alphanumeric': 0.13471731448763252, 'fraction_numerical': 0.054770318021201414, 'mean_word_length': 3.4586614173228347, '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': '6938478', 'n_tokens_mistral': 902, 'n_tokens_neox': 822, 'n_words': 123}