Skip to main content
Glama

Google Calendar MCP Server

run_tests.py5.42 kB
#!/usr/bin/env python3 import os import sys import subprocess import argparse from pathlib import Path def run_tests(mode='mock', test_pattern=None, verbose=False, coverage=False): # 環境変数の設定 if mode == 'real_api': os.environ['USE_REAL_API'] = 'true' print("🔴 実際のGoogle APIを使用してテストを実行します") print("⚠️ 注意: 実際のカレンダーにテスト用イベントが作成される可能性があります") else: os.environ['USE_REAL_API'] = 'false' print("🟢 モックを使用してテストを実行します") # pytestコマンドの構築 cmd = ['pytest'] if verbose: cmd.append('-v') if coverage: cmd.extend(['--cov=src/tools', '--cov-report=html', '--cov-report=term']) if test_pattern: # パスがtests/で始まっていない場合は追加 if not test_pattern.startswith('tests/'): cmd.append(f'tests/{test_pattern}') else: cmd.append(test_pattern) else: cmd.append('tests/') # モードに応じてマーカーを設定 if mode == 'mock': cmd.extend(['-m', 'not real_api']) elif mode == 'real_api': cmd.extend(['-m', 'real_api']) print(f"実行コマンド: {' '.join(cmd)}") print("-" * 50) # テスト実行 try: # 現在の環境変数を取得し、USE_REAL_APIを追加 env = os.environ.copy() env['USE_REAL_API'] = 'true' if mode == 'real_api' else 'false' result = subprocess.run(cmd, check=True, env=env) print("\n✅ テストが正常に完了しました") if coverage and mode == 'mock': print("📊 カバレッジレポートが htmlcov/index.html に生成されました") return True except subprocess.CalledProcessError as e: if e.returncode == 5: # テストが選択されなかった場合(環境変数未設定など) print(f"\n⚠️ テストが選択されませんでした (終了コード: {e.returncode})") if mode == 'real_api': print("💡 実際のAPIモードを使用するには、必要な環境変数が設定されていることを確認してください") return True # 警告として扱う else: print(f"\n❌ テストが失敗しました (終了コード: {e.returncode})") return False except KeyboardInterrupt: print("\n⏹️ テストが中断されました") return False def main(): parser = argparse.ArgumentParser(description='Google Calendar MCP テスト実行スクリプト') parser.add_argument( '--mode', choices=['mock', 'real_api'], default='mock', help='テストモード (デフォルト: mock)' ) parser.add_argument( '--test', type=str, help='実行するテストのパターン (例: test_calendar_tools.py::TestListCalendars)' ) parser.add_argument( '--verbose', '-v', action='store_true', help='詳細出力' ) parser.add_argument( '--coverage', '-c', action='store_true', help='カバレッジレポート生成 (mockモードのみ)' ) parser.add_argument( '--list-modes', action='store_true', help='利用可能なモードを表示' ) args = parser.parse_args() if args.list_modes: print("利用可能なテストモード:") print(" mock - モックを使用したテスト (デフォルト)") print(" real_api - 実際のGoogle APIを使用したテスト") print("\n使用例:") print(" python run_tests.py --mode mock") print(" python run_tests.py --mode real_api") print(" python run_tests.py --mode mock --coverage") print(" python run_tests.py --mode real_api --test test_calendar_tools.py::TestRealAPI") return # プロジェクトルートに移動 project_root = Path(__file__).parent os.chdir(project_root) # 環境変数の確認 if args.mode == 'real_api': required_env_vars = [ 'GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET', 'GOOGLE_PROJECT_ID', 'GOOGLE_REFRESH_TOKEN' ] missing_vars = [var for var in required_env_vars if not os.getenv(var)] if missing_vars: print(f"❌ 実際のAPIを使用するには以下の環境変数が必要です: {', '.join(missing_vars)}") print("環境変数を設定してから再実行してください") print("\n設定例:") print("export GOOGLE_CLIENT_ID=\"your_client_id\"") print("export GOOGLE_CLIENT_SECRET=\"your_client_secret\"") print("export GOOGLE_PROJECT_ID=\"your_project_id\"") print("export GOOGLE_REFRESH_TOKEN=\"your_refresh_token\"") print("\nまたは、.envファイルに設定することもできます") return False # テスト実行 success = run_tests( mode=args.mode, test_pattern=args.test, verbose=args.verbose, coverage=args.coverage ) sys.exit(0 if success else 1) if __name__ == '__main__': main()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/YusukeYoshiyama/google-calendar-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server