
from unittest import SkipTest
import logging

from pbcore.io import AlignmentSet

from pysiv2.custom.base import TestResequencingOutput
from pysiv2.io.datastore import DataStore

log = logging.getLogger(__name__)

class TestConsolidateAlignmentBam(TestResequencingOutput):
    """
    Test for behavior of BAM consolidation - only appropriate for jobs where
    this option was enabled.
    """

    def test_alignment_bam_is_single_file(self):
        """
        Test that the consolidated AlignmentSet contains a single BAM file.
        """
        if self.consolidated_alignment_file_name is None:
            raise SkipTest("No gathered AlignmentSet found")
        else:
            with AlignmentSet(self.consolidated_alignment_file_name) as ds:
                self.assertEqual(len(ds.toExternalFiles()), 1)
                ds.assertIndexed()
