<commit_before><commit_msg>Add tests for simple enums<commit_after>import unittest
from richenum import EnumConstructionException, enum


Breakfast = enum(
    COFFEE=0,
    OATMEAL=1,
    FRUIT=2)


class SimpleEnumTestSuite(unittest.TestCase):

    def test_members_are_accessible_through_attributes(self):
        self.assertEqual(Breakfast.COFFEE, 0)

    def test_lookup_by_name(self):
        self.assertEqual(Breakfast.get_id_by_label('COFFEE'), 0)

    def test_lookup_by_value(self):
        self.assertEqual(Breakfast.get_label_by_id(0), 'COFFEE')

    def test_can_cast_to_list_of_choices(self):
        self.assertEqual(
            Breakfast.choices,
            [(0, 'COFFEE'), (1, 'OATMEAL'), (2, 'FRUIT')])

    def test_choices_are_ordered_by_value(self):
        Shuffled = enum(FRUIT=2, COFFEE=0, OATMEAL=1)
        self.assertEqual(Shuffled.choices, Breakfast.choices)

    def test_values_can_be_any_hashable_type(self):
        try:
            Confused = enum(INT=0, TUPLE=(1, 2), STR='yup')
            self.assertEqual(Confused.get_id_by_label('TUPLE'), (1, 2))
        except:
            self.fail('Simple enums should accept values of any hashable type.')

        with self.assertRaisesRegexp(EnumConstructionException, 'hashable'):
            Confused = enum(LIST=[1, 2])
{'fraction_non_alphanumeric': 0.11136712749615975, 'fraction_numerical': 0.014592933947772658, 'mean_word_length': 3.5400696864111496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1540537', 'n_tokens_mistral': 456, 'n_tokens_neox': 433, 'n_words': 75}