def test_service_callable_with_active_client_with_no_registered_services( self, ): def myservice(): pass def myclient(): pass qualname_service = _qualname(myservice) self.lenient.__dict__[qualname_service] = True self.lenient.__dict__["active"] = _qualname(myclient) self.assertFalse(self.lenient(myservice))
def test_in_value_iterable_callable(self): def service1(): pass def service2(): pass client = "client" self.lenient.__dict__[client] = None qualname_services = (_qualname(service1), _qualname(service2)) self.lenient[client] = (service1, service2) self.assertEqual(self.lenient.__dict__[client], qualname_services)
def test_callable_service_callable(self): def client(): pass def service(): pass qualname_client = _qualname(client) qualname_service = _qualname(service) self.lenient.register_client(client, service) self.assertIn(qualname_client, self.lenient.__dict__) self.assertEqual(self.lenient.__dict__[qualname_client], (qualname_service, ))
def test_callable_in_value_callable(self): def client(): pass def service(): pass qualname_client = _qualname(client) qualname_service = _qualname(service) self.lenient.__dict__[qualname_client] = None self.lenient[client] = service self.assertEqual(self.lenient.__dict__[qualname_client], (qualname_service, ))
def test_args_services_callable(self): def service1(): pass def service2(): pass services = (service1, service2) lenient = _Lenient(*services) self.expected.update({ _qualname(service1): True, _qualname(service2): True }) self.assertEqual(self.expected, lenient.__dict__)
def test_service_callable_with_active_client_with_unmatched_registered_service_str( self, ): def myservice(): pass def myclient(): pass qualname_service = _qualname(myservice) qualname_client = _qualname(myclient) self.lenient.__dict__[qualname_service] = True self.lenient.__dict__["active"] = qualname_client self.lenient.__dict__[qualname_client] = f"{qualname_service}XXX" self.assertFalse(self.lenient(myservice))
def test_in_callable(self): def service(): pass qualname_service = _qualname(service) self.lenient.__dict__[qualname_service] = True self.assertTrue(self.lenient[service])
def test_callable_services_callable(self): def client(): pass def service1(): pass def service2(): pass qualname_client = _qualname(client) qualname_services = (_qualname(service1), _qualname(service2)) self.lenient.register_client(client, (service1, service2)) self.assertIn(qualname_client, self.lenient.__dict__) self.assertEqual(self.lenient.__dict__[qualname_client], qualname_services)
def test_disable_service_callable(self): def myservice(): pass qualname_service = _qualname(myservice) self.lenient.__dict__[qualname_service] = False self.assertFalse(self.lenient(myservice))
def test_service_callable_with_no_active_client(self): def myservice(): pass qualname_service = _qualname(myservice) self.lenient.__dict__[qualname_service] = True self.assertFalse(self.lenient(myservice))
def test_callable(self): def client(): pass qualname_client = _qualname(client) self.lenient.__dict__[qualname_client] = (None, ) self.lenient.unregister_client(client) self.assertNotIn(qualname_client, self.lenient.__dict__)
def test_callable(self): def service(): pass qualname_service = _qualname(service) self.lenient.__dict__[qualname_service] = True self.lenient.unregister_service(service) self.assertNotIn(qualname_service, self.lenient.__dict__)
def test_not_in_callable(self): def service(): pass qualname_service = _qualname(service) emsg = f"Invalid .* option, got '{qualname_service}'." with self.assertRaisesRegex(KeyError, emsg): _ = self.lenient[service]
def test_callable_function_local(self): def myfunc(): pass qualname_func = self.locals.format("test_callable_function_local", "myfunc") result = _qualname(myfunc) self.assertEqual(result, qualname_func)
def test_kwargs_clients_callable(self): def client1(): pass def client2(): pass def service1(): pass def service2(): pass qualname_client1 = _qualname(client1) qualname_client2 = _qualname(client2) clients = { qualname_client1: service1, qualname_client2: (service1, service2), } lenient = _Lenient(**clients) self.expected.update({ _qualname(client1): (_qualname(service1), ), _qualname(client2): (_qualname(service1), _qualname(service2)), }) self.assertEqual(self.expected, lenient.__dict__)
def test_service_callable_with_active_client_with_registered_services( self, ): def myservice(): pass def myclient(): pass qualname_service = _qualname(myservice) qualname_client = _qualname(myclient) self.lenient.__dict__[qualname_service] = True self.lenient.__dict__["active"] = qualname_client self.lenient.__dict__[qualname_client] = ( "service1", "service2", qualname_service, ) self.assertTrue(self.lenient(myservice))
def test_in_qualname(self): def func(): pass qualname_func = _qualname(func) lenient = _Lenient() lenient.__dict__[qualname_func] = None self.assertIn(func, lenient) self.assertIn(qualname_func, lenient)
def test_callable_in_value_iterable(self): def client(): pass qualname_client = _qualname(client) services = ("service1", "service2") self.lenient.__dict__[qualname_client] = None self.lenient[client] = services self.assertEqual(self.lenient.__dict__[qualname_client], services)
def test_in_value_callable(self): def service(): pass client = "client" qualname_service = _qualname(service) self.lenient.__dict__[client] = None self.lenient[client] = service self.assertEqual(self.lenient.__dict__[client], (qualname_service, ))
def test_callable_in_value_str(self): def client(): pass service = "service" qualname_client = _qualname(client) self.lenient.__dict__[qualname_client] = None self.lenient[client] = service self.assertEqual(self.lenient.__dict__[qualname_client], (service, ))
def test_active_callable(self): def client(): pass active = "active" qualname_client = _qualname(client) self.assertIsNone(self.lenient.__dict__[active]) self.lenient[active] = client self.assertEqual(self.lenient.__dict__[active], qualname_client)
def test_not_service_callable(self): def service(): pass qualname_service = _qualname(service) self.lenient.__dict__[qualname_service] = (None, ) emsg = "Cannot unregister .* service, as .* is not a valid .* service." with self.assertRaisesRegex(ValueError, emsg): self.lenient.unregister_service(service)
def test_callable_method_local(self): class MyClass: def mymethod(self): pass qualname_method = self.locals.format("test_callable_method_local", "MyClass.mymethod") result = _qualname(MyClass.mymethod) self.assertEqual(result, qualname_method)
def test_not_client_callable(self): def client(): pass qualname_client = _qualname(client) self.lenient.__dict__[qualname_client] = True emsg = "Cannot unregister .* client, as .* is not a valid .* client." with self.assertRaisesRegex(ValueError, emsg): self.lenient.unregister_client(client)
def test_callable_in_value_bool(self): def client(): pass qualname_client = _qualname(client) self.lenient.__dict__[qualname_client] = None self.lenient[client] = True self.assertTrue(self.lenient.__dict__[qualname_client]) self.assertFalse( isinstance(self.lenient.__dict__[qualname_client], Iterable))
def test_callable(self): def service(): pass qualname_service = _qualname(service) self.assertNotIn(qualname_service, self.lenient.__dict__) self.lenient.register_service(service) self.assertIn(qualname_service, self.lenient.__dict__) self.assertFalse( isinstance(self.lenient.__dict__[qualname_service], Iterable)) self.assertTrue(self.lenient.__dict__[qualname_service])
def test_active_callable(self): def client(): pass pre = self.copy() with self.lenient.context(active=client): context = self.copy() post = self.copy() qualname_client = _qualname(client) self.assertEqual(pre, self.default) expected = self.default.copy() expected.update(dict(active=qualname_client)) self.assertEqual(context, expected) self.assertEqual(post, self.default)
def test_args_callable(self): def service1(): pass def service2(): pass client = "client" services = (service1, service2) pre = self.copy() with self.lenient.context(*services, active=client): context = self.copy() post = self.copy() qualname_services = tuple([_qualname(service) for service in services]) self.assertEqual(pre, self.default) expected = self.default.copy() expected.update(dict(active=client, client=qualname_services)) self.assertEqual(context["active"], expected["active"]) self.assertEqual(set(context["client"]), set(expected["client"])) self.assertEqual(post, self.default)
def test_lenient_service(self): qualname___eq__ = _qualname(self.cls.__eq__) self.assertIn(qualname___eq__, _LENIENT) self.assertTrue(_LENIENT[qualname___eq__]) self.assertTrue(_LENIENT[self.cls.__eq__])
def test_lenient_service(self): qualname_equal = _qualname(self.cls.equal) self.assertIn(qualname_equal, _LENIENT) self.assertTrue(_LENIENT[qualname_equal]) self.assertTrue(_LENIENT[self.cls.equal])