Files
doczyai-pipelines/fieldExtraction/tests/cnc_hotfix_test.py
T
Alex Galarce 53b38ea15c Merged in refactor/split-investment-and-client (pull request #347)
Refactor/split investment and client

* refactor: clean up tests

* Renamed tests/qcqa to tests/qa_qc for consistency

* comment out faulty test - see docstring note at top

* split to client/investment

* add __init__.py to investment and client to avoid mypy confusion

* fix imports

* update imports for consistency across investment module

* move back to one config

* try changing import to relative

* add init.py to src

* try relative import

* try one more sys.path.append

* fix path for client main

* fix imports in file_processing

* make prompts common

* move keywords out to `src`

* move smart_chunking_funcs to `src`

* fix mypy error

* start moving to explicit imports

* remove old keywords and fix imports for keywords and prompts

* change all imports to full paths

* fix unit tests

* add readme for new way of running things

* isort after all that import work

* remove unused sys.path.append from some tests


Approved-by: Katon Minhas
2025-01-08 21:59:47 +00:00

208 lines
8.6 KiB
Python

import math
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
# from scripts.cnc_hotfixes.hotfix_helper_funcs import state_check
# class TestStateCheck:
# @pytest.mark.parametrize("input_state,expected_df_output,expected_non_df_output", [
# ("Multiple", "N/A",["N/A"]),
# ("Peach State", "N/A",["N/A"]),
# ("Statewide", "N/A",["N/A"]),
# ("Sunshine State Health Plan Suggests This Is For Florida, But Since The State Is Not Explicitly Specified, The Most Appropriate Answer Is:\n\nN/A", "N/A", ["N/A"]),
# ("The Contract Text Indicates This Health Plan Is For The Sunshine State, Which Is Florida. Therefore, The Answer Is:\n\nFlorida->N/A", "N/A", ["N/A"]),
# ("Sunshine State", "N/A", ["N/A"]),
# ("The Health Plan Is For The Sunshine State, Which Refers To Florida. However, Since The State Is Not Explicitly Specified, The Most Accurate Answer Based Solely On The Information Provided Is:\n\nN/A", "N/A", ["N/A"]),
# ])
# def test_invalid_state_names(self, input_state, expected_df_output, expected_non_df_output):
# """Test invalid inputs"""
# assert state_check(input_state,is_dataframe=True) == expected_df_output
# assert state_check(input_state,is_dataframe=False) == expected_non_df_output
# def test_hlorida_correction(self):
# """Test fix - Hlorida -> Florida"""
# assert state_check("Hlorida",is_dataframe=False) == ["Florida"]
# @pytest.mark.parametrize("input_state,expected_df_output,expected_non_df_output", [
# ("AL", "Alabama",["Alabama"]),
# ("Florida", "Florida",["Florida"]),
# ("FLORIDA", "Florida",["Florida"]),
# ("florida", "Florida",["Florida"]),
# ])
# def test_valid_states(self, input_state, expected_df_output, expected_non_df_output):
# """Test valid inputs"""
# assert state_check(input_state,is_dataframe=True) == expected_df_output
# assert state_check(input_state,is_dataframe=False) == expected_non_df_output
# def test_list_inputs(self):
# """Test a list of input"""
# input_states = ["AL", "Florida", "Hlorida", "Multiple"]
# expected_df_output = "Alabama, Florida, Florida, N/A"
# expected_non_df_output = ["Alabama", "Florida", "Florida", "N/A"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# @pytest.mark.parametrize("invalid_input", [
# 123,
# {"state": "Florida"},
# True
# ])
# def test_invalid_input_types(self, invalid_input):
# """Test invalid input types"""
# with pytest.raises(TypeError):
# state_check(invalid_input)
# @pytest.mark.parametrize("empty_input,expected_df_output,expected_non_df_output", [
# ("", "N/A",["N/A"]),
# ([], "",[]),
# ([" "], "N/A",["N/A"])
# ])
# def test_empty_inputs(self, empty_input, expected_df_output, expected_non_df_output):
# """Test empty inputs"""
# assert state_check(empty_input,is_dataframe=True) == expected_df_output
# assert state_check(empty_input,is_dataframe=False) == expected_non_df_output
# def test_multiple_invalid_states(self):
# """Test multiple invalid inputs"""
# input_states = [
# "Multiple",
# "Peach State",
# "The Health Plan Is For The Sunshine State, Which Refers To Florida. So The Answer Is:\n\nFlorida->N/A",
# "The Health Plan Is For The Florida State, Which Refers To Florida",
# "Sunshine State Health Plan Suggests This Is For Florida, But Since The State Is Not Explicitly Specified, The Most Appropriate Answer Is:\n\nN/A->N/A",
# "Sunshine State Health Plan->N/A",
# "Sunshine State->N/A",
# "The Contract Text Indicates This Health Plan Is For Florida, As It Mentions Sunshine State Health Plan, Inc. Which Operates In Florida. However, To Strictly Follow The Instructions, I Will Provide The Answer:\n\nN/A->N/A"
# ]
# expected_df_output = ", ".join(["N/A"]*8)
# expected_non_df_output = ["N/A"]*8
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# def test_mixed_states(self):
# """Test mixed input"""
# input_states = ["AL", "Multiple", "Florida", "Hlorida", "Florida State Health Plan"]
# expected_df_output = "Alabama, N/A, Florida, Florida, N/A"
# expected_non_df_output = ["Alabama", "N/A", "Florida", "Florida", "N/A"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# def concatenated_string_states(self):
# """Test concatentated input"""
# input_states = ["Arizona, Louisiana","NY, NJ, Connecticut"]
# expected_df_output = "Arizona, Louisiana, New York, New Jersey"
# expected_non_df_output = ["Arizona", "Louisiana", "New York", "New Jersey"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# class TestApplyStateCheckToDataFrame:
# def test_basic_state_processing(self):
# """Test basic state code to full name conversion"""
# df = pd.DataFrame({
# 'Health Plan State': ['NY', 'CA', 'TX', ['CO','CT'], 'NJ, AR']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['NY', 'CA', 'TX', ['CO','CT'], 'NJ, AR'],
# 'Health Plan State_corrected': ['New York', 'California', 'Texas', 'Colorado, Connecticut', 'New Jersey, Arkansas']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_mixed_case_states(self):
# """Test handling of mixed case input"""
# df = pd.DataFrame({
# 'Health Plan State': ['ny', 'Ca', 'TeXaS']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['ny', 'Ca', 'TeXaS'],
# 'Health Plan State_corrected': ['New York', 'California', 'Texas']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_invalid_states(self):
# """Test handling of invalid state codes"""
# df = pd.DataFrame({
# 'Health Plan State': [['SH', 'IO'], 'LM', 'XY']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': [['SH', 'IO'], 'LM', 'XY'],
# 'Health Plan State_corrected': ['N/A, N/A', 'N/A', 'N/A']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_already_full_state_names(self):
# """Test handling of already expanded state names"""
# df = pd.DataFrame({
# 'Health Plan State': ['Vermont', 'Tennessee', 'Mississippi']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['Vermont', 'Tennessee', 'Mississippi'],
# 'Health Plan State_corrected': ['Vermont', 'Tennessee', 'Mississippi']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_empty_dataframe(self):
# """Test handling of empty DataFrame"""
# df = pd.DataFrame({'Health Plan State': []})
# expected_df = pd.DataFrame({
# 'Health Plan State': [],
# 'Health Plan State_corrected': []
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_wrong_column_name(self):
# """Test error handling for non-existent column"""
# df = pd.DataFrame({
# 'Heaalth Plans state': ['NY', 'CA'],
# })
# with pytest.raises(KeyError) as exc_info:
# apply_state_check_to_df(df,is_dataframe=True)
# def test_is_dataframe_parameter_false(self):
# """Test 'is_dataframe' parameter as false"""
# df = pd.DataFrame({'Health Plan State': ['NY', 'CA']})
# with pytest.raises(ValueError):
# apply_state_check_to_df(df,is_dataframe=False)