ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

Refactor/sdk tests to use fixtures

Open voulkon opened this issue 1 year ago • 3 comments

What problem does this PR solve?

ATTENTION! I haven't managed to run tests and ensure that everything's working smoothly (I will start a respective issue to record why). Though I think there are many possibilities tests will work as expected.


I noticed in the sdk tests that we repeat this line of code:

ragflow = RAGFlow(API_KEY, HOST_ADDRESS) and recreate the same object in every test.

I replaced it with a fixture: @pytest.fixture(scope="class") def ragflow(): return RAGFlow(API_KEY, HOST_ADDRESS) to

  1. Keep each test simpler and smaller in size
  2. Centralize the object's creation (in case we need to change the way we create it).

Also, I replaced the setup_method of test_dataset.py with a slightly different one: ` @pytest.fixture(autouse=True) def setup_and_teardown(ragflow): # Setup: Delete all datasets before each test listed_data = ragflow.list_dataset() listed_data = listed_data["data"] listed_names = {d["name"] for d in listed_data} for name in listed_names: ragflow.delete_dataset(name) yield # Teardown: Delete all datasets after each test listed_data = ragflow.list_dataset() listed_data = listed_data["data"] listed_names = {d["name"] for d in listed_data} for name in listed_names: ragflow.delete_dataset(name)

` Which ensures it also deletes dataset after each test is run.


Finally, I created this fixture function: @pytest.fixture def create_dataset(ragflow): def _create_dataset(name): created_res = ragflow.create_dataset(name) return created_res["data"]["dataset_id"] return _create_dataset

to avoid the repetition of this line:

dataset_id = created_res["data"]["dataset_id"] in test_document.py.

Type of change

  • [X] Refactoring

It's about refactoring the sdk tests.

voulkon avatar Jul 16 '24 14:07 voulkon

Thanks for your contribution, Voulkon. But do you want to make it a contribution or just a suggestion? If you want to contribute, could you please make it more complete and try to run all the tests?

cecilia-uu avatar Jul 17 '24 02:07 cecilia-uu

Hi cecilia-uu,

Contribution was my intention but I found it hard to run the tests, since I didn't find neither any CI pipeline, nor any guidelines to run them.

I tried to install requirements_dev.txt and I got:

Collecting idna==3.6 Using cached idna-3.6-py3-none-any.whl (61 kB) ERROR: Could not find a version that satisfies the requirement install==1.3.5 (from versions: none) ERROR: No matching distribution found for install==1.3.5

image

So, right after I was facing missing modules:

from ruamel.yaml import YAML

E ModuleNotFoundError: No module named 'ruamel.yaml'

image

I tried removing idna package from requirements_dev.txt and I got:

ERROR: Could not find a version that satisfies the requirement install==1.3.5 (from versions: none) ERROR: No matching distribution found for install==1.3.5

image

I'll have a close look today. If you could provide some guidance, it would be deeply appreciated.

voulkon avatar Jul 17 '24 14:07 voulkon

I tried to install requirements_dev.txt and I got:

Install requirements.txt instead of requirements_dev.txt

KevinHuSh avatar Jul 19 '24 01:07 KevinHuSh