|
| 1 | +import os |
| 2 | +import asyncio |
| 3 | + |
| 4 | + |
| 5 | +files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("awaitme")] |
| 6 | +for f in files: |
| 7 | + exec("import " + f[:-3] + " as " + f[:-3]) |
| 8 | + |
| 9 | + |
| 10 | +def test_names(): |
| 11 | + for f in files: |
| 12 | + assert "awaitme" in dir(eval(f[:-3])), "awaitme is not defined in " + f[:-3] |
| 13 | + |
| 14 | +def test_callables(): |
| 15 | + for f in files: |
| 16 | + assert callable(eval(f[:-3]).awaitme), "awaitme is not callable in " + f[:-3] |
| 17 | + |
| 18 | +def test_awaitable(): |
| 19 | + for f in files: |
| 20 | + @eval(f[:-3]).awaitme |
| 21 | + def dummy_awaitable(): |
| 22 | + return 1 |
| 23 | + @eval(f[:-3]).awaitme |
| 24 | + def dummy_function(x: int = 0, y: int = 0) -> int: |
| 25 | + return x + y |
| 26 | + assert asyncio.iscoroutinefunction(dummy_awaitable), "awaitme is not awaitable in " + f[:-3] |
| 27 | + assert asyncio.iscoroutinefunction(dummy_function), "awaitme is not awaitable in " + f[:-3] |
| 28 | + |
| 29 | +def test_values(): |
| 30 | + for f in files: |
| 31 | + @eval(f[:-3]).awaitme |
| 32 | + def dummy_awaitable(): |
| 33 | + return 1 |
| 34 | + @eval(f[:-3]).awaitme |
| 35 | + def dummy_function(x: int = 0, y: int = 0) -> int: |
| 36 | + return x + y |
| 37 | + @eval(f[:-3]).awaitme |
| 38 | + def another_dummy_function(s: str = "") -> str: |
| 39 | + return s.capitalize() |
| 40 | + @eval(f[:-3]).awaitme |
| 41 | + def dummy_tuple_return() -> tuple: |
| 42 | + return 1, 2, 3 |
| 43 | + async def just_a_tester(): |
| 44 | + result = await dummy_awaitable() |
| 45 | + assert result == 1, "awaitme is not returning the correct value in " + f[:-3] |
| 46 | + result = await dummy_function(1, 2) |
| 47 | + assert result == 3, "awaitme is not returning the correct value in " + f[:-3] |
| 48 | + result = await another_dummy_function("bora") |
| 49 | + assert result == "Bora", "awaitme is not returning the correct value in " + f[:-3] |
| 50 | + result = await dummy_tuple_return() |
| 51 | + assert result == (1, 2, 3), "awaitme is not returning the correct value in " + f[:-3] |
| 52 | + asyncio.run(just_a_tester()) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + test_names() |
| 57 | + test_callables() |
| 58 | + test_awaitable() |
| 59 | + test_values() |
| 60 | + print("Everything passed") |
0 commit comments