mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Apply marketplace path test formatting
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,37 +15,37 @@ from openhands.storage.data_models.settings import Settings
|
||||
def test_settings_from_config():
|
||||
# Mock configuration
|
||||
mock_app_config = OpenHandsConfig(
|
||||
default_agent='test-agent',
|
||||
default_agent="test-agent",
|
||||
max_iterations=100,
|
||||
security=SecurityConfig(
|
||||
security_analyzer='test-analyzer',
|
||||
security_analyzer="test-analyzer",
|
||||
confirmation_mode=True,
|
||||
),
|
||||
llms={
|
||||
'llm': LLMConfig(
|
||||
model='test-model',
|
||||
api_key=SecretStr('test-key'),
|
||||
base_url='https://test.example.com',
|
||||
"llm": LLMConfig(
|
||||
model="test-model",
|
||||
api_key=SecretStr("test-key"),
|
||||
base_url="https://test.example.com",
|
||||
)
|
||||
},
|
||||
sandbox=SandboxConfig(remote_runtime_resource_factor=2),
|
||||
)
|
||||
|
||||
with patch(
|
||||
'openhands.storage.data_models.settings.load_openhands_config',
|
||||
"openhands.storage.data_models.settings.load_openhands_config",
|
||||
return_value=mock_app_config,
|
||||
):
|
||||
settings = Settings.from_config()
|
||||
|
||||
assert settings is not None
|
||||
assert settings.language == 'en'
|
||||
assert settings.agent == 'test-agent'
|
||||
assert settings.language == "en"
|
||||
assert settings.agent == "test-agent"
|
||||
assert settings.max_iterations == 100
|
||||
assert settings.security_analyzer == 'test-analyzer'
|
||||
assert settings.security_analyzer == "test-analyzer"
|
||||
assert settings.confirmation_mode is True
|
||||
assert settings.llm_model == 'test-model'
|
||||
assert settings.llm_api_key.get_secret_value() == 'test-key'
|
||||
assert settings.llm_base_url == 'https://test.example.com'
|
||||
assert settings.llm_model == "test-model"
|
||||
assert settings.llm_api_key.get_secret_value() == "test-key"
|
||||
assert settings.llm_base_url == "https://test.example.com"
|
||||
assert settings.remote_runtime_resource_factor == 2
|
||||
assert not settings.secrets_store.provider_tokens
|
||||
|
||||
@@ -53,22 +53,22 @@ def test_settings_from_config():
|
||||
def test_settings_from_config_no_api_key():
|
||||
# Mock configuration without API key
|
||||
mock_app_config = OpenHandsConfig(
|
||||
default_agent='test-agent',
|
||||
default_agent="test-agent",
|
||||
max_iterations=100,
|
||||
security=SecurityConfig(
|
||||
security_analyzer='test-analyzer',
|
||||
security_analyzer="test-analyzer",
|
||||
confirmation_mode=True,
|
||||
),
|
||||
llms={
|
||||
'llm': LLMConfig(
|
||||
model='test-model', api_key=None, base_url='https://test.example.com'
|
||||
"llm": LLMConfig(
|
||||
model="test-model", api_key=None, base_url="https://test.example.com"
|
||||
)
|
||||
},
|
||||
sandbox=SandboxConfig(remote_runtime_resource_factor=2),
|
||||
)
|
||||
|
||||
with patch(
|
||||
'openhands.storage.data_models.settings.load_openhands_config',
|
||||
"openhands.storage.data_models.settings.load_openhands_config",
|
||||
return_value=mock_app_config,
|
||||
):
|
||||
settings = Settings.from_config()
|
||||
@@ -77,29 +77,29 @@ def test_settings_from_config_no_api_key():
|
||||
|
||||
def test_settings_handles_sensitive_data():
|
||||
settings = Settings(
|
||||
language='en',
|
||||
agent='test-agent',
|
||||
language="en",
|
||||
agent="test-agent",
|
||||
max_iterations=100,
|
||||
security_analyzer='test-analyzer',
|
||||
security_analyzer="test-analyzer",
|
||||
confirmation_mode=True,
|
||||
llm_model='test-model',
|
||||
llm_api_key='test-key',
|
||||
llm_base_url='https://test.example.com',
|
||||
llm_model="test-model",
|
||||
llm_api_key="test-key",
|
||||
llm_base_url="https://test.example.com",
|
||||
remote_runtime_resource_factor=2,
|
||||
)
|
||||
|
||||
assert str(settings.llm_api_key) == '**********'
|
||||
assert settings.llm_api_key.get_secret_value() == 'test-key'
|
||||
assert str(settings.llm_api_key) == "**********"
|
||||
assert settings.llm_api_key.get_secret_value() == "test-key"
|
||||
|
||||
|
||||
def test_convert_to_settings():
|
||||
settings_with_token_data = Settings(
|
||||
llm_api_key='test-key',
|
||||
llm_api_key="test-key",
|
||||
)
|
||||
|
||||
settings = convert_to_settings(settings_with_token_data)
|
||||
|
||||
assert settings.llm_api_key.get_secret_value() == 'test-key'
|
||||
assert settings.llm_api_key.get_secret_value() == "test-key"
|
||||
|
||||
|
||||
def test_settings_no_pydantic_frozen_field_warning():
|
||||
@@ -110,7 +110,7 @@ def test_settings_no_pydantic_frozen_field_warning():
|
||||
See: https://github.com/All-Hands-AI/infra/issues/860
|
||||
"""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
warnings.simplefilter("always")
|
||||
|
||||
# Re-import to trigger any warnings during model definition
|
||||
import importlib
|
||||
@@ -122,11 +122,11 @@ def test_settings_no_pydantic_frozen_field_warning():
|
||||
# Check for warnings containing 'frozen' which would indicate
|
||||
# incorrect usage of frozen=True in Field()
|
||||
frozen_warnings = [
|
||||
warning for warning in w if 'frozen' in str(warning.message).lower()
|
||||
warning for warning in w if "frozen" in str(warning.message).lower()
|
||||
]
|
||||
|
||||
assert len(frozen_warnings) == 0, (
|
||||
f'Pydantic frozen field warnings found: {[str(w.message) for w in frozen_warnings]}'
|
||||
f"Pydantic frozen field warnings found: {[str(w.message) for w in frozen_warnings]}"
|
||||
)
|
||||
|
||||
|
||||
@@ -138,8 +138,8 @@ def test_settings_marketplace_path_default():
|
||||
|
||||
def test_settings_marketplace_path_custom():
|
||||
"""Test that marketplace_path can be set to a custom value."""
|
||||
settings = Settings(marketplace_path='marketplaces/custom.json')
|
||||
assert settings.marketplace_path == 'marketplaces/custom.json'
|
||||
settings = Settings(marketplace_path="marketplaces/custom.json")
|
||||
assert settings.marketplace_path == "marketplaces/custom.json"
|
||||
|
||||
|
||||
def test_settings_marketplace_path_none_explicit():
|
||||
@@ -149,27 +149,26 @@ def test_settings_marketplace_path_none_explicit():
|
||||
|
||||
|
||||
def test_settings_marketplace_path_trims_whitespace():
|
||||
settings = Settings(marketplace_path=' marketplaces/custom.json ')
|
||||
assert settings.marketplace_path == 'marketplaces/custom.json'
|
||||
settings = Settings(marketplace_path=" marketplaces/custom.json ")
|
||||
assert settings.marketplace_path == "marketplaces/custom.json"
|
||||
|
||||
|
||||
def test_settings_marketplace_path_blank_string_maps_to_none():
|
||||
settings = Settings(marketplace_path=' ')
|
||||
settings = Settings(marketplace_path=" ")
|
||||
assert settings.marketplace_path is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'value',
|
||||
"value",
|
||||
[
|
||||
'/marketplaces/default.json',
|
||||
'../secret.json',
|
||||
'owner/repo:path/to/marketplace.json',
|
||||
'marketplaces\\default.json',
|
||||
'marketplaces/default',
|
||||
'marketplaces/%2e%2e/secret.json',
|
||||
"/marketplaces/default.json",
|
||||
"../secret.json",
|
||||
"owner/repo:path/to/marketplace.json",
|
||||
"marketplaces\\default.json",
|
||||
"marketplaces/default",
|
||||
"marketplaces/%2e%2e/secret.json",
|
||||
],
|
||||
)
|
||||
def test_settings_marketplace_path_rejects_invalid_values(value: str):
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(marketplace_path=value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user