#!/usr/bin/env python3 """ Test runner for Sigma API scripts """ import unittest import sys import os def run_all_tests(): """Run all unit tests""" # Add current directory to path test_dir = os.path.join(os.path.dirname(__file__), 'tests') # Discover and run tests loader = unittest.TestLoader() suite = loader.discover(test_dir, pattern='test_*.py') # Run tests with verbose output runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) # Return exit code based on test results return 0 if result.wasSuccessful() else 1 def run_specific_test(test_module): """Run tests for a specific module""" test_dir = os.path.join(os.path.dirname(__file__), 'tests') test_file = f'test_{test_module}.py' if not os.path.exists(os.path.join(test_dir, test_file)): print(f"Test file {test_file} not found") return 1 # Import and run specific test loader = unittest.TestLoader() suite = loader.loadTestsFromName(f'tests.test_{test_module}') runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) return 0 if result.wasSuccessful() else 1 def main(): """Main test runner""" if len(sys.argv) > 1: test_module = sys.argv[1] if test_module == '--help': print("Usage:") print(" python run_tests.py # Run all tests") print(" python run_tests.py # Run specific test module") print("") print("Available test modules:") print(" sigma_api_client") print(" user_management") print(" team_management") print(" snowflake_object_manager") print(" config") return 0 else: return run_specific_test(test_module) else: return run_all_tests() if __name__ == '__main__': sys.exit(main())