示例#1
0
def test_save_results_saves_epochs(hyperopt, tmpdir, caplog) -> None:

    hyperopt.results_file = Path(tmpdir / 'ut_results.fthypt')

    hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {})
    assert log_has_re("Hyperopt file .* not found.", caplog)
    assert hyperopt_epochs == ([], 0)

    # Test writing to temp dir and reading again
    epochs = create_results()

    caplog.set_level(logging.DEBUG)

    for epoch in epochs:
        hyperopt._save_result(epoch)
    assert log_has(f"1 epoch saved to '{hyperopt.results_file}'.", caplog)

    hyperopt._save_result(epochs[0])
    assert log_has(f"2 epochs saved to '{hyperopt.results_file}'.", caplog)

    hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {})
    assert len(hyperopt_epochs) == 2
    assert hyperopt_epochs[1] == 2
    assert len(hyperopt_epochs[0]) == 2

    result_gen = HyperoptTools._read_results(hyperopt.results_file, 1)
    epoch = next(result_gen)
    assert len(epoch) == 1
    assert epoch[0] == epochs[0]
    epoch = next(result_gen)
    assert len(epoch) == 1
    epoch = next(result_gen)
    assert len(epoch) == 0
    with pytest.raises(StopIteration):
        next(result_gen)
示例#2
0
def test_read_results_returns_epochs(mocker, hyperopt, testdatadir, caplog) -> None:
    epochs = create_results(mocker, hyperopt, testdatadir)
    mock_load = mocker.patch('freqtrade.optimize.hyperopt_tools.load', return_value=epochs)
    results_file = testdatadir / 'optimize' / 'ut_results.pickle'
    hyperopt_epochs = HyperoptTools._read_results(results_file)
    assert log_has(f"Reading epochs from '{results_file}'", caplog)
    assert hyperopt_epochs == epochs
    mock_load.assert_called_once()