Skip to content

Commit

Permalink
add --skip and --only to test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Apr 12, 2024
1 parent df5a541 commit 7ec0488
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
41 changes: 37 additions & 4 deletions controllers/pyctrl/driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import re
import argparse

import pyaici.rest
import pyaici.util
Expand Down Expand Up @@ -51,10 +52,38 @@ def main():
js_mode = False
cmt = "#"

files = sys.argv[1:]
if not files:
print("need some python files as input")
return
parser = argparse.ArgumentParser(
description="Run pyctrl or jsctrl tests",
prog="ctrldriver",
)

parser.add_argument(
"--skip",
"-s",
type=str,
default=[],
action="append",
help="skip tests matching string",
)

parser.add_argument(
"--only",
"-k",
type=str,
default=[],
action="append",
help="only run tests matching string",
)

parser.add_argument(
"test_file",
nargs="+",
help="files to test",
)

args = parser.parse_args()

files = args.test_file

if files[0].endswith(".js"):
js_mode = True
Expand All @@ -77,6 +106,10 @@ def main():
else:
tests = re.findall(r"^async def (test_\w+)\(.*", arg, flags=re.MULTILINE)
for t in tests:
if any([s in t for s in args.skip]):
continue
if args.only and not any([s in t for s in args.only]):
continue
if js_mode:
arg_t = f"{arg}\ntest({t});\n"
else:
Expand Down
7 changes: 4 additions & 3 deletions controllers/pyctrl/samples/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ async def test_hello():
prompt = await aici.GetPrompt()
print("prompt", prompt)
await aici.gen_tokens(regex=r"[A-Z].*", max_tokens=5)
await aici.FixedTokens("\n2 +")
l = aici.Label()
await aici.FixedTokens("\n2 + 2 = ")
await aici.FixedTokens(" 2 = ")
await aici.gen_tokens(regex=r"\d+", max_tokens=1)
await aici.FixedTokens("\n3 + 3 = ", following=l)
await aici.FixedTokens(" 3 = ", following=l)
await aici.gen_tokens(regex=r"\d+", max_tokens=1)


Expand Down Expand Up @@ -187,4 +188,4 @@ async def test_joke():
await aici.gen_text(max_tokens=15)


aici.test(test_hello())
aici.test(test_drugs())
2 changes: 1 addition & 1 deletion scripts/test-jsctrl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cd $HERE/../controllers/jsctrl
tsc --version || npm install -g typescript
tsc -p samples
PYTHONPATH=$HERE/../py \
python3 ../pyctrl/driver.py samples/dist/test.js
python3 ../pyctrl/driver.py samples/dist/test.js "$@"
2 changes: 1 addition & 1 deletion scripts/test-pyctrl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cd `dirname $0`
HERE=`pwd`
cd $HERE/../controllers/pyctrl
PYTHONPATH=$HERE/../py \
python3 driver.py samples/test*.py
python3 driver.py samples/test*.py "$@"

0 comments on commit 7ec0488

Please sign in to comment.