forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/oai endpoints mapper using JSON (janhq#2929)
* feat: test mapper * chore: temporally add other runner * chore: temp remove ubuntu-18-04-openai-api-collection-test * chore: test json file * chore: test json file * Correct path endpoints_mapping.json * feat: running via endpoints * feat: running multiple endpoint * feat: use endpoint value from workflow dispatch * feat: add mapper between endpoint and python test file * feat: config run all * feat: config run all --------- Co-authored-by: Van-QA <[email protected]> Co-authored-by: Hien To <[email protected]>
- Loading branch information
1 parent
65b8d8e
commit ae499c7
Showing
3 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
import json | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--endpoint", action="store", default="all", help="my option: endpoints" | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
config.addinivalue_line( | ||
"markers", "endpoint(endpoint): this mark select the test based on endpoint" | ||
) | ||
|
||
|
||
def pytest_runtest_setup(item): | ||
getoption = item.config.getoption("--endpoint").split(",") | ||
if getoption not in (["all"], [''], [""]): | ||
endpoint_names = [mark.args[0] for mark in item.iter_markers(name="endpoint")] | ||
if not endpoint_names or not set(getoption).intersection(set(endpoint_names)): | ||
pytest.skip("Test skipped because endpoint is {!r}".format(endpoint_names)) | ||
|
||
|
||
def pytest_collection_modifyitems(items): | ||
# load the JSON file | ||
with open("tests/endpoints_mapping.json", "r") as json_file: | ||
endpoints_file_mapping = json.load(json_file) | ||
|
||
# create a dictionary to map filenames to endpoints | ||
filename_to_endpoint = {} | ||
for endpoint, files in endpoints_file_mapping.items(): | ||
for filename in files: | ||
filename_to_endpoint[filename] = endpoint | ||
|
||
# add the markers based on the JSON file | ||
for item in items: | ||
# add the name of the file (without extension) as a marker | ||
filename = item.nodeid.split("::")[0].split("/")[-1].replace(".py", "") | ||
marker = pytest.mark.file(filename) | ||
item.add_marker(marker) | ||
# map the name of the file to endpoint, else use default value | ||
filename = item.fspath.basename | ||
marker = filename_to_endpoint.get(filename, filename) | ||
item.add_marker(pytest.mark.endpoint(marker, filename=filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"/embeddings": [ | ||
"test_embedding.py" | ||
], | ||
"/audio/translations": [ | ||
"test_translations.py" | ||
], | ||
"/audio/transcriptions": [ | ||
"test_transcriptions.py" | ||
], | ||
"/moderations": [ | ||
"test_moderations.py" | ||
], | ||
"/images/generations": [ | ||
"test_images.py" | ||
], | ||
"/batches": [ | ||
"test_batches.py" | ||
], | ||
"/vector_stores": [ | ||
"test_vector_stores.py" | ||
], | ||
"/fine_tuning/jobs": [ | ||
"test_jobs.py", | ||
"test_checkpoints.py" | ||
], | ||
"/assistants": [ | ||
"test_assistants.py" | ||
], | ||
"/threads/{thread_id}/runs": [ | ||
"test_runs.py" | ||
], | ||
"/threads/{thread_id}/runs/{run_id}/steps": [ | ||
"test_steps.py" | ||
], | ||
"/vector_stores/{vector_store_id}/file_batches": [ | ||
"test_file_batches.py" | ||
], | ||
"/messages": [ | ||
"test_messages.py" | ||
], | ||
"/vector_stores/{vector_store_id}/files": [ | ||
"test_files.py" | ||
], | ||
"/chat/completions": [ | ||
"test_completions.py" | ||
], | ||
"/threads": [ | ||
"test_threads.py" | ||
], | ||
"/audio/speech": [ | ||
"test_speech.py" | ||
], | ||
"/models": [ | ||
"test_models.py" | ||
], | ||
"native_client_sdk_only": [ | ||
"test_streaming.py" | ||
], | ||
"utils": [ | ||
"test_response.py", | ||
"test_client.py", | ||
"test_extract_files.py", | ||
"test_typing.py", | ||
"test_legacy_response.py", | ||
"test_module_client.py", | ||
"test_old_api.py", | ||
"test_proxy.py", | ||
"test_qs.py", | ||
"test_required_args.py", | ||
"test_transform.py", | ||
"test_azure.py", | ||
"test_deepcopy.py" | ||
] | ||
} |