Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

not_async_context_manager.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """Test that an async context manager receives a proper object."""
  2. # pylint: disable=missing-docstring, import-error, too-few-public-methods
  3. import contextlib
  4. from ala import Portocala
  5. @contextlib.contextmanager
  6. def ctx_manager():
  7. yield
  8. class ContextManager(object):
  9. def __enter__(self):
  10. pass
  11. def __exit__(self, *args):
  12. pass
  13. class PartialAsyncContextManager(object):
  14. def __aenter__(self):
  15. pass
  16. class SecondPartialAsyncContextManager(object):
  17. def __aexit__(self, *args):
  18. pass
  19. class UnknownBases(Portocala):
  20. def __aenter__(self):
  21. pass
  22. class AsyncManagerMixin(object):
  23. pass
  24. class GoodAsyncManager(object):
  25. def __aenter__(self):
  26. pass
  27. def __aexit__(self, *args):
  28. pass
  29. class InheritExit(object):
  30. def __aexit__(self, *args):
  31. pass
  32. class SecondGoodAsyncManager(InheritExit):
  33. def __aenter__(self):
  34. pass
  35. async def bad_coro():
  36. async with 42: # [not-async-context-manager]
  37. pass
  38. async with ctx_manager(): # [not-async-context-manager]
  39. pass
  40. async with ContextManager(): # [not-async-context-manager]
  41. pass
  42. async with PartialAsyncContextManager(): # [not-async-context-manager]
  43. pass
  44. async with SecondPartialAsyncContextManager(): # [not-async-context-manager]
  45. pass
  46. async def good_coro():
  47. async with UnknownBases():
  48. pass
  49. async with AsyncManagerMixin():
  50. pass
  51. async with GoodAsyncManager():
  52. pass
  53. async with SecondGoodAsyncManager():
  54. pass