mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-03-20 22:27:42 +08:00
Add comprehensive unit tests for `graphrag/utils.py`, covering 15 functions/classes with 87 test cases. Tested functions: - clean_str, dict_has_keys_with_types, perform_variable_replacements - get_from_to, compute_args_hash, is_float_regex - GraphChange dataclass - handle_single_entity_extraction, handle_single_relationship_extraction - graph_merge, tidy_graph - split_string_by_multi_markers, pack_user_ass_to_openai_messages - is_continuous_subsequence, merge_tuples, flat_uniq_list All 327 existing + new tests pass with no regressions.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
#
|
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
|
|
"""
|
|
Mock heavy dependencies that graphrag/utils.py transitively imports,
|
|
so unit tests can run without infrastructure services (Redis, Elasticsearch, etc.).
|
|
"""
|
|
|
|
import sys
|
|
from unittest.mock import MagicMock
|
|
|
|
_modules_to_mock = [
|
|
"quart",
|
|
"common.connection_utils",
|
|
"common.settings",
|
|
"common.doc_store",
|
|
"common.doc_store.doc_store_base",
|
|
"rag.nlp",
|
|
"rag.nlp.search",
|
|
"rag.nlp.rag_tokenizer",
|
|
"rag.utils.redis_conn",
|
|
]
|
|
|
|
for mod_name in _modules_to_mock:
|
|
if mod_name not in sys.modules:
|
|
sys.modules[mod_name] = MagicMock()
|
|
|
|
# Ensure `from common.connection_utils import timeout` returns a no-op decorator
|
|
sys.modules["common.connection_utils"].timeout = lambda *a, **kw: (lambda fn: fn)
|