mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
* fix(openrouter): list OpenRouter's live catalog for openrouter/* when check_provider_endpoint is on
* fix(openrouter): list models off the event loop and keep only chat-callable catalog ids
The model-list builders are sync, and with check_provider_endpoint on they call OpenRouter's catalog with a 10 second timeout and no caching of failures. They ran on the event loop inside /v1/models, /model/info, /model_group/info and the per-user listing, so one slow catalog froze every request on the worker. Those calls now run in a worker thread with asyncio.to_thread
File, batch and RAG credential lookups only need each name's deployment, and a wildcard that is itself a deployment sits in the list ahead of its expansions and resolves its own credentials. get_complete_model_list takes expand_deployed_wildcard_routes, which that lookup sets to False, so a deployed wildcard never fetches its provider catalog there. A key wildcard wider than any deployment, like anthropic/* over a deployed anthropic/claude-*, still expands so it finds the matching deployment's credentials. Every other caller keeps the default
The pattern router's model lookup tolerates a pattern removed between its two reads of the pattern table, which a deployment delete on the event loop can now do while a listing runs in a thread
Listing now reads only OpenRouter's models/user catalog. OpenRouter's own /models list carries no embedding models, the OpenAI-format /v1/models has no mode field so chat pickers cannot tell embeddings apart, /model_group/info labels them mode chat, and one failing catalog emptied the whole list. Ids ending in :batch are dropped because chat completions answers 404 for them, while :free and every other variant stay. An api_base that already ends in /chat/completions, which chat accepts as is, has that suffix stripped before the catalog route is joined
* fix(proxy): keep model listing off the shared thread pool and out of credential lookups
Listings run on their own thread pool so many slow catalogs cannot starve
the default executor that chat and Responses calls share. File and batch
credential lookups match deployed names against a key's wildcard grants
instead of listing any provider catalog. The token counter keeps OpenRouter
deployments on their previous path, and a catch-all "*" over provider/*
lists bare ids that route back through it
* test(proxy): give the off-loop listing tests a generous deadlock guard and typed ids
* fix(proxy): keep routed models in wildcard model info, skip key-only OpenRouter catalogs, cache failed listings briefly
* fix(utils): cache failed model listings under their own key so a late failure never hides a good listing
* fix(proxy): remember only timed-out provider listings so a provider that failed fast is listed again
* fix(proxy): ask each provider catalog once per worker, keep deployed names out of catch-all ids, and match file credentials by name
Listings that start together for one deployment now wait for the first catalog request. A catch-all wildcard no longer lists a name a deployment serves by name. A key wildcard only finds file and batch credentials on deployments named under it, so a bare name keeps the default credentials as before.
* fix(proxy): keep the listing failure log line the same for timed-out listings
* refactor(proxy): fold the cached listing lookup back into the provider listing function
* fix(proxy): list each model id once and keep a named deployment's row over a wildcard's
* fix(openrouter): show published limits on the proxy model-info routes
An OpenRouter model with no cost-map row showed a null context window and
output cap on /v1/model/info and /model_group/info, so lite pi fell back to
128k. The model-info refresh now reads OpenRouter's /models/user catalog, keeps
one shared catalog per wildcard deployment, and looks up each concrete model on
read, with no new call on the request path. Operator model_info still wins, and
catalog values win over a cost-map row. Wildcard rows on /v1/models show the
same limits, since the lite OpenCode and Codex model sync reads them there
* fix(proxy): drop a wildcard's model info row when named deployments serve every name it lists
* fix(openrouter): keep /v1/models cheap when no wildcard catalog is cached
* test(router): list the OpenRouter discovery helpers in the router coverage gate
* fix(openrouter): keep catalog limits through outages, scope the env key, share one fetch per key
A failed catalog fetch now keeps the last published limits instead of
dropping them after the cache entry ages out, and a model the catalog no
longer lists loses its limits on the next good refresh.
The proxy-wide OpenRouter key goes only to openrouter.ai. A deployment
with its own api_base on another host sends only its own key.
Overlapping refreshes on one key share a single catalog download.
A team-owned openrouter/* wildcard now shows each model's catalog limits
on /v1/models, and the wildcard-catalog flag resets when the model list
is replaced
* fix(openrouter): scope wildcard listing limits to the caller's team, read wildcard catalog rows at request time
* fix(openrouter): keep discovered limits out of model saves, send the shared key only to openrouter.ai, list only routable wildcard names
A model saved from the Admin UI echoes the limits /model/info showed, and PATCH /model/{id}/update stored them
as overrides, so the model stopped following its backend. Limits equal to the discovered ones are now display
values on both update routes. The catalog request now picks its key from the host it actually calls, so a global
api_base never gets the proxy-wide OpenRouter key. Wildcard listing resolves names the way requests route, and a
refresh clears the group caches once at its end
* fix(router): keep a deployment's discovered limits when an edit leaves its backend alone
Saving a model in the UI replaced the deployment, and the discovered limits
only matched the old deployment object, so the model info routes showed no
limits until the next refresh, up to 5 minutes later. An edit that changes
only tpm, rpm, max_parallel_requests or token prices now carries the
discovered limits to the new deployment. Any other change still waits for
the refresh, so a new api_base or key never shows the old backend's limits
* fix(router): keep other deployments' discovered limits when a save carries one over
The discovered-limits cache holds one entry per deployment, so writing the carried entry over a full cache evicted another deployment's limits first. Delete the edited entry before writing it, as the refresh path does
* test(router): pin that discovered limits outlive only a same-backend replacement
Main's test pinned that any replacement forgets discovered limits. A replacement that changes only rpm now keeps them, and one that points at another api_base still forgets them
* fix(openrouter): keep typed limits, show new models' limits at once, scope team wildcards
A request that types a limit equal to the discovered one is stored again, since only
a /model/info row carrying its key reads as an echo. Wildcard rows now carry their
routed model as key, so echoing one back no longer pins its limits on the wildcard.
A model added through the API, a DB sync or a read-through starts a model info refresh,
so its backend limits show right away instead of after up to 5 minutes.
A team wildcard under the public openrouter/* name lists its catalog limits only to its
team. Regional openrouter.ai hosts get the proxy-wide key for the catalog. Cached limits
are a frozen pydantic model, so the in-memory cache debug route encodes them again, and
fetch locks are kept per event loop.
---------
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
265 lines
20 KiB
Python
265 lines
20 KiB
Python
import ast
|
|
import os
|
|
|
|
|
|
def get_function_names_from_file(file_path):
|
|
"""
|
|
Extracts all function names from a given Python file.
|
|
"""
|
|
with open(file_path, "r", encoding="utf-8") as file:
|
|
tree = ast.parse(file.read())
|
|
|
|
function_names = []
|
|
|
|
for node in tree.body:
|
|
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
# Top-level functions
|
|
function_names.append(node.name)
|
|
elif isinstance(node, ast.ClassDef):
|
|
# Functions inside classes
|
|
for class_node in node.body:
|
|
if isinstance(class_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
function_names.append(class_node.name)
|
|
|
|
return function_names
|
|
|
|
|
|
def get_all_functions_called_in_tests(base_dir):
|
|
"""
|
|
Returns a set of function names that are called in test functions
|
|
inside the unit test directories,
|
|
specifically in files containing the word 'router'.
|
|
"""
|
|
called_functions = set()
|
|
test_dirs = ["unit"]
|
|
|
|
for test_dir in test_dirs:
|
|
dir_path = os.path.join(base_dir, test_dir)
|
|
if not os.path.exists(dir_path):
|
|
print(f"Warning: Directory {dir_path} does not exist.")
|
|
continue
|
|
|
|
print("dir_path: ", dir_path)
|
|
for root, _, files in os.walk(dir_path):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
if file.endswith(".py") and (
|
|
"router" in os.path.relpath(file_path, dir_path).lower() or test_dir == "unit"
|
|
):
|
|
print("file: ", file)
|
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
try:
|
|
tree = ast.parse(f.read())
|
|
except SyntaxError:
|
|
print(f"Warning: Syntax error in file {file_path}")
|
|
continue
|
|
if file == "test_router_validate_fallbacks.py":
|
|
print(f"tree: {tree}")
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
called_functions.add(node.func.id)
|
|
elif isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
|
|
called_functions.add(node.func.attr)
|
|
|
|
return called_functions
|
|
|
|
|
|
def get_functions_from_router(file_path):
|
|
"""
|
|
Extracts all functions defined in router.py.
|
|
"""
|
|
return get_function_names_from_file(file_path)
|
|
|
|
|
|
ignored_function_names = [
|
|
"_acancel_batch",
|
|
"_acreate_batch",
|
|
"_acreate_file",
|
|
"__init__",
|
|
"_router_init", # Never run: it carries Router.__init__'s signature and docstring
|
|
"avector_store_create", # Tested via proxy vector_store_endpoints (files lack "router" in name)
|
|
"_override_vector_store_methods_for_router", # No-op placeholder, called during Router init
|
|
"_merge_tools_from_deployment", # Tested indirectly via _update_kwargs_with_deployment (test files lack "router" in name)
|
|
"_invalidate_access_groups_cache", # Tested indirectly via set_model_list, upsert_model etc. (test files lack "router" in name)
|
|
"has_buffered_provider_output", # Property, so its reads in test_router.py are never an ast.Call
|
|
"chunks", # Property on FallbackAwareAnthropicMessagesStream, so its reads in tests are never an ast.Call
|
|
"messages", # Property on FallbackAwareAnthropicMessagesStream, so its reads in tests are never an ast.Call
|
|
"model", # Property on FallbackAwareAnthropicMessagesStream, so its reads in tests are never an ast.Call
|
|
"_routing_groups", # Property getter and setter reads are never ast.Call nodes
|
|
"_request_header", # Tested through Claude Code session routing in test_router.py
|
|
"_claude_code_session_router_cache_key", # Tested through Claude Code session routing in test_router.py
|
|
"_delete_claude_code_session_router_binding", # Tested through Redis cleanup failure in test_router.py
|
|
"_resolve_claude_code_session_router", # Tested through Claude Code session routing in test_router.py
|
|
"_get_claude_code_session_router_binding", # Tested through the two-worker session routing test in test_router.py
|
|
"_apply_updated_routing_strategy_args", # Tested via update_settings in test_lowest_latency.py (file lacks "router" in name)
|
|
"_wait_for_scheduler_turn", # Tested through prioritized acompletion and atext_completion in test_router.py
|
|
"arm_routing_read_prefetch", # Tested in tests/unit/caching/test_request_redis_batch_pre_call.py (file lacks "router" in name)
|
|
"_deployment_params_base_model", # Tested through log_retry in test_router_helper_utils.py
|
|
"_configured_model_info", # Tested through get_configured_service_tiers in test_router.py
|
|
"_every_deployment_refused", # Tested through the unsupported transcription retry tests in test_router.py
|
|
"_routable_deployments", # Tested through get_configured_service_tiers and get_routable_upstream_model in test_router.py
|
|
"_async_get_available_deployment", # Body of the `route {model}` phase wrapper, exercised through async_get_available_deployment in test_router.py
|
|
"_async_get_available_deployment_for_pass_through", # Same, through async_get_available_deployment_for_pass_through in test_router.py
|
|
"_embedding",
|
|
"_aembedding",
|
|
"_stream_pre_content_error", # Tested through the non-retriable retry error tests in test_router.py
|
|
"_narrow_to_video_deployment", # Tested through video_status and avideo_status polls in test_router_provider_endpoints.py
|
|
"_video_call_pin", # Tested through the video_status pin tests and the chat video_id test in test_router_provider_endpoints.py
|
|
"_deployment_num_retries", # Tested through the deployment num_retries mid-stream budget test in test_router.py
|
|
"_request_fallback_list", # Tested through every mid-stream retry test in test_router.py
|
|
"_request_model_group", # Tested through test_anthropic_messages_retry_budget_precedence_direct_call
|
|
"_search_tool_support", # Tested through the test_get_search_tool_support_* tests
|
|
"_mid_stream_retry_trigger", # Tested through the retry policy mid-stream budget test in test_router.py
|
|
"_anthropic_messages_group_retry_policy", # Tested through the retry budget precedence test in test_router.py
|
|
"_anthropic_messages_resolved_retry_policy", # Tested through the malformed retry policy tests in test_router.py
|
|
"_anthropic_messages_plain_retry_budget", # Tested through the retry budget precedence test in test_router.py
|
|
"_stream_should_retry", # Tested through every mid-stream retry test in test_router.py
|
|
"_astream_retry_same_group", # Tested through the dropped-before-content retry tests in test_router.py
|
|
"_aanthropic_messages_yield_recovered", # Tested through every mid-stream retry and fallback test in test_router.py
|
|
"_anthropic_messages_policy_retries", # Tested through the retry budget precedence test in test_router.py
|
|
"_get_wildcard_deployments", # Tested through the get_model_list_of_routed_group wildcard test in test_router.py
|
|
"_prompt_management_acompletion", # Tested through the scheduled prompt-management model test in test_router.py
|
|
"_request_deployment_params", # Tested through the team-route and deployment-id drop_params priority tests in test_router.py
|
|
"split_request_priority", # Tested through the acompletion, atext_completion and queue route priority tests
|
|
"_pinned_deployment", # Tested through the deployment-id scheduler test in test_router.py
|
|
"_is_fallback_hop", # Tested through the order fallback hop tests in test_router_order_fallback.py
|
|
"_deployment_that_just_failed", # Tested through the same-boundary hop test in test_router_order_fallback.py
|
|
"_merged_tools", # Tested through the _update_kwargs_with_deployment tools merge tests in test_router.py
|
|
"_malformed_request_params_the_deployment_sets", # Run by _update_kwargs_with_deployment, tested through the drop_params deployment test in test_thought_signature_in_tool_call_id.py
|
|
"_drop_malformed_request_params_the_deployment_sets", # Run by _update_kwargs_with_deployment, tested through the drop_params deployment test in test_thought_signature_in_tool_call_id.py
|
|
"_drops_malformed_request_tools", # Tested through the _update_kwargs_with_deployment tools merge tests in test_router.py
|
|
"_collect_ptu_share_teams", # Cached behind team_ptu_ceiling, tested through the live model list test in test_router.py
|
|
"_resolve_team_ptu_ceiling", # Cached behind team_ptu_ceiling, tested through the live model list test in test_router.py
|
|
"_register_continuation_prefill_check", # Tested through the continuation tests in test_router.py
|
|
"_set_mid_stream_fallback_continuation", # Tested through the update_settings continuation test in test_router.py
|
|
"_is_flag_enabled", # Tested through the string-flag continuation tests in test_router.py
|
|
"_params_sent_to_deployment", # Tested through the configured-constraint continuation tests in test_router.py
|
|
"_names_deployment_that_cannot_continue", # Tested through the deployment-id continuation tests in test_router.py
|
|
"_set_retry_policy", # Tested through update_settings in test_router_retry_policy_update.py
|
|
"_resolve_pre_call_check_input_tokens", # Tested through the token-count failure pre-call check tests in test_router.py
|
|
"_params_neither_dropped_nor_allowed", # Tested through the allowed-or-dropped param pre-call check tests in test_router.py
|
|
"_deployment_rejects_params", # Tested through the unsupported-param pre-call check tests in test_router.py
|
|
"_cache_flags_left_to_the_catalog", # Tested through the wildcard prompt cache flag tests in test_anthropic_cache_control_hook.py
|
|
"_deployment_lacks_params", # Tested through the unsupported-param pre-call check tests in test_router.py
|
|
"_pre_call_check_requested_chat_params", # Tested through the unsupported-param pre-call check tests in test_router.py
|
|
"_deployment_supports_param", # Tested through the deployment-capability pre-call check tests in test_router.py
|
|
"_capability_model_and_provider", # Tested through the authenticating-provider pre-call check test in test_router.py
|
|
"_route_capability_pin", # Exercised through Decisions routing tests in test_router.py
|
|
"_deployment_serves_route", # Exercised through mixed-group Decisions tests in test_router.py
|
|
"_without_deployments_that_cannot_serve_route", # Exercised through Decisions routing tests in test_router.py
|
|
"_exact_base_model_max_input_tokens", # Tested through get_router_model_info in test_router_model_cost_isolation.py
|
|
"_base_model_widened_window", # Tested through get_router_model_info in test_router_model_cost_isolation.py
|
|
"_provider_model_id", # Tested through get_router_model_info in test_router_model_cost_isolation.py
|
|
"_names_route_model", # Tested through get_router_model_info in test_router_model_cost_isolation.py
|
|
"_declared_base_model", # Tested through get_router_model_info in test_router_model_cost_isolation.py
|
|
"async_admit_deployment_turn", # Bound as the WebSocket turn_admission partial, tested through it in test_router_helper_utils.py
|
|
"_deployment_as_configured_now", # Read by async_admit_deployment_turn, tested through turn_admission in test_router_helper_utils.py
|
|
"_admit_turn_through_routing_strategy", # Run by async_admit_deployment_turn, tested through turn_admission in test_router_helper_utils.py
|
|
"_callback_selectors", # Run by discard, tested through the discard tests in test_router_helper_utils.py
|
|
"bind_to_request_logging", # Run by the proxy user_config route, tested through the user_config tests in test_route_llm_request.py
|
|
"serve_through_request_logging", # Run by the proxy user_config route, tested through the user_config tests in test_route_llm_request.py
|
|
"_request_adaptive_router_hooks", # Run by serve_through_request_logging, tested through the user_config adaptive test
|
|
"_release_global_callbacks", # Run by discard, tested through the discard tests in test_router_helper_utils.py
|
|
"_routing_callbacks", # Read by the pre-call checks, tested through the user_config limit tests in test_route_llm_request.py
|
|
"_request_policies_not_set_globally", # Read by bind_to_request_logging, tested through the user_config budget test in test_route_llm_request.py
|
|
"_optional_loggers", # Read by discard and serve_through_request_logging, tested through the budget limiter discard test
|
|
"retire_routing_state", # Run by discard, tested through the budget limiter discard test
|
|
"_slack_alerting_loggers", # Run by discard, tested through the Slack alerting discard test in test_router_helper_utils.py
|
|
"_adaptive_router_hooks", # Run by discard, tested through the adaptive router discard tests in test_router_helper_utils.py
|
|
"_global_callback_candidates", # Run by discard, tested through the survivor discard tests in test_router_helper_utils.py
|
|
"without_deployments_that_cannot_batch", # Tested through the Azure and OpenAI mixed-group acreate_batch tests in test_router.py
|
|
"batch_create_routing", # Tested through the mixed-group acreate_batch tests in test_router.py
|
|
"is_batch_create_routing", # Tested through the chat-after-batch-create test in test_router.py
|
|
"is_batch_capable", # Tested through the mixed-group acreate_batch and model group info tests in test_router.py
|
|
"deployments_the_caller_may_use", # Tested through the usage-based-routing team batch create test in test_router.py
|
|
"deployment_supported_endpoints", # Tested through the model group info batch endpoint tests in test_router.py
|
|
"_endpoint_paths", # Read by deployment_supported_endpoints, tested through the malformed endpoint list group info test in test_router.py
|
|
"_deployment_field", # Read by is_batch_capable, tested through the mixed-group tests in test_router.py
|
|
"_deployment_provider", # Read by without_deployments_that_cannot_batch, tested through the mixed-group tests in test_router.py
|
|
"_cannot_run_batches", # Tested through the Azure and OpenAI mixed-group acreate_batch tests in test_router.py
|
|
"job_cost_of_poll", # Read by job_to_charge_once and charged_video_id, tested through the guardrail-priced poll tests in test_batch_utils.py
|
|
"charged_video_id", # Read by job_to_charge_once and get_spend_logs_id, tested through both in test_batch_utils.py and test_spend_tracking_utils.py
|
|
"_requested_video_id", # Read by charged_video_id, tested through the polled-id video test in test_batch_utils.py
|
|
"_guardrail_cost_of_poll", # Read by job_cost_of_poll and repeat_poll_cost, tested through the guardrail-priced poll tests
|
|
"repeat_poll_cost", # Read by job_to_charge_once and _charge_request_cost, tested through every limiter's guardrail poll test
|
|
"pays_only_its_guardrail", # Read by get_spend_logs_id, tested through its guardrail-only poll test in test_spend_tracking_utils.py
|
|
"charged_poll_cost", # Read by get_spend_logs_id, tested through the finished job guardrail poll tests in test_db_spend_update_writer.py
|
|
"_polled_batch", # Read by defers_batch_cost and _charged_batch, tested through the redacted batch retrieve tests
|
|
"_charged_batch", # Read by job_to_charge_once, tested through the batch charge identity tests in test_batch_utils.py
|
|
"_responses_continuation", # Tested through the Responses mid-stream fallback tests in tests/unit/llms/base_llm/responses/test_transformation.py
|
|
"_responses_continuation_ceilings", # Tested through the Responses mid-stream fallback tests in tests/unit/llms/base_llm/responses/test_transformation.py
|
|
"_team_deployments_named", # Tested through the team lookups in the concurrent delete tests in test_router.py
|
|
"_served_openai_models", # Cached as served_openai_models, tested through the pre-call check token count tests in test_router.py
|
|
"priority_header_update", # Tested through the priority header tests in test_common_request_processing.py
|
|
"_drops_params", # Read by split_request_priority and priority_header_update, tested through both
|
|
"_responses_event_announces_background_run", # Tested through the background Responses stream tests in test_router.py
|
|
"_aresponses_background_stream_can_release", # Tested through the background Responses stream tests in test_router.py
|
|
"_raise_released_stream_error", # Tested through the background Responses stream content-policy tests in test_router.py
|
|
"_mid_stream_error_before_output", # Tested through the Responses mid-stream fallback and background stream tests
|
|
"_adiscover_openai_compatible_model_info", # Tested through the model info refresh tests in test_router_model_cost_isolation.py
|
|
"_adiscover_openrouter_model_info", # Tested through the OpenRouter refresh tests in test_router_model_cost_isolation.py
|
|
"_model_info_request_headers", # Read by both discovery paths, tested through the refresh tests in test_router_model_cost_isolation.py
|
|
"_core_get_wildcard_listing_info", # Tested through the OpenRouter wildcard listing tests in test_router_model_cost_isolation.py
|
|
"_wildcard_catalog_model_infos", # Read by _core_get_wildcard_listing_info, tested through the same listing tests
|
|
"get_routed_deployments", # Read by get_models_by_pattern and the wildcard listing, tested through both
|
|
"_deployments_of", # Read by get_routed_deployments, tested through get_models_by_pattern
|
|
"_without_decisions_deployments_refusing_media", # Tested through the mixed media-flag group tests in tests/unit/decisions/test_main.py
|
|
"_decisions_deployment_refuses_media", # Read by _without_decisions_deployments_refusing_media, tested through the same group tests
|
|
"_active_default_litellm_params", # Tested through the router default drop_params test in tests/unit/decisions/test_main.py
|
|
"_rewound", # Read by rewrite_rows_naming_model, tested through its stream tests in test_batch_utils.py
|
|
"_copy_line_renaming_model", # Read by rewrite_rows_naming_model, tested through its byte-preserving test in test_batch_utils.py
|
|
"_renamed_row", # Read by _copy_line_renaming_model, tested through the BOM, unparseable, and truncated rows in test_batch_utils.py
|
|
]
|
|
|
|
|
|
def public_name(function_name):
|
|
"""
|
|
The deprecated public name a ``_core_<name>`` router member is reached through. Tests that call the
|
|
old name run the core member, since ``DeprecatedRouterMembers`` forwards it there.
|
|
"""
|
|
return function_name.removeprefix("_core_")
|
|
|
|
|
|
def main():
|
|
router_file = [
|
|
"./litellm/router.py",
|
|
"./litellm/litellm_core_utils/batch_utils.py",
|
|
"./litellm/litellm_core_utils/pattern_match_deployments.py",
|
|
]
|
|
# router_file = [
|
|
# "../../litellm/router.py",
|
|
# "../../litellm/litellm_core_utils/pattern_match_deployments.py",
|
|
# "../../litellm/litellm_core_utils/batch_utils.py",
|
|
# ] ## LOCAL TESTING
|
|
tests_dir = "./tests/" # Update this path if your tests directory is located elsewhere
|
|
# tests_dir = "../../tests/" # LOCAL TESTING
|
|
|
|
router_functions = []
|
|
for file in router_file:
|
|
router_functions.extend(get_functions_from_router(file))
|
|
print("router_functions: ", router_functions)
|
|
called_functions_in_tests = get_all_functions_called_in_tests(tests_dir)
|
|
untested_functions = [
|
|
fn
|
|
for fn in router_functions
|
|
if fn not in called_functions_in_tests and public_name(fn) not in called_functions_in_tests
|
|
]
|
|
|
|
if untested_functions:
|
|
all_untested_functions = []
|
|
for func in untested_functions:
|
|
if func not in ignored_function_names and public_name(func) not in ignored_function_names:
|
|
all_untested_functions.append(func)
|
|
untested_perc = (len(all_untested_functions)) / len(router_functions)
|
|
print("untested_perc: ", untested_perc)
|
|
if untested_perc > 0:
|
|
print("The following functions in router.py are not tested:")
|
|
raise Exception(
|
|
f"{untested_perc * 100:.2f}% of functions in router.py are not tested: {all_untested_functions}"
|
|
)
|
|
else:
|
|
print("All functions in router.py are covered by tests.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|