Spaces:
Runtime error
Runtime error
Create tests/test_utils.py
Browse files- tests/test_utils.py +90 -0
tests/test_utils.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import unittest
|
| 3 |
+
from unittest.mock import patch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TestStreamlitApp(unittest.TestCase):
|
| 7 |
+
"""Test suite for the Streamlit app components"""
|
| 8 |
+
|
| 9 |
+
@patch("streamlit.title")
|
| 10 |
+
@patch("streamlit.markdown")
|
| 11 |
+
@patch("streamlit.subheader")
|
| 12 |
+
@patch("streamlit.columns")
|
| 13 |
+
@patch("streamlit.metric")
|
| 14 |
+
@patch("utils.set_page_config")
|
| 15 |
+
@patch("utils.display_sidebar")
|
| 16 |
+
def test_app_initialization(
|
| 17 |
+
self,
|
| 18 |
+
mock_display_sidebar,
|
| 19 |
+
mock_set_page_config,
|
| 20 |
+
mock_metric,
|
| 21 |
+
mock_columns,
|
| 22 |
+
mock_subheader,
|
| 23 |
+
mock_markdown,
|
| 24 |
+
mock_title,
|
| 25 |
+
):
|
| 26 |
+
"""Test app initialization and component display"""
|
| 27 |
+
|
| 28 |
+
mock_set_page_config.assert_called_once()
|
| 29 |
+
mock_title.assert_called_once_with("CodeGen Hub")
|
| 30 |
+
mock_markdown.assert_called()
|
| 31 |
+
mock_display_sidebar.assert_called_once()
|
| 32 |
+
|
| 33 |
+
@patch("streamlit.session_state", new_callable=dict)
|
| 34 |
+
def test_session_state_initialization(self, mock_session_state):
|
| 35 |
+
"""Test session state variable initialization"""
|
| 36 |
+
|
| 37 |
+
self.assertIn("datasets", mock_session_state)
|
| 38 |
+
self.assertIn("trained_models", mock_session_state)
|
| 39 |
+
self.assertIn("training_logs", mock_session_state)
|
| 40 |
+
self.assertIn("training_progress", mock_session_state)
|
| 41 |
+
|
| 42 |
+
self.assertEqual(mock_session_state["datasets"], {})
|
| 43 |
+
self.assertEqual(mock_session_state["trained_models"], {})
|
| 44 |
+
self.assertEqual(mock_session_state["training_logs"], [])
|
| 45 |
+
self.assertEqual(mock_session_state["training_progress"], {})
|
| 46 |
+
|
| 47 |
+
@patch("streamlit.metric")
|
| 48 |
+
@patch("streamlit.session_state", new_callable=dict)
|
| 49 |
+
def test_platform_statistics_display(self, mock_session_state,
|
| 50 |
+
mock_metric):
|
| 51 |
+
"""Test platform statistics metrics display"""
|
| 52 |
+
mock_session_state["datasets"] = {
|
| 53 |
+
"dataset1": "data1",
|
| 54 |
+
"dataset2": "data2"
|
| 55 |
+
}
|
| 56 |
+
mock_session_state["trained_models"] = {"model1": "trained_model1"}
|
| 57 |
+
mock_session_state["training_progress"] = {
|
| 58 |
+
"job1": {
|
| 59 |
+
"status": "running"
|
| 60 |
+
},
|
| 61 |
+
"job2": {
|
| 62 |
+
"status": "completed"
|
| 63 |
+
},
|
| 64 |
+
"job3": {
|
| 65 |
+
"status": "running"
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
mock_metric.assert_any_call("Datasets Available", 2)
|
| 70 |
+
mock_metric.assert_any_call("Trained Models", 1)
|
| 71 |
+
mock_metric.assert_any_call("Active Training Jobs", 2)
|
| 72 |
+
|
| 73 |
+
@patch("streamlit.info")
|
| 74 |
+
def test_getting_started_section_display(self, mock_info):
|
| 75 |
+
"""Test 'Getting Started' section instructions display"""
|
| 76 |
+
|
| 77 |
+
expected_messages = [
|
| 78 |
+
"1. π Start by uploading or selecting a Python code dataset in the **Dataset Management** section.",
|
| 79 |
+
"2. π οΈ Configure and train your model in the **Model Training** section.",
|
| 80 |
+
"3. π‘ Generate code predictions using your trained models in the **Code Generation** section.",
|
| 81 |
+
"4. π Access your models on Hugging Face Hub for broader use.",
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
for msg in expected_messages:
|
| 85 |
+
mock_info.assert_any_call(msg)
|
| 86 |
+
self.assertEqual(mock_info.call_count, 4)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
unittest.main()
|