def test_registry01(self): "Register in __init__" registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod) period1 = registry.get_period(MinutesPeriod.name, 1) self.assertIsInstance(period1, MinutesPeriod) period2 = registry.get_period(HoursPeriod.name, 1) self.assertIsInstance(period2, HoursPeriod) self.assertIsNone(registry.get_period('invalid', 1))
def setUpClass(cls): super().setUpClass() cls.registry = DatePeriodRegistry( MinutesPeriod, HoursPeriod, DaysPeriod, WeeksPeriod, MonthsPeriod, YearsPeriod, )
def test_registry02(self): "register() method" registry = DatePeriodRegistry() registry.register(DaysPeriod, WeeksPeriod) period = registry.get_period(DaysPeriod.name, 1) self.assertIsInstance(period, DaysPeriod) self.assertIsNone(registry.get_period(MinutesPeriod.name, 1))
def test_registry03(self): "Duplicates" registry = DatePeriodRegistry() with self.assertRaises(registry.RegistrationError): registry.register(DaysPeriod, WeeksPeriod, DaysPeriod)
def test_registry_3(self): registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod) field = DatePeriodField() field.period_registry = registry self.assertEqual(list(registry.choices()), list(field.choices))
def test_registry_2(self): registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod) self.assertEqual( list(registry.choices()), list(DatePeriodField(period_registry=registry).choices))
def test_registry_3(self): registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod) field = DatePeriodField() field.period_registry = registry self.assertListEqual([*registry.choices()], [*field.choices])
def test_registry_2(self): registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod) self.assertListEqual( [*registry.choices()], [*DatePeriodField(period_registry=registry).choices] )