test_base_intent_extraction

python 5 hours, 5 minutes ago
import unittest from unittest.mock import MagicMock, patch from base_intent_extraction_service import BaseIntentExtractionService # Replace with the correct module name class TestBaseIntentExtractionService(unittest.TestCase): def setUp(self): # Mock services self.mongo_service = MagicMock() self.oracle_service = MagicMock() self.service = BaseIntentExtractionService(self.mongo_service, self.oracle_service) @patch('emona.util.common_util.chunker') def test_write_data_to_mongo_in_chunks_success(self, mock_chunker): mock_chunker.return_value = [[{"record": 1}], [{"record": 2}]] self.mongo_service.bulk_write.return_value = None mongo_bulk_write_list = [{"record": 1}, {"record": 2}] mongo_collection_name = "test_collection" chunk_size = 1 self.service.write_data_to_mongo_in_chunks(mongo_bulk_write_list, mongo_collection_name, chunk_size) # Assertions self.mongo_service.bulk_write.assert_any_call(mongo_collection_name, [{"record": 1}]) self.mongo_service.bulk_write.assert_any_call(mongo_collection_name, [{"record": 2}]) self.assertEqual(self.mongo_service.bulk_write.call_count, 2) @patch('emona.util.common_util.chunker') def test_write_data_to_mongo_in_chunks_exception(self, mock_chunker): mock_chunker.return_value = [[{"record": 1}], [{"record": 2}]] self.mongo_service.bulk_write.side_effect = Exception("Mocked Exception") mongo_bulk_write_list = [{"record": 1}, {"record": 2}] mongo_collection_name = "test_collection" chunk_size = 1 self.service.write_data_to_mongo_in_chunks(mongo_bulk_write_list, mongo_collection_name, chunk_size) # Assertions self.assertEqual(self.mongo_service.bulk_write.call_count, 2) def test_get_prompt_info_success(self): mock_response = '[["prompt1", "This is a prompt", "Example1, Example2"]]' self.oracle_service.execute_select_query.return_value = mock_response result = self.service.get_prompt_info(1, "Azure") # Assertions self.assertEqual(result, { "prompt_name": "prompt1", "prompt": "This is a prompt", "examples": "Example1, Example2" }) self.oracle_service.execute_select_query.assert_called_once_with( "SELECT PROMPT_NAME, PROMPT, EXAMPLES FROM AI_PROMPT_CONFIG WHERE USE_CASE_ID = 1 AND IS_ACTIVE = 'Y' AND PROVIDER = 'Azure'" ) def test_get_prompt_info_exception(self): self.oracle_service.execute_select_query.side_effect = Exception("Mocked Exception") result = self.service.get_prompt_info(1, "Azure") # Assertions self.assertIsNone(result) def test_get_model_name_google_text(self): model_name = self.service.get_model_name("Google", "text", "text_model", "chat_model", "azure_model") self.assertEqual(model_name, "text_model") def test_get_model_name_google_chat(self): model_name = self.service.get_model_name("Google", "chat", "text_model", "chat_model", "azure_model") self.assertEqual(model_name, "chat_model") def test_get_model_name_azure(self): model_name = self.service.get_model_name("Azure", "text", "text_model", "chat_model", "azure_model") self.assertEqual(model_name, "azure_model") def test_get_model_name_invalid_provider(self): model_name = self.service.get_model_name("Invalid", "text", "text_model", "chat_model", "azure_model") self.assertIsNone(model_name) def test_get_sample_input_output_list(self): prompt_examples = """ input: Input1 output: Output1 input: Input2 output: Output2 """ inputs, outputs = self.service.get_sample_input_output_list(prompt_examples) # Assertions self.assertEqual(inputs, ["Input1", "Input2"]) self.assertEqual(outputs, ["Output1", "Output2"]) def test_get_sample_input_output_list_empty(self): inputs, outputs = self.service.get_sample_input_output_list(None) # Assertions self.assertEqual(inputs, []) self.assertEqual(outputs, []) if __name__ == '__main__': unittest.main()
3
Posted By
Python Script to create AWS beanstalk
#!/usr/bin/python
  
import boto
python aws beanstalk
sandeep sandeep
List all files and folders using python os mo
import os

def list_files_folders(path):
python python-os
kishore_kumar
Get current environment variables in python
import os
env = os.environ

python python-os
kishore_kumar
Get os details using python os
import os
print os.uname()
# Don't use os.system('uname -a'), its j
python python-os
kishore_kumar
Get stats ( lines, words, char count ) of fil
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
kishore_kumar
Use map function in python
def get_double(num):
    return num * 2

python
kishore_kumar
Python sample codes for beginners
print "Welcome to python"
python
gaya38 gaya38
Python program for even number checking
a=input("Enter a value:")
if (a%2==0):
    print "The given number is even numb
python
gaya38 gaya38
Python program for prime number check
a=input("Enter a value:")
k=0
b=(a/2)+1
python
gaya38 gaya38
Pass command line arguments in python
import sys
x=len(sys.argv)
a=[]
python
gaya38 gaya38
Python program for the largest number in an a
a = [1,43,98,5]#Dummy data
for l in range(len(a)-1):
        if (a[l]>a[l+1]):
python
gaya38 gaya38
print list of even numbers within a range
n=100
a=[10,20,30,40,50]
b=[60,70,80,90]
python
gaya38 gaya38
generate fibonacci series in python
n=input("Enter the constraint to print n
m=input("Enter the maximum value to prin
a=0
python
gaya38 gaya38
Generate Random number within the range in py
import random
print random.uniform(10,500)
python
gaya38 gaya38
Shuffle list elements in python
import random;
z = [1,90,4,2]
z = random.shuffle(z)
python
gaya38 gaya38
use python requests to get contents of url (
import requests

req = requests.get("https://httpbin.org/
python python-requests
kishore_kumar
how to iterate or get values in python dictio
sample_dict = { "number": 1, "fruits": [

for key in sample_dict:
python
kishore_kumar
create matrix and multiply using numpy in pyt
import numpy as np

matrix = [[1,2,3], [4,5,6], [7,8,9]]
python numpy
kishore_kumar
generate random numbers matrix with numpy pyt
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
kishore_kumar
Find min , max and mean for numpy arrays
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
kishore_kumar