Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Test script for the new configuration functionality in app.py | |
| """ | |
| import os | |
| import sys | |
| from unittest.mock import patch | |
| def test_trackio_space_initialization(): | |
| """Test TrackioSpace initialization with different parameters""" | |
| print("π§ͺ Testing TrackioSpace initialization...") | |
| # Import the app module | |
| import templates.spaces.app as app | |
| # Test 1: Default initialization (uses environment variables) | |
| print("\n1. Testing default initialization...") | |
| trackio = app.TrackioSpace() | |
| print(f" Dataset repo: {trackio.dataset_repo}") | |
| print(f" HF token set: {'Yes' if trackio.hf_token else 'No'}") | |
| # Test 2: Custom initialization | |
| print("\n2. Testing custom initialization...") | |
| trackio_custom = app.TrackioSpace( | |
| hf_token="test_token_123", | |
| dataset_repo="test-user/test-dataset" | |
| ) | |
| print(f" Dataset repo: {trackio_custom.dataset_repo}") | |
| print(f" HF token set: {'Yes' if trackio_custom.hf_token else 'No'}") | |
| # Test 3: Partial custom initialization | |
| print("\n3. Testing partial custom initialization...") | |
| trackio_partial = app.TrackioSpace(dataset_repo="another-user/another-dataset") | |
| print(f" Dataset repo: {trackio_partial.dataset_repo}") | |
| print(f" HF token set: {'Yes' if trackio_partial.hf_token else 'No'}") | |
| print("β TrackioSpace initialization tests passed!") | |
| def test_configuration_functions(): | |
| """Test the configuration functions""" | |
| print("\nπ§ͺ Testing configuration functions...") | |
| import templates.spaces.app as app | |
| # Test update_trackio_config function | |
| print("\n1. Testing update_trackio_config...") | |
| result = app.update_trackio_config("test_token", "test-user/test-dataset") | |
| print(f" Result: {result}") | |
| # Test test_dataset_connection function | |
| print("\n2. Testing test_dataset_connection...") | |
| result = app.test_dataset_connection("", "test-user/test-dataset") | |
| print(f" Result: {result}") | |
| # Test create_dataset_repository function | |
| print("\n3. Testing create_dataset_repository...") | |
| result = app.create_dataset_repository("", "test-user/test-dataset") | |
| print(f" Result: {result}") | |
| print("β Configuration function tests passed!") | |
| def test_environment_variables(): | |
| """Test environment variable handling""" | |
| print("\nπ§ͺ Testing environment variable handling...") | |
| # Test with environment variables set | |
| with patch.dict(os.environ, { | |
| 'HF_TOKEN': 'env_test_token', | |
| 'TRACKIO_DATASET_REPO': 'env-user/env-dataset' | |
| }): | |
| import templates.spaces.app as app | |
| trackio = app.TrackioSpace() | |
| print(f" Dataset repo: {trackio.dataset_repo}") | |
| print(f" HF token set: {'Yes' if trackio.hf_token else 'No'}") | |
| # Test with no environment variables | |
| with patch.dict(os.environ, {}, clear=True): | |
| import templates.spaces.app as app | |
| trackio = app.TrackioSpace() | |
| print(f" Dataset repo: {trackio.dataset_repo}") | |
| print(f" HF token set: {'Yes' if trackio.hf_token else 'No'}") | |
| print("β Environment variable tests passed!") | |
| def main(): | |
| """Run all tests""" | |
| print("π Testing App Configuration Features") | |
| print("=" * 50) | |
| try: | |
| test_trackio_space_initialization() | |
| test_configuration_functions() | |
| test_environment_variables() | |
| print("\nπ All tests passed!") | |
| print("\nπ Configuration Features:") | |
| print("β HF Token input field") | |
| print("β Dataset Repository input field") | |
| print("β Environment variable fallback") | |
| print("β Configuration update function") | |
| print("β Connection testing function") | |
| print("β Dataset creation function") | |
| print("β Gradio interface integration") | |
| except Exception as e: | |
| print(f"\nβ Test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| main() |