Skip to content

Conversation

abhijeetSaroha
Copy link
Contributor

No description provided.

@abhijeetSaroha
Copy link
Contributor Author

I have created the initial PR for test cases, but it has some issue, test cases is not passing currently, anyone can help me in that how to improve this.

@felipepaes
Copy link
Contributor

Hey @abhijeetSaroha I was thinking if instead of adding a mock test for avoiding the ci not selecting any tests. We could implement a test for the utils module by creating tests/test_utils.py for it.

Here is how it would look like

"""Tests for anamnesisai package utility module."""

import pytest

from typing import Type

from fhir.resources.resource import Resource

from anamnesisai.utils import get_resource_detail


class MockResource(Resource):  # type: ignore[misc]
    """Disclaimer: Any field name ends with ``__ext`` doesn't part of
    Resource StructureDefinition, instead used to enable Extensibility feature
    for FHIR Primitive Data Types.

    MOCK RESOURCE FOR TESTING PURPOSES ONLY. 
    This is a simulated DomainResource used to test resource handling functionality.
    It mimics the structure of a real FHIR resource but contains no actual implementation.
    """


@pytest.fixture
def resource() -> Type[Resource]:
    """Mock Resource fixture."""  # noqa: D202

    return MockResource


def test_get_resource_detail(resource: Type[Resource]) -> None:
    """Test get_resource_detail function."""
    expected = (
        "MOCK RESOURCE FOR TESTING PURPOSES ONLY. "
        "This is a simulated DomainResource used to test "
        "resource handling functionality. It mimics the "
        "structure of a real FHIR resource but contains no "
        "actual implementation."
    )
    assert get_resource_detail(resource) == expected

ps. I has to add # type: ignore[misc] otherwise mypy complains that we are subclassing from type Any

This should be enough to avoid the non tests selected error. You can try it locally by running makim tests.unit --params "-v tests/test_utils.py"

@felipepaes
Copy link
Contributor

LGTM @abhijeetSaroha ! Did it run ok locally?


for filename, content in synthetic_files_content.items():
print(f"Testing synthetic file: {filename}")
fhir_data = aai.extract_fhir(content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be quite expensive, running the extract_fhr_resources against all synthetic files would take a lot of time and api calls.

with open(random_file, "r") as f:
transcript_content = f.read()

api_key = openai_api_key if backend == "openai" else ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we may need another fixture to get the api key from a dictionary where the key will be the backend literal and the value will be the API_KEY from .env, but right now I don't think it's necessary. We can do that once we implement ollama and/or other LLMs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants