Skip to content

Commit

Permalink
revert test_engine for run through windows test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyongchao committed Nov 25, 2024
1 parent 7942533 commit 6701dd8
Showing 1 changed file with 13 additions and 67 deletions.
80 changes: 13 additions & 67 deletions tests/basic_tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ async def get_last_report():
else:
return {{}}
@app.get("/get_all_reports")
async def get_all_reports():
if len(received_datas) > 0:
return list(received_datas)
else:
return []
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port={port})
Expand All @@ -63,7 +56,6 @@ def setUpClass(cls):
ip_address = socket.gethostbyname(hostname)
cls.report_url = f"http://{ip_address}:{HOOK_PORT}/{HOOK_ROUTE}"
cls.get_url = f"http://{ip_address}:{HOOK_PORT}/get_last_report"
cls.get_all_url = f"http://{ip_address}:{HOOK_PORT}/get_all_reports"

def read_stdout(process):
for line in iter(process.stdout.readline, b''):
Expand All @@ -81,23 +73,14 @@ def tearDownClass(cls):
cls.fastapi_process.terminate()
cls.fastapi_process.wait()

def get_report(self, only_last=True):
if only_last:
r = requests.get(self.get_url)
json_obj = {}
try:
json_obj = json.loads(r.content)
except Exception as e:
lazyllm.LOG.warning(str(e))
return json_obj
else:
r = requests.get(self.get_all_url)
json_obj = []
try:
json_obj = json.loads(r.content)
except Exception as e:
lazyllm.LOG.warning(str(e))
return json_obj
def get_last_report(self):
r = requests.get(self.get_url)
json_obj = {}
try:
json_obj = json.loads(r.content)
except Exception as e:
lazyllm.LOG.warning(str(e))
return json_obj

@pytest.fixture(autouse=True)
def run_around_tests(self):
Expand Down Expand Up @@ -129,43 +112,6 @@ def test_engine_code(self):
assert engine.run(gid, 1) == 2
assert engine.run(gid, 2) == 4

def test_engine_hook_multi_share(self):
resources = [
dict(
id='publish-llm',
kind='LocalLLM',
name='publish-llm',
args=dict(base_model='', deploy_method='dummy'),
)
]
nodes = [
{
"id": "draft-1",
"kind": "SharedLLM",
"name": "1732431852399",
"args": {"llm": "publish-llm", "prompt": "", "_lazyllm_enable_report": True},
},
{
"id": "draft-2",
"kind": "SharedLLM",
"name": "1732437478030",
"args": {"llm": "publish-llm", "_lazyllm_enable_report": True},
},
]
edges = [
{"iid": "__start__", "oid": "draft-1"},
{"iid": "draft-1", "oid": "__end__"},
{"iid": "__start__", "oid": "draft-2"},
{"iid": "draft-2", "oid": "__end__"},
]
engine = LightEngine()
engine.set_report_url(self.report_url)
gid = engine.start(nodes, edges, resources)
old_reports = self.get_report(only_last=False)
engine.run(gid, "你好")
new_reports = self.get_report(only_last=False)
assert len(new_reports) - len(old_reports) == 2

def test_engine_switch(self):
plus1 = dict(id='1', kind='Code', name='m1', args=dict(code='def test(x: int):\n return 1 + x\n'))
double = dict(id='2', kind='Code', name='m2', args=dict(code='def test(x: int):\n return 2 * x\n'))
Expand Down Expand Up @@ -209,7 +155,7 @@ def test_engine_switch(self):
assert engine.run(gid, 'case1', 2) == 4
assert engine.run(gid, 'case2', 2) == 6
assert engine.run(gid, 'case3', 3) == 9
assert "prompt_tokens" in self.get_report()
assert "prompt_tokens" in self.get_last_report()

def test_engine_ifs(self):
plus1 = dict(id='1', kind='Code', name='m1', args=dict(code='def test(x: int):\n return 1 + x\n'))
Expand All @@ -234,7 +180,7 @@ def test_engine_ifs(self):
assert engine.run(gid, 1) == 4
assert engine.run(gid, 5) == 12
assert engine.run(gid, 10) == 100
assert "prompt_tokens" in self.get_report()
assert "prompt_tokens" in self.get_last_report()

def test_data_reflow_in_server(self):
nodes = [
Expand Down Expand Up @@ -296,7 +242,7 @@ def test_data_reflow_in_server(self):
engine.set_report_url(self.report_url)
gid = engine.start(nodes, edges, resources)
assert engine.run(gid, 1) == 7
assert "prompt_tokens" in self.get_report()
assert "prompt_tokens" in self.get_last_report()

def test_engine_loop(self):
nodes = [dict(id='1', kind='Code', name='code', args=dict(code='def square(x: int): return x * x'))]
Expand All @@ -321,7 +267,7 @@ def test_engine_loop(self):
engine.set_report_url(self.report_url)
gid = engine.start(nodes, edges)
assert engine.run(gid, 2) == 16
assert "prompt_tokens" in self.get_report()
assert "prompt_tokens" in self.get_last_report()

def test_engine_warp(self):
nodes = [dict(id='1', kind='Code', name='code', args=dict(code='def square(x: int): return x * x'))]
Expand All @@ -345,7 +291,7 @@ def test_engine_warp(self):
engine.set_report_url(self.report_url)
gid = engine.start(nodes, edges)
assert engine.run(gid, 2, 3, 4, 5) == (4, 9, 16, 25)
assert "prompt_tokens" in self.get_report()
assert "prompt_tokens" in self.get_last_report()

def test_engine_formatter(self):
nodes = [dict(id='1', kind='Formatter', name='f1', args=dict(ftype='python', rule='[:]'))]
Expand Down

0 comments on commit 6701dd8

Please sign in to comment.