diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..67e5403 --- /dev/null +++ b/.github/workflows/python-tests.yml @@ -0,0 +1,25 @@ +name: Python Tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + pip install -e ./python + pip install pytest pytest-xdist + + - name: Run Python tests + run: | + cd tests + pytest --adapters adapters/python + diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml new file mode 100644 index 0000000..688dc9c --- /dev/null +++ b/.github/workflows/rust-tests.yml @@ -0,0 +1,36 @@ +name: Rust Tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Build and Install Rust Project + run: | + cd rust + cargo install --path crates/mesc_cli + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' # Specify your required Python version + + - name: Install Python dependencies for testing + run: | + pip install pytest pytest-xdist + + - name: Run Rust tests + run: | + cd tests + pytest --adapters adapters/cli diff --git a/rust/crates/mesc_cli/Cargo.toml b/rust/crates/mesc_cli/Cargo.toml index 4245bfc..29fde7e 100644 --- a/rust/crates/mesc_cli/Cargo.toml +++ b/rust/crates/mesc_cli/Cargo.toml @@ -25,5 +25,5 @@ serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } tokio = { version = "1.32.0", features = ["full"] } -toolstr = { version = "0.1.3", path = "../../../../toolstr/toolstr-rust/crates/toolstr" } +toolstr = { version = "0.1.3" } url = "2.2.2" diff --git a/tests/adapters/cli b/tests/adapters/cli index 11db74b..5875665 100755 --- a/tests/adapters/cli +++ b/tests/adapters/cli @@ -1,11 +1,16 @@ #!/usr/bin/env python3 +from __future__ import annotations + import argparse import json import os import subprocess +import typing from typing import cast -from mesc.types import MescQuery + +if typing.TYPE_CHECKING: + from mesc.types import MescQuery def run_query(query: MescQuery) -> str: diff --git a/tests/adapters/python b/tests/adapters/python index d6e451a..3635a59 100755 --- a/tests/adapters/python +++ b/tests/adapters/python @@ -1,14 +1,16 @@ #!/usr/bin/env python3 +from __future__ import annotations + import argparse import json -from typing import Sequence, cast +from typing import Sequence, cast, Union from mesc.types import Endpoint, EndpointQuery import mesc -def run_query(query: EndpointQuery) -> Endpoint | Sequence[Endpoint] | None: +def run_query(query: EndpointQuery) -> Union[Endpoint, Sequence[Endpoint], None]: if query["query_type"] == "default_endpoint": default_fields = cast(mesc.types.DefaultEndpointQuery, query["fields"]) return mesc.get_default_endpoint(**default_fields) @@ -22,10 +24,10 @@ def run_query(query: EndpointQuery) -> Endpoint | Sequence[Endpoint] | None: user_input_fields = cast(mesc.types.UserInputQuery, query["fields"]) return mesc.get_endpoint_by_query(**user_input_fields) elif query["query_type"] == "multi_endpoint": - multi_endpoint_fields = cast(mesc.types.MultiEndpointQuery, query['fields']) + multi_endpoint_fields = cast(mesc.types.MultiEndpointQuery, query["fields"]) return mesc.find_endpoints(**multi_endpoint_fields) elif query["query_type"] == "global_metadata": - return mesc.get_global_metadata(**query['fields']) + return mesc.get_global_metadata(**query["fields"]) else: raise Exception("invalid query type: " + str(query["query_type"])) diff --git a/tests/generate.py b/tests/generate.py index d659e6a..ed9a009 100755 --- a/tests/generate.py +++ b/tests/generate.py @@ -3,10 +3,12 @@ from __future__ import annotations import copy -from typing import Any, TypeVar, Sequence +from typing import Any, TypeVar, Sequence, Union +import typing -from mesc import RpcConfig, Profile, Endpoint -from mesc.types import MescQuery +if typing.TYPE_CHECKING: + from mesc import RpcConfig, Profile, Endpoint + from mesc.types import MescQuery blank_config: RpcConfig = { "mesc_version": "MESC 1.0", @@ -120,14 +122,15 @@ known_networks = { } # tests are in form [test_name, env, config, query, result, should_succeed] -Test = tuple[ - str, - dict[str, str], - RpcConfig, - None | MescQuery, - Any, - bool, -] +if typing.TYPE_CHECKING: + Test = tuple[ + str, + dict[str, str], + RpcConfig, + Union[None, MescQuery], + Any, + bool, + ] def generate_tests() -> list[Test]: diff --git a/tests/test_mesc.py b/tests/test_mesc.py index d972a57..e1d3f02 100755 --- a/tests/test_mesc.py +++ b/tests/test_mesc.py @@ -14,22 +14,26 @@ from typing import ( Generator, Mapping, cast, + Union, ) import pytest import generate -from mesc.types import EndpointQuery, MultiEndpointQuery, RpcConfig +import typing -# tests are in form [test_name, env, config, query, result, should_succeed] -Test = tuple[ - str, - dict[str, str], - RpcConfig, - None | EndpointQuery | MultiEndpointQuery, - Any, - bool, -] +if typing.TYPE_CHECKING: + from mesc.types import RpcConfig, MescQuery + + # tests are in form [test_name, env, config, query, result, should_succeed] + Test = tuple[ + str, + dict[str, str], + RpcConfig, + Union[None, MescQuery], + Any, + bool, + ] class AdapterFailure(Exception):