def test_get_all_sequences(self): test_folder = os.path.abspath(os.path.dirname(__file__)) test_data_path = os.path.join(test_folder, 'data', 'cluster_A_multifasta.aln') cluster = ClusterConsensus() with open(test_data_path, 'r') as input_file: cluster.load_fasta_file(input_file) sequences = cluster._get_all_sequences(cluster.sequences) expected = ["AAAAACAAAAA-", "ATGAACAAAA--"] self.assertEqual(sequences, expected)
def test_get_all_sequences(self): test_folder = os.path.abspath(os.path.dirname(__file__)) test_data_path = os.path.join(test_folder, 'data', 'cluster_A_multifasta.aln') cluster = ClusterConsensus() with open(test_data_path, 'r') as input_file: cluster.load_fasta_file(input_file) sequences = cluster._get_all_sequences(cluster.sequences) expected = ["AAAAACAAAAA-", "ATGAACAAAA--"] self.assertEqual(sequences, expected)
def test_load_fasta_file(self, seqio_mock): cluster = ClusterConsensus() fake_file = StringIO("Some sequences") fake_sequence_generator = GeneratorMock(['AG', 'AG', 'AG']) seqio_mock.parse.return_value = fake_sequence_generator cluster.load_fasta_file(fake_file) seqio_mock.parse.assert_called_once_with(fake_file, 'fasta') self.assertEqual(cluster.sequences, fake_sequence_generator) self.assertEqual(fake_sequence_generator.call_count, 0) self.assertEqual(cluster.get_consensus(), 'AG') self.assertEqual(fake_sequence_generator.call_count, 3)
def test_load_fasta_file(self, seqio_mock): cluster = ClusterConsensus() fake_file = StringIO("Some sequences") fake_sequence_generator = GeneratorMock(['AG', 'AG', 'AG']) seqio_mock.parse.return_value = fake_sequence_generator cluster.load_fasta_file(fake_file) seqio_mock.parse.assert_called_once_with(fake_file, 'fasta') self.assertEqual(cluster.sequences, fake_sequence_generator) self.assertEqual(fake_sequence_generator.call_count, 0) self.assertEqual(cluster.get_consensus(), 'AG') self.assertEqual(fake_sequence_generator.call_count, 3)
def test_real_file(self): test_folder = os.path.abspath(os.path.dirname(__file__)) test_data_path = os.path.join(test_folder, 'data', 'cluster_A_multifasta.aln') cluster = ClusterConsensus() cluster.output_file = StringIO() cluster.output_file.name = "fake_filename.aln" with open(test_data_path, 'r') as input_file: cluster.load_fasta_file(input_file) cluster.write_consensus() expected_response = """\ >fake_filename ANNAACAAAANN """ cluster.output_file.seek(0) self.assertEqual(cluster.output_file.read(), expected_response)
def test_real_file(self): test_folder = os.path.abspath(os.path.dirname(__file__)) test_data_path = os.path.join(test_folder, 'data', 'cluster_A_multifasta.aln') cluster = ClusterConsensus() cluster.output_file = StringIO() cluster.output_file.name = "fake_filename.aln" with open(test_data_path, 'r') as input_file: cluster.load_fasta_file(input_file) cluster.write_consensus() expected_response = """\ >fake_filename ANNAACAAAANN """ cluster.output_file.seek(0) self.assertEqual(cluster.output_file.read(), expected_response)