1+ {
2+ "metadata" : {
3+ "kernelspec" : {
4+ "display_name" : " Streamlit Notebook" ,
5+ "name" : " streamlit"
6+ },
7+ "lastEditStatus" : {
8+ "notebookId" : " 7ycg3hbug2glfjvzz3xl" ,
9+ "authorId" : " 6690310009356" ,
10+ "authorName" : " YOHANMARKOSE" ,
11+ "authorEmail" : " markose.y@northeastern.edu" ,
12+ "sessionId" : " aa1f1098-f598-47d1-a214-190db2554032" ,
13+ "lastEditTime" : 1740721506591
14+ }
15+ },
16+ "nbformat_minor" : 5 ,
17+ "nbformat" : 4 ,
18+ "cells" : [
19+ {
20+ "cell_type" : " markdown" ,
21+ "id" : " 22551f39-0e95-4c06-883e-0a796eb918f6" ,
22+ "metadata" : {
23+ "name" : " cell8" ,
24+ "collapsed" : false
25+ },
26+ "source" : " # Unit Test Notebook"
27+ },
28+ {
29+ "cell_type" : " code" ,
30+ "id" : " 3deb088f-9d32-4337-a77f-c59a6d5861ce" ,
31+ "metadata" : {
32+ "language" : " python" ,
33+ "name" : " cell5"
34+ },
35+ "outputs" : [],
36+ "source" : " from snowflake.snowpark.context import get_active_session\n\n # Enter the Running env\n env = 'DEV'\n\n database_name = 'FRED_DB'\n schema_name = f'{env}_ANALYTICS'\n session = get_active_session()" ,
37+ "execution_count" : null
38+ },
39+ {
40+ "cell_type" : " markdown" ,
41+ "id" : " 47662e29-e56d-43fd-bed4-1b8ead7c7b24" ,
42+ "metadata" : {
43+ "name" : " cell2" ,
44+ "collapsed" : false
45+ },
46+ "source" : " ## Creating The Unit Test Log Table"
47+ },
48+ {
49+ "cell_type" : " code" ,
50+ "id" : " 05773e01-8e7b-482a-879a-d6dbd8758a17" ,
51+ "metadata" : {
52+ "language" : " sql" ,
53+ "name" : " cell4"
54+ },
55+ "outputs" : [],
56+ "source" : " CREATE OR REPLACE TABLE FRED_DB.INTEGRATIONS.TEST_LOGS (\n TEST_NAME STRING,\n EXPECTED STRING,\n OUTPUT STRING,\n TEST_STATUS STRING,\n TEST_MESSAGE STRING,\n TEST_TIMESTAMP TIMESTAMP_LTZ DEFAULT CURRENT_TIMESTAMP()\n );" ,
57+ "execution_count" : null
58+ },
59+ {
60+ "cell_type" : " markdown" ,
61+ "id" : " 433951f0-7eb7-4e7a-b4ef-4414b8007a40" ,
62+ "metadata" : {
63+ "name" : " cell3" ,
64+ "collapsed" : false
65+ },
66+ "source" : " ## PyTest Functions to Test the defined UDF"
67+ },
68+ {
69+ "cell_type" : " code" ,
70+ "id" : " 3775908f-ca36-4846-8f38-5adca39217f2" ,
71+ "metadata" : {
72+ "language" : " python" ,
73+ "name" : " cell1"
74+ },
75+ "source": "def log_test_result(test_name, expected, output, test_status, test_message):\n \"\"\"Log test results to the TEST_LOGS table.\"\"\"\n session.sql(f\"\"\"\n INSERT INTO FRED_DB.INTEGRATIONS.TEST_LOGS (TEST_NAME, EXPECTED, OUTPUT, TEST_STATUS, TEST_MESSAGE)\n VALUES ('{test_name}', '{expected}', '{output}', '{test_status}', '{test_message}')\n \"\"\").collect()\n \n# Example test\ndef test_calculate_spread():\n try:\n result = session.sql(f\"SELECT {database_name}.{schema_name}.calculate_spread(1.88, 0.23)\").collect()[0][0]\n assert result == 1.65, f\"Expected 1.65, got {result}\"\n log_test_result(\"test_calculate_spread\", \"1.65\", str(result), \"PASS\", \"Spread calculation is correct\")\n except Exception as e:\n log_test_result(\"test_calculate_spread\", \"1.65\", str(result), \"FAIL\", str(e))\n\ndef test_check_spread_status():\n try:\n # Positive spread\n result = session.sql(f\"SELECT {database_name}.{schema_name}.check_spread_status(1.65)\").collect()[0][0]\n assert result == 'POSITIVE', f\"Expected 'POSITIVE', got {result}\"\n log_test_result(\"test_check_spread_status\", \"POSITIVE\", str(result), \"PASS\", \"Spread status calculation is correct\")\n \n # Negative spread\n result = session.sql(f\"SELECT {database_name}.{schema_name}.check_spread_status(-0.10)\").collect()[0][0]\n assert result == 'NEGATIVE', f\"Expected 'NEGATIVE', got {result}\"\n log_test_result(\"test_check_spread_status\", \"NEGATIVE\", str(result), \"PASS\", \"Spread status calculation is correct\")\n \n # Zero spread\n result = session.sql(f\"SELECT {database_name}.{schema_name}.check_spread_status(0.00)\").collect()[0][0]\n assert result == 'ZERO', f\"Expected 'ZERO', got {result}\"\n \n # Log success\n log_test_result(\"test_check_spread_status\", \"ZERO\", str(result), \"PASS\", \"Spread status calculation is correct\")\n except Exception as e:\n # Log failure\n log_test_result(\"test_check_spread_status\", \"\", \"\", \"FAIL\", str(e))\n",
76+ "execution_count" : null ,
77+ "outputs" : []
78+ },
79+ {
80+ "cell_type" : " markdown" ,
81+ "id" : " 02cb6f3e-4ed8-49a1-848f-621174ba17bd" ,
82+ "metadata" : {
83+ "name" : " cell7" ,
84+ "collapsed" : false
85+ },
86+ "source" : " ## Running The Tests"
87+ },
88+ {
89+ "cell_type" : " code" ,
90+ "id" : " 27010c3c-4a0a-44ac-a602-416533189e1d" ,
91+ "metadata" : {
92+ "language" : " python" ,
93+ "name" : " cell6"
94+ },
95+ "outputs" : [],
96+ "source" : " # Running the tests\n test_calculate_spread()\n test_check_spread_status()" ,
97+ "execution_count" : null
98+ }
99+ ]
100+ }
0 commit comments