|
1 |
| -from asyncio import Future |
2 | 1 | import inspect
|
| 2 | +import logging |
| 3 | +from asyncio import Future |
3 | 4 | from contextlib import nullcontext as does_not_raise
|
| 5 | +from textwrap import dedent |
4 | 6 |
|
5 | 7 | import pytest
|
6 | 8 | import pytest_asyncio
|
@@ -228,6 +230,55 @@ async def test_download_log(mocker, client):
|
228 | 230 | assert m_download.call_args == ((log_url, f"{artifacts_dir}/bitrise.log"),)
|
229 | 231 |
|
230 | 232 |
|
| 233 | +@pytest.mark.asyncio |
| 234 | +async def test_dump_perfherder_data(mocker, caplog): |
| 235 | + caplog.set_level(logging.INFO) |
| 236 | + artifacts_dir = "artifacts" |
| 237 | + |
| 238 | + # bitrise.log doesn't exist |
| 239 | + mock_is_file = mocker.patch.object(bitrise.Path, "is_file") |
| 240 | + mock_is_file.return_value = False |
| 241 | + await bitrise.dump_perfherder_data(artifacts_dir) |
| 242 | + assert "Not scanning for Perfherder data" in caplog.text |
| 243 | + |
| 244 | + # bitrise.log doesn't contain Perfherder data |
| 245 | + caplog.clear() |
| 246 | + mock_is_file.return_value = True |
| 247 | + mock_read_text = mocker.patch.object(bitrise.Path, "read_text") |
| 248 | + mock_read_text.return_value = dedent( |
| 249 | + """ |
| 250 | + INFO does not contain |
| 251 | + DEBUG any perfherder data |
| 252 | + """ |
| 253 | + ).strip() |
| 254 | + await bitrise.dump_perfherder_data(artifacts_dir) |
| 255 | + assert "Not scanning for Perfherder data" not in caplog.text |
| 256 | + assert "Found Perfherder data in" not in caplog.text |
| 257 | + |
| 258 | + # bitrise.log contains Perfherder data |
| 259 | + caplog.clear() |
| 260 | + mock_read_text.return_value = dedent( |
| 261 | + """ |
| 262 | + INFO does contain |
| 263 | + PERFHERDER_DATA {"foo": "bar"} |
| 264 | + DEBUG perfherder data |
| 265 | + PERFHERDER_DATA {"baz": 1} |
| 266 | + """ |
| 267 | + ).strip() |
| 268 | + await bitrise.dump_perfherder_data(artifacts_dir) |
| 269 | + assert "Not scanning for Perfherder data" not in caplog.text |
| 270 | + assert ( |
| 271 | + dedent( |
| 272 | + """ |
| 273 | + Found Perfherder data in artifacts/bitrise.log: |
| 274 | + PERFHERDER_DATA {"foo": "bar"} |
| 275 | + PERFHERDER_DATA {"baz": 1} |
| 276 | + """ |
| 277 | + ).strip() |
| 278 | + in caplog.text |
| 279 | + ) |
| 280 | + |
| 281 | + |
231 | 282 | @pytest.mark.asyncio
|
232 | 283 | async def test_download_file(responses, tmp_path):
|
233 | 284 | url = "https://example.com/log.txt"
|
|
0 commit comments