Skip to content

Commit 9dfc62a

Browse files
committed
Make test dir and class skel location configurable
1 parent 386062d commit 9dfc62a

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

main.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
from langroid.utils.configuration import set_global, Settings
66
from langroid.utils.logging import setup_colored_logging
77

8-
from TestRunner.GenericTestRunner import InlineTestRunner
8+
from TestRunner.GenericTestRunner import GenericTestRunner, InlineTestRunner, SubProcessTestRunner
99

1010
app = typer.Typer()
1111
setup_colored_logging()
1212

1313

14-
def generate_first_attempt() -> None:
15-
# code_prompt = typer.Prompt("Describe what kind of code you want.")
16-
# class_skeleton: str = ""
17-
with open(os.path.join(".", "assets", "test_class.py"), "r") as f:
14+
def generate_first_attempt(class_skeleton: str) -> None:
15+
with open(class_skeleton, "r") as f:
1816
class_skeleton = f.read()
1917

2018
cfg = lr.ChatAgentConfig(
@@ -79,25 +77,34 @@ def teardown() -> None:
7977
generated_file.truncate(0)
8078

8179

82-
def chat() -> None:
83-
generate_first_attempt()
84-
test_runner = InlineTestRunner("", os.path.join(".", "test"))
85-
for _ in range(5):
80+
def chat(class_skeleton: str, test_dir: str, test_runner: GenericTestRunner, max_epochs: int=5) -> None:
81+
generate_first_attempt(class_skeleton)
82+
solved = False
83+
for _ in range(max_epochs):
8684
# test_exit_code, test_results = get_test_results()
8785
test_exit_code, test_results = test_runner.run()
8886
print(test_results)
89-
if test_exit_code == 1:
87+
if test_exit_code == 0:
88+
solved = True
89+
print("Done!")
90+
break
91+
elif test_exit_code == 1:
9092
generate_next_attempt(test_results)
9193
else:
94+
solved = True
95+
print("There is some problem with the test suite itself.")
9296
break
9397
teardown()
94-
print("Done! All tests are passing, or there is some problem with the test suite itself.")
98+
if not solved:
99+
print(f"Reached the end of epoch {max_epochs} without finding a solution :(")
95100

96101
@app.command()
97102
def main(
98103
debug: bool = typer.Option(False, "--debug", "-d", help="debug mode"),
99104
no_stream: bool = typer.Option(False, "--nostream", "-ns", help="no streaming"),
100105
nocache: bool = typer.Option(False, "--nocache", "-nc", help="don't use cache"),
106+
class_skeleton: str = typer.Option(None, "--class-skeleton", "-c", help="You must provide a class skeleton."),
107+
test_dir: str = typer.Option(os.path.join(".", "test"), "--test-dir", "-t", help=""),
101108
) -> None:
102109
set_global(
103110
Settings(
@@ -106,7 +113,15 @@ def main(
106113
stream=not no_stream,
107114
)
108115
)
109-
chat()
116+
assert os.path.isfile(class_skeleton), f"The class skeleton file provided does not exist! Got {class_skeleton}"
117+
assert os.path.exists(test_dir), f"The test-dir provided does not exist! Got {test_dir}"
118+
119+
tr: GenericTestRunner = InlineTestRunner("", test_dir)
120+
chat(
121+
class_skeleton=class_skeleton,
122+
test_dir=test_dir,
123+
test_runner=tr
124+
)
110125

111126

112127
if __name__ == "__main__":

0 commit comments

Comments
 (0)