|
1 | 1 | """Dependency injector resource provider unit tests."""
|
2 | 2 |
|
3 | 3 | import asyncio
|
| 4 | +import inspect |
4 | 5 | import unittest
|
5 | 6 | from typing import Any
|
6 | 7 |
|
@@ -158,27 +159,21 @@ def shutdown(self, resource: TestDependency) -> None: ...
|
158 | 159 |
|
159 | 160 | self.assertTrue(issubclass(TestResource, resources.Resource))
|
160 | 161 |
|
161 |
| - def test_init_class_abc_definition_is_required(self): |
| 162 | + def test_init_class_abc_init_definition_is_required(self): |
162 | 163 | class TestResource(resources.Resource):
|
163 | 164 | ...
|
164 | 165 |
|
165 | 166 | with self.assertRaises(TypeError) as context:
|
166 | 167 | TestResource()
|
167 | 168 |
|
168 | 169 | self.assertIn("Can't instantiate abstract class TestResource", str(context.exception))
|
169 |
| - self.assertIn("init, shutdown", str(context.exception)) |
| 170 | + self.assertIn("init", str(context.exception)) |
170 | 171 |
|
171 |
| - |
172 |
| - def test_init_class_abc_shutdown_definition_is_required(self): |
| 172 | + def test_init_class_abc_shutdown_definition_is_not_required(self): |
173 | 173 | class TestResource(resources.Resource):
|
174 | 174 | def init(self):
|
175 | 175 | ...
|
176 |
| - |
177 |
| - with self.assertRaises(TypeError) as context: |
178 |
| - TestResource() |
179 |
| - |
180 |
| - self.assertIn("Can't instantiate abstract class TestResource", str(context.exception)) |
181 |
| - self.assertIn("shutdown", str(context.exception)) |
| 176 | + self.assertTrue(hasattr(TestResource(), 'shutdown')) |
182 | 177 |
|
183 | 178 | def test_init_not_callable(self):
|
184 | 179 | provider = providers.Resource(1)
|
@@ -497,26 +492,22 @@ async def shutdown(self, resource: TestDependency) -> None: ...
|
497 | 492 |
|
498 | 493 | self.assertTrue(issubclass(TestAsyncResource, resources.AsyncResource))
|
499 | 494 |
|
500 |
| - def test_init_async_class_abc_definition_is_required(self): |
| 495 | + def test_init_async_class_abc_init_definition_is_required(self): |
501 | 496 | class TestAsyncResource(resources.AsyncResource):
|
502 | 497 | ...
|
503 | 498 |
|
504 | 499 | with self.assertRaises(TypeError) as context:
|
505 | 500 | TestAsyncResource()
|
506 | 501 |
|
507 | 502 | self.assertIn("Can't instantiate abstract class TestAsyncResource", str(context.exception))
|
508 |
| - self.assertIn("init, shutdown", str(context.exception)) |
| 503 | + self.assertIn("init", str(context.exception)) |
509 | 504 |
|
510 |
| - def test_init_async_class_abc_shutdown_definition_is_required(self): |
| 505 | + def test_init_async_class_abc_shutdown_definition_is_not_required(self): |
511 | 506 | class TestAsyncResource(resources.AsyncResource):
|
512 | 507 | async def init(self):
|
513 | 508 | ...
|
514 |
| - |
515 |
| - with self.assertRaises(TypeError) as context: |
516 |
| - TestAsyncResource() |
517 |
| - |
518 |
| - self.assertIn("Can't instantiate abstract class TestAsyncResource", str(context.exception)) |
519 |
| - self.assertIn("shutdown", str(context.exception)) |
| 509 | + self.assertTrue(hasattr(TestAsyncResource(), 'shutdown')) |
| 510 | + self.assertTrue(inspect.iscoroutinefunction(TestAsyncResource.shutdown)) |
520 | 511 |
|
521 | 512 | def test_init_with_error(self):
|
522 | 513 | async def _init():
|
|
0 commit comments