christianhelle / autofaker

Python library designed to minimize the setup/arrange phase of your unit tests
MIT License
6 stars 3 forks source link

Enum support in the future? #6

Closed TheRobotCarlson closed 1 year ago

TheRobotCarlson commented 1 year ago

Love the idea of this! Our use case makes heavy use of enums. Are there plans for enum support in the future?

christianhelle commented 1 year ago

@TheRobotCarlson

Thank you for your kind words!

I have never worked with enums in Python before. May I ask you to provide a use case or examples of how you would use and test enums?

christianhelle commented 1 year ago

Will this work for you @TheRobotCarlson

from enum import Enum

class Weekday(Enum):
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3
    THURSDAY = 4
    FRIDAY = 5
    SATURDAY = 6
    SUNDAY = 7
from autofaker import autodata

@autodata(Weekday)
def test_create_enum_class_returns_not_none(sut):
    assert sut is not None

@autodata(Weekday)
def test_create_enum_class_returns_instance(sut):
    assert isinstance(sut, Weekday)

or

import unittest
from autofaker import Autodata

class AnonymousWeekdayTestCase(unittest.TestCase):

    def test_create_enum_class_returns_not_none(self):
        self.assertIsNotNone(Autodata.create(Weekday))

    def test_create_enum_class_returns_instance(self):
        self.assertIsInstance(Autodata.create(Weekday), Weekday)