Skip to content

Commit 7d9e44b

Browse files
committed
update comment
1 parent 966728a commit 7d9e44b

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

tests/test_get_result_web.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,78 @@
1111
from examples.atlas.get_result_web import check_exist, check_identical_strings, spilt_web, write_ans
1212

1313

14-
# 测试 check_identical_strings 函数
14+
# Test check_identical_strings function
1515
def test_check_identical_strings():
16-
# 测试相同字符串的情况
16+
# Test case for identical strings
1717
assert check_identical_strings(["test", "test", "test"]) == "test"
1818

19-
# 测试空列表
19+
# Test case for empty list
2020
with pytest.raises(ValueError, match="The list is empty"):
2121
check_identical_strings([])
2222

23-
# 测试不同字符串
23+
# Test case for different strings
2424
with pytest.raises(ValueError, match="Different strings found"):
2525
check_identical_strings(["test1", "test2"])
2626

2727

28-
# 测试 spilt_web 函数
28+
# Test spilt_web function
2929
def test_spilt_web():
30-
# 测试有效的URL
30+
# Test valid URL
3131
url = "https://wandb.ai/user123/project456/sweeps/abc789"
3232
result = spilt_web(url)
3333
assert result == ("user123", "project456", "abc789")
3434

35-
# 测试无效的URL
35+
# Test invalid URL
3636
invalid_url = "https://invalid-url.com"
3737
assert spilt_web(invalid_url) is None
3838

3939

40-
# 测试 check_exist 函数
40+
# Test check_exist function
4141
def test_check_exist(tmp_path):
42-
# 创建临时测试目录
42+
# Create temporary test directory
4343
results_dir = tmp_path / "results" / "params"
4444
results_dir.mkdir(parents=True)
4545

46-
# 测试空目录
46+
# Test empty directory
4747
assert check_exist(str(tmp_path)) is False
4848

49-
# 创建测试文件
49+
# Create test files
5050
(results_dir / "file1.txt").touch()
5151
(results_dir / "file2.txt").touch()
5252

53-
# 测试有多个文件的情况
53+
# Test case with multiple files
5454
assert check_exist(str(tmp_path)) is True
5555

5656

57-
# 创建测试固定装置
57+
# Create test fixed data
5858
@pytest.fixture
5959
def sample_df():
6060
return pd.DataFrame({"id": ["run1", "run2", "run3"], "metric": [0.8, 0.9, 0.7]})
6161

6262

63-
# 如果需要模拟wandb API,可以使用mock
63+
# use mock to simulate wandb API
6464
@pytest.fixture
6565
def mock_wandb(mocker):
6666
mock_api = mocker.patch("wandb.Api")
67-
# 这里可以设置mock的返回值
67+
# set mock return values
6868
return mock_api
6969

7070

71-
# 添加一个mock fixture来模拟ATLASDIR
71+
# Add a mock fixture to simulate ATLASDIR
7272
@pytest.fixture(autouse=True)
7373
def mock_settings(tmp_path, monkeypatch):
7474
"""Mock ATLASDIR and METADIR settings for tests."""
75-
# 创建临时目录
75+
# Create temporary directory
7676
mock_atlas_dir = tmp_path / "atlas"
7777
mock_meta_dir = tmp_path / "meta"
7878
mock_atlas_dir.mkdir(parents=True)
7979
mock_meta_dir.mkdir(parents=True)
8080

81-
# 设置环境变量
81+
# Set environment variables
8282
monkeypatch.setenv("ATLAS_DIR", str(mock_atlas_dir))
8383
monkeypatch.setenv("META_DIR", str(mock_meta_dir))
8484

85-
# 如果直接从dance.settings导入,也替换这些值
85+
# If import directly from dance.settings, also replace these values
8686
monkeypatch.setattr("examples.atlas.get_result_web.ATLASDIR", mock_atlas_dir)
8787
monkeypatch.setattr("examples.atlas.get_result_web.METADIR", mock_meta_dir)
8888

@@ -94,7 +94,7 @@ def test_write_ans(mock_settings):
9494
sweep_results_dir.mkdir(parents=True)
9595
output_file = sweep_results_dir / "heart_ans.csv"
9696

97-
# 创建初始数据
97+
# Create initial data
9898
existing_data = pd.DataFrame({
9999
'Dataset_id': ['dataset1', 'dataset2'],
100100
'cta_actinn': ['url1', 'url2'],
@@ -103,35 +103,35 @@ def test_write_ans(mock_settings):
103103
})
104104
existing_data.to_csv(output_file)
105105

106-
# 测试数据:包含较低分数和较高分数的情况
106+
# Test data: include lower score and higher score
107107
new_data = pd.DataFrame({
108108
'Dataset_id': ['dataset1', 'dataset2'],
109109
'cta_actinn': ['url1_new', 'url2_new'],
110110
'cta_actinn_best_yaml': ['yaml1_new', 'yaml2_new'],
111-
'cta_actinn_best_res': [0.9, 0.6] # dataset1更高分数,dataset2更低分数
111+
'cta_actinn_best_res': [0.9, 0.6] # dataset1 higher score, dataset2 lower score
112112
})
113113

114114
write_ans("heart", new_data, output_file)
115115

116-
# 验证结果
116+
# Verify results
117117
result_df = pd.read_csv(output_file)
118118

119-
# 验证高分数更新成功
119+
# Verify high score update success
120120
dataset1_row = result_df[result_df['Dataset_id'] == 'dataset1'].iloc[0]
121121
assert dataset1_row['cta_actinn_best_res'] == 0.9
122122
assert dataset1_row['cta_actinn'] == 'url1_new'
123123
assert dataset1_row['cta_actinn_best_yaml'] == 'yaml1_new'
124124

125-
# 验证低分数保持不变
125+
# Verify low score remains unchanged
126126
dataset2_row = result_df[result_df['Dataset_id'] == 'dataset2'].iloc[0]
127127
assert dataset2_row['cta_actinn_best_res'] == 0.7
128128
assert dataset2_row['cta_actinn'] == 'url2'
129129
assert dataset2_row['cta_actinn_best_yaml'] == 'yaml2'
130130

131131

132-
# 测试完全新的数据写入(文件不存在的情况)
132+
# Test completely new data write (file does not exist)
133133
def test_write_ans_new_file(mock_settings):
134-
# 使用mock_settings而不是创建新的临时目录
134+
# Use mock_settings instead of creating new temporary directory
135135
sweep_results_dir = mock_settings / "sweep_results"
136136
sweep_results_dir.mkdir(parents=True)
137137
output_file = sweep_results_dir / "new_heart_ans.csv"
@@ -143,9 +143,9 @@ def test_write_ans_new_file(mock_settings):
143143
'cta_actinn_best_res': [0.8, 0.9]
144144
})
145145

146-
# 测试写入新文件
146+
# Test write to new file
147147

148-
# 验证文件被创建并包含正确的数据
148+
# Verify file is created and contains correct data
149149
write_ans("heart", new_data, output_file)
150150
assert output_file.exists()
151151

0 commit comments

Comments
 (0)