from django.test import SimpleTestCase

from ..base import Constants, C


class TestConstants(SimpleTestCase):

    def test_invalid_codename(self):
        """Each codename must be a valid Python identifier."""
        with self.assertRaises(AttributeError):
            Constants(C(codename='9invalid', value=1, description='Invalid'))

    def test_conflicting_codename(self):
        """Codename cannot conflict with an existing attribute."""
        with self.assertRaises(AttributeError):
            Constants(C(codename='get_choices', value=1, description='Conflicting'))

    def test_duplicate_codename(self):
        """Codenames cannot be duplicated."""
        with self.assertRaises(AttributeError):
            Constants(
                C(codename='duplicate', value=1, description='Duplicated 1'),
                C(codename='duplicate', value=2, description='Duplicated 2'),
            )

    def test_get_choices(self):
        """
        get_choices() should return a choices list in Django's format, in the
        order in which the choices were originally passed in.
        """
        constants = Constants(
            C(codename='hello', value=1, description='First'),
            C(codename='world', value=2, description='Second'),
        )
        self.assertEquals(constants.get_choices(), [
            (1, 'First'),
            (2, 'Second'),
        ])

    def test_repr(self):
        """Smoke test for string representation."""
        str(Constants(C(codename='hello', value=1, description='Hello')))

    def test_get_values(self):
        constants = Constants(
            C(codename='hello', value=1, description='First'),
            C(codename='world', value=2, description='Second'),
        )
        self.assertEquals(constants.get_values('hello', 'world'), [1, 2])

    def test_get_invalid_value(self):
        constants = Constants(
            C(codename='hello', value=1, description='First'),
            C(codename='world', value=2, description='Second'),
        )
        with self.assertRaises(AttributeError):
            self.assertEquals(constants.get_values('invalid'))

@@ -901,16 +901,660 @@
      )%0A%0A
+    def test_initialization_formats(self):%0A        %22%22%22Constants can be initialized in multiple ways.%22%22%22%0A        constants = Constants(%0A            C(codename=%22one%22, value=1, description=%22You can use **kwargs%22),%0A            C(%22two%22, 2, %22You can use *args%22),%0A            C(%22three%22, 3, description=%22You can mix *args and **kwargs%22),%0A            (%22four%22, 4, %22You can use a 3-tuple%22),%0A            %5B%22five%22, 5, %22You can use an iterable of length 3%22%5D,%0A        )%0A        codenames = %5B%22one%22, %22two%22, %22three%22, %22four%22, %22five%22%5D%0A        for value, codename in enumerate(codenames, start=1):%0A            self.assertEquals(getattr(constants, codename), value)%0A%0A
     def 

Test constant initialization formats