def test_deactivated_callable(self): """ Disabled enforcers should be returning just Callable """ settings = Settings(enabled=False) func = no_type_check(self.func_int___none()) wrapped = apply_enforcer(func) enforcer = wrapped.__enforcer__ func_type = enforcer.callable_signature self.assertEqual(func_type, Callable) func = self.func_int___none() self.assertFalse(hasattr(func, "__enforcer__")) wrapped = apply_enforcer(func, settings=settings) enforcer = wrapped.__enforcer__ func_type = enforcer.callable_signature self.assertIsNotNone(enforcer.settings) self.assertFalse(enforcer.settings) self.assertFalse(enforcer.settings.enabled) self.assertEqual(func_type, Callable)
def test_mode_value(self): """ Verifies that mode and covariant/contravariant properties work as expected Invariant by default - even if 'mode' is set to None """ settings = Settings() self.assertEqual(settings.mode, ModeChoices.invariant) self.assertFalse(settings.covariant) self.assertFalse(settings.contravariant) config({'mode': ModeChoices.covariant.name}) self.assertEqual(settings.mode, ModeChoices.covariant) self.assertTrue(settings.covariant) self.assertFalse(settings.contravariant) config({'mode': ModeChoices.contravariant.name}) self.assertEqual(settings.mode, ModeChoices.contravariant) self.assertFalse(settings.covariant) self.assertTrue(settings.contravariant) config({'mode': ModeChoices.invariant.name}) self.assertEqual(settings.mode, ModeChoices.invariant) self.assertFalse(settings.covariant) self.assertFalse(settings.contravariant) config({'mode': ModeChoices.bivariant.name}) self.assertEqual(settings.mode, ModeChoices.bivariant) self.assertTrue(settings.covariant) self.assertTrue(settings.contravariant) _GLOBAL_SETTINGS['mode'] = None self.assertEqual(settings.mode, ModeChoices.invariant) self.assertFalse(settings.covariant) self.assertFalse(settings.contravariant)
def test_groups(self): """ Verifies that settings can be assigned to a group different from the default Also, verifies that local enabled takes precedence over the group enabled status """ settings = Settings(group='my_group') self.assertFalse(settings) self.assertEqual(settings.group, 'my_group') config({'groups': {'set': {'my_group': True}}}) self.assertTrue(settings) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) ################## config(reset=True) settings = Settings(group='my_group', enabled=True) self.assertTrue(settings) self.assertEqual(settings.group, 'my_group') config({'groups': {'set': {'my_group': True}}}) self.assertTrue(settings) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) ################## config(reset=True) settings = Settings(group='my_group', enabled=False) self.assertFalse(settings) self.assertEqual(settings.group, 'my_group') config({'groups': {'set': {'my_group': True}}}) self.assertFalse(settings) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled'])
def test_can_create_settings_instance(self): """ Verifies that Settings instance and especially its enabled property work as intended """ settings = Settings() self.assertFalse(settings.enabled) self.assertFalse(settings) self.assertEqual(settings.group, 'default') settings.enabled = False self.assertFalse(settings.enabled) self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = True self.assertTrue(settings.enabled) self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) ############################################# settings = Settings(enabled=True) self.assertTrue(settings.enabled) self.assertTrue(settings) self.assertEqual(settings.group, 'default') settings.enabled = False self.assertFalse(settings.enabled) self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = True self.assertTrue(settings.enabled) self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) ############################################# settings = Settings(enabled=False) self.assertFalse(settings.enabled) self.assertFalse(settings) self.assertEqual(settings.group, 'default') settings.enabled = True self.assertTrue(settings.enabled) self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled']) settings.enabled = False self.assertFalse(settings.enabled) self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS['enabled'])
def test_groups(self): """ Verifies that settings can be assigned to a group different from the default Also, verifies that local enabled takes precedence over the group enabled status """ settings = Settings(group="my_group") self.assertFalse(settings) self.assertEqual(settings.group, "my_group") config({"groups": {"set": {"my_group": True}}}) self.assertTrue(settings) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"]) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"]) ################## config(reset=True) settings = Settings(group="my_group", enabled=True) self.assertTrue(settings) self.assertEqual(settings.group, "my_group") config({"groups": {"set": {"my_group": True}}}) self.assertTrue(settings) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"]) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"]) ################## config(reset=True) settings = Settings(group="my_group", enabled=False) self.assertFalse(settings) self.assertEqual(settings.group, "my_group") config({"groups": {"set": {"my_group": True}}}) self.assertFalse(settings) settings.enabled = True self.assertTrue(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"]) settings.enabled = False self.assertFalse(settings) self.assertTrue(_GLOBAL_SETTINGS["enabled"])