def test_write_sequence_object(self): with FastaWriter(self.path) as fw: fw.write(SequenceRecord("name", "CCATA")) fw.write(SequenceRecord("name2", "HELLO")) assert fw._file.closed with open(self.path) as t: assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
def test(self): with FastaWriter(self.path) as fw: fw.write("name", "CCATA") fw.write("name2", "HELLO") assert fw._file.closed with open(self.path) as t: assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
def test_write_to_file_like_object(self): bio = BytesIO() with FastaWriter(bio) as fw: fw.write(SequenceRecord("name", "CCATA")) fw.write(SequenceRecord("name2", "HELLO")) assert bio.getvalue() == b'>name\nCCATA\n>name2\nHELLO\n' assert not bio.closed assert not fw._file.closed
def test_linelength(self): with FastaWriter(self.path, line_length=3) as fw: fw.write("r1", "ACG") fw.write("r2", "CCAT") fw.write("r3", "TACCAG") assert fw._file.closed with open(self.path) as t: d = t.read() assert d == '>r1\nACG\n>r2\nCCA\nT\n>r3\nTAC\nCAG\n'
def test_fasta_writer_repr(tmp_path): with FastaWriter(tmp_path / "out.fasta") as fw: repr(fw)
def test_write_zero_length_sequence_record(self): bio = BytesIO() with FastaWriter(bio) as fw: fw.write(SequenceRecord("name", "")) assert bio.getvalue() == b'>name\n\n', '{!r}'.format(bio.getvalue())