forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_git_config.py
More file actions
76 lines (61 loc) · 2.79 KB
/
test_git_config.py
File metadata and controls
76 lines (61 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Tests for git configuration functionality."""
import os
from unittest.mock import patch
from openhands.core.config import OpenHandsConfig, load_from_env
from openhands.runtime.utils.command import get_action_execution_server_startup_command
class TestGitConfig:
"""Test git configuration functionality."""
def test_default_git_config(self):
"""Test that default git configuration is set correctly."""
config = OpenHandsConfig()
assert config.git_user_name == 'openhands'
assert config.git_user_email == 'openhands@all-hands.dev'
def test_git_config_from_env_vars(self):
"""Test that git configuration can be set via environment variables."""
with patch.dict(
os.environ,
{'GIT_USER_NAME': 'testuser', 'GIT_USER_EMAIL': 'testuser@example.com'},
):
config = OpenHandsConfig()
load_from_env(config, os.environ)
assert config.git_user_name == 'testuser'
assert config.git_user_email == 'testuser@example.com'
def test_git_config_in_command_generation(self):
"""Test that git configuration is properly passed to action execution server command."""
config = OpenHandsConfig()
config.git_user_name = 'customuser'
config.git_user_email = 'customuser@example.com'
cmd = get_action_execution_server_startup_command(
server_port=8000,
plugins=[],
app_config=config,
python_prefix=['python'],
python_executable='python',
)
# Check that git config arguments are in the command
assert '--git-user-name' in cmd
assert 'customuser' in cmd
assert '--git-user-email' in cmd
assert 'customuser@example.com' in cmd
def test_git_config_with_special_characters(self):
"""Test that git configuration handles special characters correctly."""
config = OpenHandsConfig()
config.git_user_name = 'User With Spaces'
config.git_user_email = 'user+tag@example.com'
cmd = get_action_execution_server_startup_command(
server_port=8000,
plugins=[],
app_config=config,
python_prefix=['python'],
python_executable='python',
)
assert 'User With Spaces' in cmd
assert 'user+tag@example.com' in cmd
def test_git_config_empty_values(self):
"""Test behavior with empty git configuration values."""
with patch.dict(os.environ, {'GIT_USER_NAME': '', 'GIT_USER_EMAIL': ''}):
config = OpenHandsConfig()
load_from_env(config, os.environ)
# Empty values should fall back to defaults
assert config.git_user_name == 'openhands'
assert config.git_user_email == 'openhands@all-hands.dev'