From 8aeb4e00af2651cf7ec55f2ace23c600f537ff77 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 27 May 2024 14:33:44 +0300 Subject: Delete llm obsolete unittests --- tests/unit/test_llm.py | 65 -------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.py index 7b8a970..6e0f2af 100644 --- a/tests/unit/test_llm.py +++ b/tests/unit/test_llm.py @@ -35,68 +35,3 @@ def test_parse_context(): ] assert parsed_result == expected_result - - -@dataclass(frozen=True) -class MockResponse: - """mock a response object""" - text: str - - def __getattr__(self, name: str): - return self.__dict__[f"_{name}"] - - -class MockGeneNetworkQAClient: - """mock the GeneNetworkQAClient class""" - - def __init__(self, session, api_key): - pass - - def ask(self, query, auth_token): - """mock method for ask query""" - # Simulate the ask method - return MockResponse("Mock response"), "F400995EAFE104EA72A5927CE10C73B7" - - def get_answer(self, task_id): - """mock get_answer method""" - return MockResponse("Mock answer"), 1 - - -def mock_filter_response_text(text): - """ method to simulate the filterResponseText method""" - return {"data": {"answer": "Mock answer for what is a gene", "context": {}}} - - -def mock_parse_context(context, get_info_func, format_bib_func): - """method to simulate the parse context method""" - return [] - - -@pytest.mark.unit_test -def test_get_gnqa(monkeypatch): - """test for process.get_gnqa functoin""" - monkeypatch.setattr( - "gn3.llms.process.GeneNetworkQAClient", - MockGeneNetworkQAClient - ) - - monkeypatch.setattr( - 'gn3.llms.process.filter_response_text', - mock_filter_response_text - ) - monkeypatch.setattr( - 'gn3.llms.process.parse_context', - mock_parse_context - ) - - query = "What is a gene" - auth_token = "test_token" - result = get_gnqa(query, auth_token) - - expected_result = ( - "F400995EAFE104EA72A5927CE10C73B7", - 'Mock answer for what is a gene', - [] - ) - - assert result == expected_result -- cgit v1.2.3 From 59a27f884b2821ab9142f5285cd713ec374ea820 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 27 May 2024 14:47:19 +0300 Subject: Pylint fixes. --- tests/unit/test_llm.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.py index 6e0f2af..c32e888 100644 --- a/tests/unit/test_llm.py +++ b/tests/unit/test_llm.py @@ -1,8 +1,5 @@ -# pylint: disable=unused-argument -"""Test cases for procedures defined in llms module""" -from dataclasses import dataclass +"""Test cases for procedures defined in llms """ import pytest -from gn3.llms.process import get_gnqa from gn3.llms.process import parse_context -- cgit v1.2.3 From e80b08c42550aaf6ae014d88d5eaad6c9659f212 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 3 Sep 2024 11:46:39 +0300 Subject: Add unittests for formatting bib info. --- tests/unit/test_llm.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.py index c32e888..97365f4 100644 --- a/tests/unit/test_llm.py +++ b/tests/unit/test_llm.py @@ -1,7 +1,7 @@ """Test cases for procedures defined in llms """ import pytest from gn3.llms.process import parse_context - +from gn3.llms.process import format_bibliography_info @pytest.mark.unit_test @@ -32,3 +32,25 @@ def test_parse_context(): ] assert parsed_result == expected_result + +@pytest.mark.unit_test +def test_format_bib_info(): + mock_fahamu_bib_info = [ + { + "author": "J.m", + "firstName": "john", + "title": "Genes and aging", + "year": 2013, + "doi": "https://Articles.com/12231" + }, + "2019-Roy-Evaluation of Sirtuin-3 probe quality and co-expressed genes", + "2015 - Differential regional and cellular distribution of TFF3 peptide in the human brain.txt"] + expected_result = [ + "J.m.Genes and aging.2013.https://Articles.com/12231 ", + "2019-Roy-Evaluation of Sirtuin-3 probe quality and co-expressed genes", + "2015 - Differential regional and cellular distribution of TFF3 peptide in the human brain" + ] + + assert all([format_bibliography_info(data) == expected + for data, expected + in zip(mock_fahamu_bib_info, expected_result)]) -- cgit v1.2.3 From 3c3f91e6cfd0f4557101dfb0729d0b4f6bad3604 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 3 Sep 2024 12:15:54 +0300 Subject: Add tests for fetching and populating references. --- tests/unit/test_llm.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.py index 97365f4..51b4921 100644 --- a/tests/unit/test_llm.py +++ b/tests/unit/test_llm.py @@ -1,5 +1,6 @@ """Test cases for procedures defined in llms """ import pytest +from gn3.llms.process import fetch_pubmed from gn3.llms.process import parse_context from gn3.llms.process import format_bibliography_info @@ -54,3 +55,50 @@ def test_format_bib_info(): assert all([format_bibliography_info(data) == expected for data, expected in zip(mock_fahamu_bib_info, expected_result)]) + + +@pytest.mark.unit_test +def test_fetching_pubmed_info(monkeypatch): + + def mock_load_file(filename, dir_path): + return { + "12121" : { + "Abstract": "items1", + "Author": "A1" + } + } + # patch the module with the mocked function + + monkeypatch.setattr("gn3.llms.process.load_file", mock_load_file) + expected_results = [ + { + "title": "Genes", + "year": "2014", + "doi": "https/article/genes/12121", + "doc_id": "12121", + "pubmed": { + "Abstract": "items1", + "Author": "A1" + } + }, + { + "title": "Aging", + "year" : "2014", + "doc_id": "12122" + } + ] + + data = [ { + "title": "Genes", + "year": "2014", + "doi": "https/article/genes/12121", + "doc_id": "12121", + }, + { + "title": "Aging", + "year" : "2014", + "doc_id": "12122" + }] + + assert (fetch_pubmed(data, "/pubmed.json", "data/") + == expected_results) -- cgit v1.2.3 From a190f6aa0ddd745e46f6ca059d06a3fca5ffbf2e Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 3 Sep 2024 12:31:04 +0300 Subject: Make pylint fixes. --- tests/unit/test_llm.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.py index 51b4921..8fbaba6 100644 --- a/tests/unit/test_llm.py +++ b/tests/unit/test_llm.py @@ -1,4 +1,5 @@ """Test cases for procedures defined in llms """ +# pylint: disable=C0301 import pytest from gn3.llms.process import fetch_pubmed from gn3.llms.process import parse_context @@ -36,6 +37,7 @@ def test_parse_context(): @pytest.mark.unit_test def test_format_bib_info(): + """Test for formatting bibliography info """ mock_fahamu_bib_info = [ { "author": "J.m", @@ -52,17 +54,17 @@ def test_format_bib_info(): "2015 - Differential regional and cellular distribution of TFF3 peptide in the human brain" ] - assert all([format_bibliography_info(data) == expected + assert all((format_bibliography_info(data) == expected for data, expected - in zip(mock_fahamu_bib_info, expected_result)]) + in zip(mock_fahamu_bib_info, expected_result))) @pytest.mark.unit_test def test_fetching_pubmed_info(monkeypatch): - - def mock_load_file(filename, dir_path): + """Test for fetching and populating pubmed data with pubmed info""" + def mock_load_file(_filename, _dir_path): return { - "12121" : { + "12121": { "Abstract": "items1", "Author": "A1" } @@ -83,22 +85,22 @@ def test_fetching_pubmed_info(monkeypatch): }, { "title": "Aging", - "year" : "2014", + "year": "2014", "doc_id": "12122" } ] - data = [ { + data = [{ "title": "Genes", "year": "2014", "doi": "https/article/genes/12121", "doc_id": "12121", - }, - { + }, + { "title": "Aging", - "year" : "2014", + "year": "2014", "doc_id": "12122" - }] + }] assert (fetch_pubmed(data, "/pubmed.json", "data/") == expected_results) -- cgit v1.2.3