Skip to content

Commit 65c6d4f

Browse files
committed
use argparse in tests
1 parent 6c8be58 commit 65c6d4f

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

.github/workflows/test.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
just start
2828
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
2929
kubectl port-forward svc/rpc 9276:9276 &
30-
- run: ./test/scenarios_test.py ${{matrix.backend}}
30+
- run: ./test/scenarios_test.py --backend=${{matrix.backend}}
3131
rpc:
3232
runs-on: ubuntu-latest
3333
strategy:
@@ -48,7 +48,7 @@ jobs:
4848
just start
4949
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
5050
kubectl port-forward svc/rpc 9276:9276 &
51-
- run: ./test/rpc_test.py ${{matrix.backend}}
51+
- run: ./test/rpc_test.py --backend=${{matrix.backend}}
5252
graph:
5353
runs-on: ubuntu-latest
5454
strategy:
@@ -69,7 +69,7 @@ jobs:
6969
just start
7070
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
7171
kubectl port-forward svc/rpc 9276:9276 &
72-
- run: ./test/graph_test.py ${{matrix.backend}}
72+
- run: ./test/graph_test.py --backend=${{matrix.backend}}
7373
ln:
7474
runs-on: ubuntu-latest
7575
strategy:
@@ -90,7 +90,7 @@ jobs:
9090
just start
9191
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
9292
kubectl port-forward svc/rpc 9276:9276 &
93-
- run: ./test/ln_test.py ${{matrix.backend}}
93+
- run: ./test/ln_test.py --backend=${{matrix.backend}}
9494
build:
9595
needs: [scenarios, rpc, graph, ln] # Only run if the others complete successfully as it's slow
9696
runs-on: ubuntu-latest
@@ -112,4 +112,4 @@ jobs:
112112
just start
113113
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
114114
kubectl port-forward svc/rpc 9276:9276 &
115-
- run: ./test/build_branch_test.py ${{matrix.backend}}
115+
- run: ./test/build_branch_test.py --backend=${{matrix.backend}}

src/warnet/server.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def setup_rpc(self):
169169
# Logs
170170
self.jsonrpc.register(self.logs_grep)
171171

172-
def get_warnet(self, network: str) -> Warnet:
172+
def get_warnet(self, network: str = "warnet") -> Warnet:
173173
"""
174174
Will get a warnet from the cache if it exists.
175175
Otherwise it will create the network using from_network() and save it
@@ -268,7 +268,7 @@ def tank_messages(self, network: str, node_a: int, node_b: int) -> str:
268268
self.logger.error(msg)
269269
raise ServerError(message=msg) from e
270270

271-
def network_export(self, network: str) -> str:
271+
def network_export(self, network: str = "warnet") -> str:
272272
"""
273273
Export all data for sim-ln to subdirectory
274274
"""
@@ -283,7 +283,7 @@ def network_export(self, network: str) -> str:
283283
self.logger.error(msg)
284284
raise ServerError(message=msg) from e
285285

286-
def scenarios_available(self, network: str) -> list[tuple]:
286+
def scenarios_available(self, network: str = "warnet") -> list[tuple]:
287287
"""
288288
List available scenarios in the Warnet Test Framework
289289
"""
@@ -415,7 +415,7 @@ def scenarios_stop(self, pid: int, network: str = "warnet") -> str:
415415
self.logger.error(msg)
416416
raise ServerError(message=msg)
417417

418-
def scenarios_list_running(self, network: str) -> list[dict]:
418+
def scenarios_list_running(self, network: str = "warnet") -> list[dict]:
419419
running = [
420420
{
421421
"pid": sc["pid"],

test/rpc_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python3
2-
32
import os
43
from pathlib import Path
54

65
from test_base import TestBase
76

87
graph_file_path = Path(os.path.dirname(__file__)) / "data" / "v25_x_12.graphml"
98

9+
1010
base = TestBase()
1111
base.start_server()
1212
print(base.warcli(f"network start {graph_file_path}"))

test/test_base.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import atexit
23
import os
34
import sys
@@ -11,6 +12,11 @@
1112
from warnet.utils import exponential_backoff
1213
from warnet.warnet import Warnet
1314

15+
parser = argparse.ArgumentParser(description="TestBase args")
16+
parser.add_argument("--backend", type=str, default="compose", help="Use compose or k8s backend")
17+
parser.add_argument("--rust_cli", action="store_true", help="Use experimental Rust CLI")
18+
args = parser.parse_args()
19+
1420

1521
class TestBase:
1622
def __init__(self):
@@ -31,15 +37,11 @@ def __init__(self):
3137
self.server_thread = None
3238
self.stop_threads = threading.Event()
3339
self.network = True
40+
self.rust_cli = args.rust_cli
3441

3542
atexit.register(self.cleanup)
3643

37-
# Default backend
38-
self.backend = "compose"
39-
# CLI arg overrides env
40-
if len(sys.argv) > 1:
41-
self.backend = sys.argv[1]
42-
44+
self.backend = args.backend
4345
if self.backend not in ["compose", "k8s"]:
4446
print(f"Invalid backend {self.backend}")
4547
sys.exit(1)
@@ -78,9 +80,13 @@ def cleanup(self, signum=None, frame=None):
7880

7981
# Execute a warcli RPC using command line (always returns string)
8082
def warcli(self, str, network=True):
81-
cmd = ["warcli"] + str.split()
82-
if network:
83-
cmd += ["--network", self.network_name]
83+
if not self.rust_cli:
84+
print("Not using rust cli")
85+
cmd = ["warcli"] + str.split()
86+
if network:
87+
cmd += ["--network", self.network_name]
88+
else:
89+
cmd = ["target/debug/warcli"] + str.split()
8490
proc = run(cmd, capture_output=True)
8591

8692
if proc.stderr:

0 commit comments

Comments
 (0)