|
| 1 | +import asyncio |
| 2 | +import pathlib |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +import textwrap |
| 6 | + |
1 | 7 | from azure.functions_worker import testutils |
2 | 8 |
|
3 | 9 |
|
@@ -26,3 +32,49 @@ def test_loader_relimport(self): |
26 | 32 | r = self.webhost.request('GET', 'relimport') |
27 | 33 | self.assertEqual(r.status_code, 200) |
28 | 34 | self.assertEqual(r.text, '__app__.relimport.relative') |
| 35 | + |
| 36 | + |
| 37 | +class TestPluginLoader(testutils.AsyncTestCase): |
| 38 | + |
| 39 | + async def test_entry_point_plugin(self): |
| 40 | + test_binding = pathlib.Path(__file__).parent / 'test-binding' |
| 41 | + subprocess.run([ |
| 42 | + sys.executable, '-m', 'pip', |
| 43 | + '--disable-pip-version-check', |
| 44 | + 'install', '--quiet', |
| 45 | + '-e', test_binding |
| 46 | + ], check=True) |
| 47 | + |
| 48 | + # This test must be run in a subprocess so that |
| 49 | + # pkg_resources picks up the newly installed package. |
| 50 | + code = textwrap.dedent(''' |
| 51 | + import asyncio |
| 52 | + from azure.functions_worker import protos |
| 53 | + from azure.functions_worker import testutils |
| 54 | +
|
| 55 | + async def _runner(): |
| 56 | + async with testutils.start_mockhost( |
| 57 | + script_root='test-binding/functions') as host: |
| 58 | + func_id, r = await host.load_function('foo') |
| 59 | +
|
| 60 | + print(r.response.function_id == func_id) |
| 61 | + print(r.response.result.status == protos.StatusResult.Success) |
| 62 | +
|
| 63 | + asyncio.get_event_loop().run_until_complete(_runner()) |
| 64 | + ''') |
| 65 | + |
| 66 | + try: |
| 67 | + proc = await asyncio.create_subprocess_exec( |
| 68 | + sys.executable, '-c', code, |
| 69 | + stdout=asyncio.subprocess.PIPE) |
| 70 | + |
| 71 | + stdout, stderr = await proc.communicate() |
| 72 | + |
| 73 | + self.assertEqual(stdout.strip().split(b'\n'), [b'True', b'True']) |
| 74 | + |
| 75 | + finally: |
| 76 | + subprocess.run([ |
| 77 | + sys.executable, '-m', 'pip', |
| 78 | + '--disable-pip-version-check', |
| 79 | + 'uninstall', '-y', '--quiet', 'foo-binding' |
| 80 | + ], check=True) |
0 commit comments