Skip to content

Commit

Permalink
fixed the generator test
Browse files Browse the repository at this point in the history
  • Loading branch information
chandralegend committed Mar 25, 2024
1 parent a527d2a commit 7fffd52
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/components/utils.jac
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ glob OLLAMA_SERVER_URL = os.environ.get("OLLAMA_SERVER_URL","http://localhost:11
can call_action(action:str, **kwargs: dict) -> dict {
url = f"{ACTION_SERVER_URL}{action}";
response = requests.post(url, json=kwargs);
print(response);
return response.json();
}

Expand Down
99 changes: 34 additions & 65 deletions src/tests/test_dashboard.jac
Original file line number Diff line number Diff line change
Expand Up @@ -8,132 +8,101 @@ import:py from pathlib, Path;

glob app = AppTest.from_file("app.py").run(timeout=20);


test app_running {
:g: app;
test app_running {
:g: app ;

assert not app.exception;
human_eval = Path(os.path.abspath(".human_eval_config"));
results = Path(os.path.abspath("results"));
if human_eval.exists(){shutil.rmtree(human_eval);}
if results.exists(){shutil.rmtree(results);}
if human_eval.exists() {
shutil.rmtree(human_eval);
}
if results.exists() {
shutil.rmtree(results);
}
}

test test_initialization_and_config_loading {
"""Tests initialization and configuration loading.""";
test test_initialization_and_config_loading {
"""Tests initialization and configuration loading.""";
app = AppTest.from_file("app.py").run(timeout=20);
app.session_state.admin_privileges = True;
assert (
"current_hv_config not found in session_state."
), app.session_state.current_hv_config;
assert ("current_hv_config not found in session_state.") , app.session_state.current_hv_config;
assert not app.exception;
assert not os.path.exists(os.path.join(".human_eval_config", "config.json"));
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), "."
);
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), ".");
app = AppTest.from_file("app.py").run(timeout=20);
app.session_state.admin_privileges = True;
app.run();
assert app.session_state.current_hv_config;
shutil.rmtree(".human_eval_config");
}

test test_error_validation {
"""Tests if appropriate error messages are displayed for missing configuration and results.""";
test test_error_validation {
"""Tests if appropriate error messages are displayed for missing configuration and results.""";
app = AppTest.from_file("app.py").run(timeout=20);
app.session_state.admin_privileges = True;
app.run();

dashboard_tab = get_item_by_label(app, "tab", "Dashboard");

# Assert error messages for missing configuration and results
assert (
dashboard_tab.error[0].value
== "Human Evaluation config was not found. Initialize a Human Evaluation first."
);
assert (
dashboard_tab.error[1].value
== "Results were not found. Initialize a Human Evaluation first. If Initiated already, wait until the results are ready."
);
assert (dashboard_tab.error[0].value == "Human Evaluation config was not found. Initialize a Human Evaluation first.");
assert (dashboard_tab.error[1].value == "Results were not found. Initialize a Human Evaluation first. If Initiated already, wait until the results are ready.");
}

test test_upload_functionality {
"""Tests basic upload functionality (placeholder for specific assertions).""";
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), "."
);
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), "."
);
test test_upload_functionality {
"""Tests basic upload functionality (placeholder for specific assertions).""";
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), ".");
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), ".");
app = AppTest.from_file("app.py").run(timeout=20);
admin_tab = get_item_by_label(app, "tab", "Admin Panel");
os.environ["SLAM_ADMIN_USERNAME"] = "admin";
os.environ["SLAM_ADMIN_PASSWORD"] = "admin";

admin_tab.text_input("username").input("admin");
admin_tab.text_input("password").input("admin");
admin_tab.get("button")[0].set_value(True).run(timeout=6);
dashboard_tab = get_item_by_label(app, "tab", "Dashboard");
dashboard_tab.button[0].click().run();
dashboard_tab = get_item_by_label(app, "tab", "Dashboard");
selectbox = (
get_item_by_label(app, "selectbox", "Select a chart type:")
.set_value("Stacked Bar Chart")
.run()
);
selectbox = (get_item_by_label(app, "selectbox", "Select a chart type:").set_value("Stacked Bar Chart").run());

# print(dashboard_tab);
assert len(selectbox.session_state.hv_results_files) > 0;
shutil.rmtree(".human_eval_config");
shutil.rmtree("results");
}

