|
1 | 1 | from datetime import datetime, timedelta, timezone |
2 | 2 | from pathlib import Path |
3 | 3 | from unittest.mock import MagicMock |
| 4 | +from zipfile import ZipFile |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 | from pandas import DataFrame, DateOffset, Timestamp, to_datetime |
|
15 | 16 | get_latest_hyperopt_file, |
16 | 17 | load_backtest_data, |
17 | 18 | load_backtest_metadata, |
| 19 | + load_file_from_zip, |
18 | 20 | load_trades, |
19 | 21 | load_trades_from_db, |
20 | 22 | ) |
@@ -569,3 +571,22 @@ def test_calculate_max_drawdown_abs(profits, relative, highd, lowdays, result, r |
569 | 571 | assert drawdown.high_value > drawdown.low_value |
570 | 572 | assert drawdown.drawdown_abs == result |
571 | 573 | assert pytest.approx(drawdown.relative_account_drawdown) == result_rel |
| 574 | + |
| 575 | + |
| 576 | +def test_load_file_from_zip(tmp_path): |
| 577 | + with pytest.raises(ValueError, match=r"Zip file .* not found\."): |
| 578 | + load_file_from_zip(tmp_path / "test.zip", "testfile.txt") |
| 579 | + |
| 580 | + (tmp_path / "testfile.zip").touch() |
| 581 | + with pytest.raises(ValueError, match=r"Bad zip file.*"): |
| 582 | + load_file_from_zip(tmp_path / "testfile.zip", "testfile.txt") |
| 583 | + |
| 584 | + zip_file = tmp_path / "testfile2.zip" |
| 585 | + with ZipFile(zip_file, "w") as zipf: |
| 586 | + zipf.writestr("testfile.txt", "testfile content") |
| 587 | + |
| 588 | + content = load_file_from_zip(zip_file, "testfile.txt") |
| 589 | + assert content.decode("utf-8") == "testfile content" |
| 590 | + |
| 591 | + with pytest.raises(ValueError, match=r"File .* not found in zip.*"): |
| 592 | + load_file_from_zip(zip_file, "testfile55.txt") |
0 commit comments