Skip to content

Commit f56134a

Browse files
authored
fix: replace print/silent exceptions with loguru logger and skip generator tests without API key (#176)
1 parent 0b915ff commit f56134a

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

openjudge/utils/prompt_format_checker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
from pathlib import Path
3434
from typing import Dict, List, Optional, Tuple
3535

36+
from loguru import logger
37+
3638

3739
class Language(Enum):
3840
"""Language enum for prompt validation."""
@@ -453,7 +455,7 @@ def extract_prompts_from_file(self, file_path: str) -> Dict[str, str]:
453455
try:
454456
tree = ast.parse(content)
455457
except SyntaxError as e:
456-
print(f" ⚠️ Syntax error in {file_path}: {e}")
458+
logger.warning(f"Syntax error in {file_path}: {e}")
457459
return prompts
458460

459461
for node in ast.walk(tree):
@@ -473,7 +475,7 @@ def extract_prompts_from_file(self, file_path: str) -> Dict[str, str]:
473475
if extracted:
474476
prompts[var_name] = extracted
475477
except Exception:
476-
pass
478+
logger.debug(f"Failed to extract prompt from variable {var_name} in {file_path}")
477479

478480
return prompts
479481

tests/generator/test_iterative_rubric.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"""
3434

3535
import asyncio
36+
import os
3637
from copy import deepcopy
3738

3839
import pytest
@@ -48,6 +49,15 @@
4849
from openjudge.models.openai_chat_model import OpenAIChatModel
4950
from openjudge.models.schema.prompt_template import LanguageEnum
5051

52+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
53+
OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL")
54+
RUN_INTEGRATION_TESTS = bool(OPENAI_API_KEY and OPENAI_BASE_URL)
55+
56+
pytestmark = pytest.mark.skipif(
57+
not RUN_INTEGRATION_TESTS,
58+
reason="Requires OPENAI_API_KEY and OPENAI_BASE_URL environment variables",
59+
)
60+
5161
# pylint: disable=line-too-long
5262

5363
# =============================================================================

tests/generator/test_simple_rubric.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"""
3131

3232
import asyncio
33+
import os
3334

3435
import pytest
3536
from loguru import logger
@@ -44,6 +45,15 @@
4445
from openjudge.models.openai_chat_model import OpenAIChatModel
4546
from openjudge.models.schema.prompt_template import LanguageEnum
4647

48+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
49+
OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL")
50+
RUN_INTEGRATION_TESTS = bool(OPENAI_API_KEY and OPENAI_BASE_URL)
51+
52+
pytestmark = pytest.mark.skipif(
53+
not RUN_INTEGRATION_TESTS,
54+
reason="Requires OPENAI_API_KEY and OPENAI_BASE_URL environment variables",
55+
)
56+
4757
# =============================================================================
4858
# Test Data
4959
# =============================================================================

0 commit comments

Comments
 (0)