Skip to content

Commit fbc22f9

Browse files
authored
Add github ci for tests (paradigmxyz#16)
* add github ci * update typing annotations * more typing annotations * update rust test action * update adapters * stop using local toolstr * revert to older type annotation syntax * do not require python mesc to be installed to run test suite * require Test type only for type annotations * Test type only necessary for type annotations
1 parent 88434ba commit fbc22f9

File tree

7 files changed

+102
-27
lines changed

7 files changed

+102
-27
lines changed

.github/workflows/python-tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Python Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up Python
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: '3.9'
15+
16+
- name: Install dependencies
17+
run: |
18+
pip install -e ./python
19+
pip install pytest pytest-xdist
20+
21+
- name: Run Python tests
22+
run: |
23+
cd tests
24+
pytest --adapters adapters/python
25+

.github/workflows/rust-tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Rust Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Install Rust
13+
uses: actions-rs/toolchain@v1
14+
with:
15+
profile: minimal
16+
toolchain: stable
17+
override: true
18+
19+
- name: Build and Install Rust Project
20+
run: |
21+
cd rust
22+
cargo install --path crates/mesc_cli
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: '3.9' # Specify your required Python version
28+
29+
- name: Install Python dependencies for testing
30+
run: |
31+
pip install pytest pytest-xdist
32+
33+
- name: Run Rust tests
34+
run: |
35+
cd tests
36+
pytest --adapters adapters/cli

rust/crates/mesc_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ serde = { workspace = true }
2525
serde_json = { workspace = true }
2626
thiserror = { workspace = true }
2727
tokio = { version = "1.32.0", features = ["full"] }
28-
toolstr = { version = "0.1.3", path = "../../../../toolstr/toolstr-rust/crates/toolstr" }
28+
toolstr = { version = "0.1.3" }
2929
url = "2.2.2"

tests/adapters/cli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import argparse
46
import json
57
import os
68
import subprocess
9+
import typing
710
from typing import cast
8-
from mesc.types import MescQuery
11+
12+
if typing.TYPE_CHECKING:
13+
from mesc.types import MescQuery
914

1015

1116
def run_query(query: MescQuery) -> str:

tests/adapters/python

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import argparse
46
import json
5-
from typing import Sequence, cast
7+
from typing import Sequence, cast, Union
68

79
from mesc.types import Endpoint, EndpointQuery
810
import mesc
911

1012

11-
def run_query(query: EndpointQuery) -> Endpoint | Sequence[Endpoint] | None:
13+
def run_query(query: EndpointQuery) -> Union[Endpoint, Sequence[Endpoint], None]:
1214
if query["query_type"] == "default_endpoint":
1315
default_fields = cast(mesc.types.DefaultEndpointQuery, query["fields"])
1416
return mesc.get_default_endpoint(**default_fields)
@@ -22,10 +24,10 @@ def run_query(query: EndpointQuery) -> Endpoint | Sequence[Endpoint] | None:
2224
user_input_fields = cast(mesc.types.UserInputQuery, query["fields"])
2325
return mesc.get_endpoint_by_query(**user_input_fields)
2426
elif query["query_type"] == "multi_endpoint":
25-
multi_endpoint_fields = cast(mesc.types.MultiEndpointQuery, query['fields'])
27+
multi_endpoint_fields = cast(mesc.types.MultiEndpointQuery, query["fields"])
2628
return mesc.find_endpoints(**multi_endpoint_fields)
2729
elif query["query_type"] == "global_metadata":
28-
return mesc.get_global_metadata(**query['fields'])
30+
return mesc.get_global_metadata(**query["fields"])
2931
else:
3032
raise Exception("invalid query type: " + str(query["query_type"]))
3133

tests/generate.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from __future__ import annotations
44

55
import copy
6-
from typing import Any, TypeVar, Sequence
6+
from typing import Any, TypeVar, Sequence, Union
7+
import typing
78

8-
from mesc import RpcConfig, Profile, Endpoint
9-
from mesc.types import MescQuery
9+
if typing.TYPE_CHECKING:
10+
from mesc import RpcConfig, Profile, Endpoint
11+
from mesc.types import MescQuery
1012

1113
blank_config: RpcConfig = {
1214
"mesc_version": "MESC 1.0",
@@ -120,14 +122,15 @@
120122
}
121123

122124
# tests are in form [test_name, env, config, query, result, should_succeed]
123-
Test = tuple[
124-
str,
125-
dict[str, str],
126-
RpcConfig,
127-
None | MescQuery,
128-
Any,
129-
bool,
130-
]
125+
if typing.TYPE_CHECKING:
126+
Test = tuple[
127+
str,
128+
dict[str, str],
129+
RpcConfig,
130+
Union[None, MescQuery],
131+
Any,
132+
bool,
133+
]
131134

132135

133136
def generate_tests() -> list[Test]:

tests/test_mesc.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@
1414
Generator,
1515
Mapping,
1616
cast,
17+
Union,
1718
)
1819
import pytest
1920

2021
import generate
21-
from mesc.types import EndpointQuery, MultiEndpointQuery, RpcConfig
2222

23+
import typing
2324

24-
# tests are in form [test_name, env, config, query, result, should_succeed]
25-
Test = tuple[
26-
str,
27-
dict[str, str],
28-
RpcConfig,
29-
None | EndpointQuery | MultiEndpointQuery,
30-
Any,
31-
bool,
32-
]
25+
if typing.TYPE_CHECKING:
26+
from mesc.types import RpcConfig, MescQuery
27+
28+
# tests are in form [test_name, env, config, query, result, should_succeed]
29+
Test = tuple[
30+
str,
31+
dict[str, str],
32+
RpcConfig,
33+
Union[None, MescQuery],
34+
Any,
35+
bool,
36+
]
3337

3438

3539
class AdapterFailure(Exception):

0 commit comments

Comments
 (0)