|
2 | 2 | import os |
3 | 3 | import asyncio |
4 | 4 |
|
| 5 | +import pytest |
| 6 | +from process_bigraph import Composite |
| 7 | + |
5 | 8 | from worker.dispatch import JobDispatcher |
6 | 9 |
|
7 | | -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 10 | +# TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def test_dir() -> str: |
| 15 | + return os.path.dirname(os.path.abspath(__file__)) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +@pytest.mark.usefixtures("test_dir") |
| 20 | +def payload(test_dir: str) -> dict: |
| 21 | + with open(os.path.join(test_dir, "test_fixtures", "test_membrane_request2.json")) as f: |
| 22 | + test_request = json.load(f) |
| 23 | + return test_request |
| 24 | + |
8 | 25 |
|
| 26 | +@pytest.mark.usefixtures('payload') |
| 27 | +class TestDispatcher: |
| 28 | + def setup_method(self): |
| 29 | + self.dispatcher = JobDispatcher() |
9 | 30 |
|
10 | | -async def test_dispatch_composition(): |
11 | | - with open(os.path.join(TEST_DIR, "test_fixtures", "test_request.json")) as f: |
| 31 | + def test_generate_composition(self, payload: dict): |
| 32 | + composition = self.dispatcher.generate_composite(payload) |
| 33 | + assert composition is not None |
| 34 | + print(f'Got the composition state:\n{composition.state}') |
| 35 | + |
| 36 | + |
| 37 | +def get_test_dir() -> str: |
| 38 | + return os.path.dirname(os.path.abspath(__file__)) |
| 39 | + |
| 40 | + |
| 41 | +def get_payload() -> dict: |
| 42 | + test_dir = get_test_dir() |
| 43 | + with open(os.path.join(test_dir, "test_fixtures", "test_membrane_request2.json")) as f: |
12 | 44 | test_request = json.load(f) |
| 45 | + return test_request |
13 | 46 |
|
| 47 | + |
| 48 | +async def test_generate_composition(): |
14 | 49 | dispatcher = JobDispatcher() |
15 | | - await dispatcher.dispatch_composition(test_request) |
| 50 | + payload = get_payload() |
| 51 | + await dispatcher.dispatch_composition(payload) |
| 52 | + # assert composition is not None |
| 53 | + # print(f'Got the composition state:\n{composition.state}') |
| 54 | + |
| 55 | + |
| 56 | +asyncio.run(test_generate_composition()) |
16 | 57 |
|
| 58 | +# @pytest.mark.asyncio |
| 59 | +# async def test_dispatch_composition(): |
| 60 | +# dispatcher = JobDispatcher() |
| 61 | +# await dispatcher.dispatch_composition(test_request) |
17 | 62 |
|
18 | | -if __name__ == "__main__": |
19 | | - asyncio.run(test_dispatch_composition()) |
|
0 commit comments