Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import pytest
  17. from common import batch_create_datasets, bulk_upload_documents, delete_datasets
  18. from libs.utils.file_utils import (
  19. create_docx_file,
  20. create_eml_file,
  21. create_excel_file,
  22. create_html_file,
  23. create_image_file,
  24. create_json_file,
  25. create_md_file,
  26. create_pdf_file,
  27. create_ppt_file,
  28. create_txt_file,
  29. )
  30. @pytest.fixture(scope="function")
  31. def clear_datasets(get_http_api_auth):
  32. yield
  33. delete_datasets(get_http_api_auth)
  34. @pytest.fixture
  35. def generate_test_files(request, tmp_path):
  36. file_creators = {
  37. "docx": (tmp_path / "ragflow_test.docx", create_docx_file),
  38. "excel": (tmp_path / "ragflow_test.xlsx", create_excel_file),
  39. "ppt": (tmp_path / "ragflow_test.pptx", create_ppt_file),
  40. "image": (tmp_path / "ragflow_test.png", create_image_file),
  41. "pdf": (tmp_path / "ragflow_test.pdf", create_pdf_file),
  42. "txt": (tmp_path / "ragflow_test.txt", create_txt_file),
  43. "md": (tmp_path / "ragflow_test.md", create_md_file),
  44. "json": (tmp_path / "ragflow_test.json", create_json_file),
  45. "eml": (tmp_path / "ragflow_test.eml", create_eml_file),
  46. "html": (tmp_path / "ragflow_test.html", create_html_file),
  47. }
  48. files = {}
  49. for file_type, (file_path, creator_func) in file_creators.items():
  50. if request.param in ["", file_type]:
  51. creator_func(file_path)
  52. files[file_type] = file_path
  53. return files
  54. @pytest.fixture(scope="class")
  55. def ragflow_tmp_dir(request, tmp_path_factory):
  56. class_name = request.cls.__name__
  57. return tmp_path_factory.mktemp(class_name)
  58. @pytest.fixture(scope="class")
  59. def add_dataset(request, get_http_api_auth):
  60. def cleanup():
  61. delete_datasets(get_http_api_auth)
  62. request.addfinalizer(cleanup)
  63. dataset_ids = batch_create_datasets(get_http_api_auth, 1)
  64. return dataset_ids[0]
  65. @pytest.fixture(scope="function")
  66. def add_dataset_func(request, get_http_api_auth):
  67. def cleanup():
  68. delete_datasets(get_http_api_auth)
  69. request.addfinalizer(cleanup)
  70. dataset_ids = batch_create_datasets(get_http_api_auth, 1)
  71. return dataset_ids[0]
  72. @pytest.fixture(scope="class")
  73. def add_document(get_http_api_auth, add_dataset, ragflow_tmp_dir):
  74. dataset_id = add_dataset
  75. document_ids = bulk_upload_documents(get_http_api_auth, dataset_id, 1, ragflow_tmp_dir)
  76. return dataset_id, document_ids[0]