From b7b7651ba0adab94cefc26d05e37eb986d8f2ae3 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:18:34 -0800 Subject: [PATCH 01/10] add github ci --- .github/workflows/python-tests.yml | 25 +++++++++++++++++++++ .github/workflows/rust-tests.yml | 35 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/python-tests.yml create mode 100644 .github/workflows/rust-tests.yml diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..d458ba1 --- /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/rust + diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml new file mode 100644 index 0000000..2e5c2c8 --- /dev/null +++ b/.github/workflows/rust-tests.yml @@ -0,0 +1,35 @@ +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: Install Python dependencies for testing + uses: actions/setup-python@v2 + with: + python-version: '3.x' + run: | + pip install pytest pytest-xdist + + - name: Run Rust tests + run: | + cd ../tests + pytest --adapters adapters/rust + From ff59205ed7c61f529686a6c446b33444c20b7526 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:22:03 -0800 Subject: [PATCH 02/10] update typing annotations --- tests/generate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/generate.py b/tests/generate.py index d659e6a..7be2b87 100755 --- a/tests/generate.py +++ b/tests/generate.py @@ -3,7 +3,7 @@ from __future__ import annotations import copy -from typing import Any, TypeVar, Sequence +from typing import Any, TypeVar, Sequence, Union from mesc import RpcConfig, Profile, Endpoint from mesc.types import MescQuery @@ -124,7 +124,7 @@ Test = tuple[ str, dict[str, str], RpcConfig, - None | MescQuery, + Union[None, MescQuery], Any, bool, ] From 0f8cb220df1f0ac27c185853cc580e76d1b07190 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:24:39 -0800 Subject: [PATCH 03/10] more typing annotations --- tests/test_mesc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_mesc.py b/tests/test_mesc.py index d972a57..5abcafa 100755 --- a/tests/test_mesc.py +++ b/tests/test_mesc.py @@ -14,11 +14,12 @@ from typing import ( Generator, Mapping, cast, + Union, ) import pytest import generate -from mesc.types import EndpointQuery, MultiEndpointQuery, RpcConfig +from mesc.types import RpcConfig, MescQuery # tests are in form [test_name, env, config, query, result, should_succeed] @@ -26,7 +27,7 @@ Test = tuple[ str, dict[str, str], RpcConfig, - None | EndpointQuery | MultiEndpointQuery, + Union[None, MescQuery], Any, bool, ] From 68994d692a51b4c90b5a8987568600b7739cce1d Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:25:58 -0800 Subject: [PATCH 04/10] update rust test action --- .github/workflows/rust-tests.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml index 2e5c2c8..2479abe 100644 --- a/.github/workflows/rust-tests.yml +++ b/.github/workflows/rust-tests.yml @@ -21,15 +21,16 @@ jobs: cd rust cargo install --path crates/mesc_cli - - name: Install Python dependencies for testing + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.x' + 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/rust - + cd tests + pytest From b3ca594cb702acdb68346f186c5987985f91d3cf Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:27:31 -0800 Subject: [PATCH 05/10] update adapters --- .github/workflows/python-tests.yml | 2 +- .github/workflows/rust-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index d458ba1..67e5403 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -21,5 +21,5 @@ jobs: - name: Run Python tests run: | cd tests - pytest --adapters adapters/rust + pytest --adapters adapters/python diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml index 2479abe..688dc9c 100644 --- a/.github/workflows/rust-tests.yml +++ b/.github/workflows/rust-tests.yml @@ -33,4 +33,4 @@ jobs: - name: Run Rust tests run: | cd tests - pytest + pytest --adapters adapters/cli From de2ee845a14549375d85ce6eb1de7d0c2670edf0 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:29:00 -0800 Subject: [PATCH 06/10] stop using local toolstr --- rust/crates/mesc_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 37214b33da50587ed9324b0c10d540f882b1b8c4 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:34:21 -0800 Subject: [PATCH 07/10] revert to older type annotation syntax --- tests/adapters/python | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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"])) From eb0bcc35163845703be824fb36fae60335d9e300 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:39:18 -0800 Subject: [PATCH 08/10] do not require python mesc to be installed to run test suite --- tests/adapters/cli | 7 ++++++- tests/generate.py | 6 ++++-- tests/test_mesc.py | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) 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/generate.py b/tests/generate.py index 7be2b87..d43ad58 100755 --- a/tests/generate.py +++ b/tests/generate.py @@ -4,9 +4,11 @@ from __future__ import annotations import copy 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", diff --git a/tests/test_mesc.py b/tests/test_mesc.py index 5abcafa..807de32 100755 --- a/tests/test_mesc.py +++ b/tests/test_mesc.py @@ -19,7 +19,11 @@ from typing import ( import pytest import generate -from mesc.types import RpcConfig, MescQuery + +import typing + +if typing.TYPE_CHECKING: + from mesc.types import RpcConfig, MescQuery # tests are in form [test_name, env, config, query, result, should_succeed] From fdd01f84d7c46b0846321a1b5f516d952e36c6c1 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:40:43 -0800 Subject: [PATCH 09/10] require Test type only for type annotations --- tests/generate.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/generate.py b/tests/generate.py index d43ad58..ed9a009 100755 --- a/tests/generate.py +++ b/tests/generate.py @@ -122,14 +122,15 @@ known_networks = { } # tests are in form [test_name, env, config, query, result, should_succeed] -Test = tuple[ - str, - dict[str, str], - RpcConfig, - Union[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]: From 8ee3550d3b0412ea74152e37fc253a7fefc7e8c7 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 28 Jan 2024 13:42:00 -0800 Subject: [PATCH 10/10] Test type only necessary for type annotations --- tests/test_mesc.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/test_mesc.py b/tests/test_mesc.py index 807de32..e1d3f02 100755 --- a/tests/test_mesc.py +++ b/tests/test_mesc.py @@ -25,16 +25,15 @@ import typing 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, -] + # 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):