test test_chart_type_selection {
"""Tests basic upload functionality (placeholder for specific assertions).""";
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), "."
);
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), "."
);
test test_chart_type_selection {
"""Tests basic upload functionality (placeholder for specific assertions).""";
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), ".");
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), ".");
app = AppTest.from_file("app.py").run(timeout=20);
admin_tab = get_item_by_label(app, "tab", "Admin Panel");
os.environ["SLAM_ADMIN_USERNAME"] = "admin";
os.environ["SLAM_ADMIN_PASSWORD"] = "admin";

admin_tab.text_input("username").input("admin");
admin_tab.text_input("password").input("admin");
admin_tab.get("button")[0].set_value(True).run(timeout=6);
dashboard_tab = get_item_by_label(app, "tab", "Dashboard");
dashboard_tab.button[0].click().run();
dashboard_tab = get_item_by_label(app, "tab", "Dashboard");
selectbox = (
get_item_by_label(dashboard_tab, "selectbox", "Select a chart type:")
.set_value("Stacked Bar Chart")
.run()
);
assert get_item_by_label(
selectbox, "selectbox", "Select a chart type:"
).value == "Stacked Bar Chart";
selectbox = (get_item_by_label(dashboard_tab, "selectbox", "Select a chart type:").set_value("Stacked Bar Chart").run());
assert get_item_by_label(selectbox, "selectbox", "Select a chart type:").value == "Stacked Bar Chart";
shutil.rmtree(".human_eval_config");
shutil.rmtree("results");
}

test test_refresh_button {
test test_refresh_button {
app = AppTest.from_file("app.py").run(timeout=20);
app.session_state.admin_privileges = True;
app.run();
dashboard_tab = get_item_by_label(app, "tab", "Dashboard");
assert dashboard_tab.error;
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), "."
);
shutil.unpack_archive(
os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), "."
);
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "config.zip"), ".");
shutil.unpack_archive(os.path.join(os.path.dirname(__file__), "fixtures", "results.zip"), ".");
app = AppTest.from_file("app.py").run(timeout=20);
admin_tab = get_item_by_label(app, "tab", "Admin Panel");
os.environ["SLAM_ADMIN_USERNAME"] = "admin";
os.environ["SLAM_ADMIN_PASSWORD"] = "admin";

admin_tab.text_input("username").input("admin");
admin_tab.text_input("password").input("admin");
admin_tab.get("button")[0].set_value(True).run(timeout=6);
Expand All @@ -142,4 +111,4 @@ test test_refresh_button {
assert not dashboard_tab.error;
shutil.rmtree(".human_eval_config");
shutil.rmtree("results");
}
}
16 changes: 14 additions & 2 deletions src/tests/test_generator.jac
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@ test app_running {
}

test run_query_engine {
:g: query_engine;
query_engine = subprocess.Popen(["jac", "run", "src/query_engine.jac"]);
time.sleep(10);
response = requests.get("http://localhost:8000");
assert response.status_code == 200;
assert response.json() == {"status": "ok"};
}

test run_ollama_server {
:g: ollama_server;
ollama_server = subprocess.Popen(["ollama", "serve"]);
time.sleep(10);
response = requests.get("http://localhost:11434");
assert response.status_code == 200;
}

test generator {
assert not app.exception;
app.session_state.admin_privileges = True;
app.run();
assert app.session_state.engine_status;

generator_tab = get_item_by_label(app, "tab", "Response Generator");
get_item_by_label(generator_tab, "multiselect", "Select Models").set_value(['openai/gpt-4']).run();
get_item_by_label(generator_tab, "multiselect", "Select Models").set_value(['ollama/orca-mini:3b']).run();
get_item_by_label(generator_tab, "number_input", "Number of Samples").set_value(2).run();
get_item_by_label(generator_tab, "number_input", "Temperature").set_value(0.0).run();
get_item_by_label(generator_tab, "text_area", "Input Prompt Template").set_value("What is the meaning of {thing}?").run();
Expand All @@ -37,7 +46,10 @@ test generator {
assert not generator_tab.error;
get_item_by_label(generator_tab, "button", "Generate Responses").set_value(True).run();

assert os.path.exists(os.path.join("runs", app.session_state.run_id, "gpt-4.json"));
assert os.path.exists(os.path.join("runs", app.session_state.run_id, "orca-mini:3b.json"));
assert os.path.exists(os.path.join("data", f"{app.session_state.run_id}_responses.json"));

query_engine.terminate();
ollama_server.terminate();
}

0 comments on commit 7fffd52

Please sign in to comment.