|
4 | 4 | from botocore.exceptions import ClientError |
5 | 5 |
|
6 | 6 | from sdgym._run_benchmark.upload_benchmark_results import ( |
7 | | - get_run_name, |
8 | 7 | get_run_name_and_s3_vars, |
9 | 8 | main, |
10 | | - parse_args, |
11 | 9 | upload_already_done, |
12 | 10 | upload_results, |
13 | 11 | write_uploaded_marker, |
14 | 12 | ) |
15 | 13 | from sdgym.s3 import S3_REGION |
16 | 14 |
|
17 | 15 |
|
18 | | -@patch('sdgym._run_benchmark.upload_benchmark_results.argparse.ArgumentParser') |
19 | | -def test_parse_args(mock_argparse): |
20 | | - """Test the `parse_args` method.""" |
21 | | - # Setup |
22 | | - parser = mock_argparse.return_value |
23 | | - parser.parse_args.return_value = Mock(date='01-07-2025') |
24 | | - mock_argparse.return_value.add_argument = Mock() |
25 | | - |
26 | | - # Run |
27 | | - args = parse_args() |
28 | | - |
29 | | - # Assert |
30 | | - assert args.date == '01-07-2025' |
31 | | - parser.add_argument.assert_called_once_with( |
32 | | - '--date', type=str, help='Benchmark date (YYYY-MM-DD)' |
33 | | - ) |
34 | | - parser.parse_args.assert_called_once() |
35 | | - |
36 | | - |
37 | | -def test_get_run_name(): |
38 | | - """Test the `get_run_name` method.""" |
39 | | - # Setup |
40 | | - expected_error_message = 'Invalid date format: invalid-date. Expected YYYY-MM-DD.' |
41 | | - |
42 | | - # Run and Assert |
43 | | - assert get_run_name('2023-10-01') == 'SDGym_results_10_01_2023' |
44 | | - with pytest.raises(ValueError, match=expected_error_message): |
45 | | - get_run_name('invalid-date') |
46 | | - |
47 | | - |
48 | 16 | def test_write_uploaded_marker(): |
49 | 17 | """Test the `write_uploaded_marker` method.""" |
50 | 18 | # Setup |
@@ -92,41 +60,40 @@ def test_upload_already_done(): |
92 | 60 | assert result_false is False |
93 | 61 |
|
94 | 62 |
|
95 | | -@patch('sdgym._run_benchmark.upload_benchmark_results.get_run_name') |
96 | 63 | @patch('sdgym._run_benchmark.upload_benchmark_results.boto3.client') |
97 | 64 | @patch('sdgym._run_benchmark.upload_benchmark_results.parse_s3_path') |
98 | 65 | @patch('sdgym._run_benchmark.upload_benchmark_results.OUTPUT_DESTINATION_AWS') |
99 | | -@patch('sdgym._run_benchmark.upload_benchmark_results.parse_args') |
| 66 | +@patch('sdgym._run_benchmark.upload_benchmark_results.get_latest_run_from_file') |
100 | 67 | def test_get_run_name_and_s3_vars( |
101 | | - mock_parse_args, |
| 68 | + mock_get_latest_run_from_file, |
102 | 69 | mock_output_destination_aws, |
103 | 70 | mock_parse_s3_path, |
104 | 71 | mock_boto_client, |
105 | | - mock_get_run_name, |
106 | 72 | ): |
107 | 73 | """Test the `get_run_name_and_s3_vars` method.""" |
108 | 74 | # Setup |
109 | | - mock_parse_args.return_value.date = '2023-10-01' |
110 | 75 | aws_access_key_id = 'my_access_key' |
111 | 76 | aws_secret_access_key = 'my_secret_key' |
112 | 77 | expected_result = ('SDGym_results_10_01_2023', 's3_client', 'bucket', 'prefix') |
113 | | - mock_get_run_name.return_value = 'SDGym_results_10_01_2023' |
114 | 78 | mock_boto_client.return_value = 's3_client' |
115 | 79 | mock_parse_s3_path.return_value = ('bucket', 'prefix') |
| 80 | + mock_get_latest_run_from_file.return_value = 'SDGym_results_10_01_2023' |
116 | 81 |
|
117 | 82 | # Run |
118 | 83 | result = get_run_name_and_s3_vars(aws_access_key_id, aws_secret_access_key) |
119 | 84 |
|
120 | 85 | # Assert |
121 | 86 | assert result == expected_result |
122 | | - mock_get_run_name.assert_called_once_with('2023-10-01') |
123 | 87 | mock_boto_client.assert_called_once_with( |
124 | 88 | 's3', |
125 | 89 | aws_access_key_id=aws_access_key_id, |
126 | 90 | aws_secret_access_key=aws_secret_access_key, |
127 | 91 | region_name=S3_REGION, |
128 | 92 | ) |
129 | 93 | mock_parse_s3_path.assert_called_once_with(mock_output_destination_aws) |
| 94 | + mock_get_latest_run_from_file.assert_called_once_with( |
| 95 | + 's3_client', 'bucket', 'prefix_BENCHMARK_DATES.json' |
| 96 | + ) |
130 | 97 |
|
131 | 98 |
|
132 | 99 | @patch('sdgym._run_benchmark.upload_benchmark_results.SDGymResultsExplorer') |
@@ -202,7 +169,7 @@ def test_upload_results_not_all_runs_complete( |
202 | 169 | ) |
203 | 170 |
|
204 | 171 | # Assert |
205 | | - mock_logger.info.assert_called_once_with(f'Run {run_name} is not complete yet. Exiting.') |
| 172 | + mock_logger.warning.assert_called_once_with(f'Run {run_name} is not complete yet. Exiting.') |
206 | 173 | mock_sdgym_results_explorer.assert_called_once_with( |
207 | 174 | mock_output_destination_aws, |
208 | 175 | aws_access_key_id=aws_access_key_id, |
|
0 commit comments