Files
assafelovic__gpt-researcher/tests/test_estimate_llm_cost_none.py
Assaf Elovic 3de7465037 fix(utils, config, document, vector_store): guard null and non-dict inputs
Consolidates the remaining single-file PRs from @Bartok9.

estimate_llm_cost hit None content, GlobalRateLimiter.configure accepted
an uncoerced delay, convert_env_value could not read list/dict JSON that
needed repair, the document loader assumed metadata['source'] existed
and reported the wrong extension when a loader failed, and the vector
store iterated docs without checking each was a dict with content.

Squashed from #1957 #1964 #1966 #1973 #2003 #2012.

Co-Authored-By: Bartok9 <noreply@github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 12:04:13 +03:00

30 lines
743 B
Python

"""estimate_llm_cost must tolerate None/non-str arguments."""
import importlib.util
import pathlib
_PATH = (
pathlib.Path(__file__).resolve().parent.parent
/ "gpt_researcher"
/ "utils"
/ "costs.py"
)
_spec = importlib.util.spec_from_file_location("_costs_ut", _PATH)
_mod = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_mod)
def test_none_inputs_return_zeroish():
assert _mod.estimate_llm_cost(None, None) == 0.0
def test_mixed_none_does_not_raise():
cost = _mod.estimate_llm_cost("hello world", None)
assert isinstance(cost, float)
assert cost > 0
def test_non_str_coerced():
cost = _mod.estimate_llm_cost(12345, ["a", "b"])
assert isinstance(cost, float)
assert cost > 0