# ----------------------------------------------------------------------------
# Copyright (c) 2023, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from qiime2.plugin.testing import TestPluginBase
from ..utils import _validate_mag_ids, _validate_num_partitions


class TestHelpers(TestPluginBase):
    package = 'q2_moshpit.partition.tests'

    def test_validate_num_partitions_None(self):
        num_partitions = _validate_num_partitions(14, None)
        self.assertEqual(14, num_partitions)

    def test_validate_num_partitions_Warning(self):
        num_partitions = 15
        num_mags = 14
        with self.assertWarnsRegex(
            Warning,
            "You have requested a number of partitions"
            f" '{num_partitions}' that is greater than your number"
            f" of MAGs '{num_mags}.'"
        ):
            _ = _validate_num_partitions(num_mags, num_partitions)

    def test_validate_num_partitions_valid(self):
        num_partitions = _validate_num_partitions(14, 2)
        self.assertEqual(2, num_partitions)

    def test_validate_mag_ids_valid(self):
        _validate_mag_ids(
            6,
            6,
            [(0, "a"), (0, "b"), (0, "c"), (0, "d"), (0, "e"), (0, "f")]
        )

    def test_validate_mag_ids_invalid(self):
        with self.assertRaisesRegex(ValueError, "MAG IDs are not unique. "):
            _validate_mag_ids(
                6,
                6,
                [(0, "a"), (0, "a"), (0, "c"), (0, "d"), (0, "e"), (0, "f")]
            )
