Spaces:
Sleeping
Sleeping
Download test_validation.py from StrategyStack/README: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/StrategyStack/README/resolve/59b483877107f99df2006fceaa2be0bb37f3fd90/test_validation.py
- Command line
-
hf download hf://spaces/StrategyStack/README@59b483877107f99df2006fceaa2be0bb37f3fd90/test_validation.py
-
curl -L -o test_validation.py https://huggingface.co/spaces/StrategyStack/README/resolve/59b483877107f99df2006fceaa2be0bb37f3fd90/test_validation.py
2.14 kB
| """ | |
| Validation script: Runs schema-compliant inserts, error cases, and prints results for atomic activity ingestion function. | |
| """ | |
| from activity_ingestion import atomic_append_activity | |
| import os | |
| def print_test_result(test_name, result): | |
| status = 'PASS' if result['success'] else 'FAIL' | |
| print(f'[{status}] {test_name}') | |
| if result['error']: | |
| print(f' Error: {result["error"]}') | |
| else: | |
| print(f' Commit Hash: {result.get("commit_hash")}, Request ID: {result.get("request_id")}') | |
| def test_all(): | |
| # Clean up before test for atomicity validation | |
| if os.path.exists('activity_log.csv'): | |
| os.rename('activity_log.csv', 'activity_log.csv.bak') | |
| valid_rec = { | |
| 'agent_id': 'validation_agent', | |
| 'activity_type': 'ingest', | |
| 'entity_id': 'entity_001', | |
| 'status': 'success', | |
| 'notes': 'Valid activity example', | |
| 'context': 'Validation test - success' | |
| } | |
| invalid_rec = { | |
| 'agent_id': 'validation_agent', | |
| 'activity_type': 'ingest', | |
| 'entity_id': 'entity_002', | |
| 'status': 'not_valid', # invalid | |
| 'notes': 'Should fail', | |
| 'context': 'Validation test - error' | |
| } | |
| missing_field = { | |
| 'agent_id': 'validation_agent', | |
| 'activity_type': 'ingest', | |
| # 'entity_id' missing | |
| 'status': 'success', | |
| 'notes': 'Missing field', | |
| 'context': 'Validation test - missing' | |
| } | |
| print('Running validation tests...') | |
| print_test_result('Valid record insert', atomic_append_activity('activity_log.csv', valid_rec)) | |
| print_test_result('Invalid status value', atomic_append_activity('activity_log.csv', invalid_rec)) | |
| print_test_result('Missing required field', atomic_append_activity('activity_log.csv', missing_field)) | |
| print('Re-inserting valid to confirm atomicity:') | |
| print_test_result('Second valid insert', atomic_append_activity('activity_log.csv', valid_rec)) | |
| if os.path.exists('activity_log.csv.bak'): | |
| os.remove('activity_log.csv') | |
| os.rename('activity_log.csv.bak', 'activity_log.csv') | |
| if __name__ == '__main__': | |
| test_all() | |