55"""Unit tests for the LoadAndTrainQRF plugin."""
66
77import iris
8- import joblib
98import numpy as np
109import pandas as pd
1110import pytest
@@ -380,10 +379,6 @@ def test_load_and_train_qrf(
380379 truth_path = truth_creation (tmp_path )
381380 file_paths = [forecast_path , truth_path ]
382381
383- model_output_dir = tmp_path / "train_qrf"
384- model_output_dir .mkdir (parents = True )
385- model_output = str (model_output_dir / "qrf_model.pkl" )
386-
387382 if include_static :
388383 ancil_path = _create_ancil_file (tmp_path , sorted (list (set (wmo_ids ))))
389384 file_paths .append (ancil_path )
@@ -407,9 +402,7 @@ def test_load_and_train_qrf(
407402 transformation = "log" ,
408403 pre_transform_addition = 1 ,
409404 )
410- plugin (file_paths , model_output = model_output )
411-
412- qrf_model = joblib .load (model_output )
405+ qrf_model = plugin (file_paths )
413406
414407 assert qrf_model .n_estimators == n_estimators
415408 assert qrf_model .max_depth == max_depth
@@ -446,10 +439,6 @@ def test_load_and_train_qrf_no_paths(tmp_path, make_files):
446439 for file_path in file_paths :
447440 (tmp_path / file_path ).mkdir (parents = True , exist_ok = True )
448441
449- model_output_dir = tmp_path / "train_qrf"
450- model_output_dir .mkdir (parents = True )
451- model_output = str (model_output_dir / "qrf_model.pkl" )
452-
453442 plugin = LoadAndTrainQRF (
454443 experiment = "latestblend" ,
455444 feature_config = feature_config ,
@@ -464,11 +453,9 @@ def test_load_and_train_qrf_no_paths(tmp_path, make_files):
464453 transformation = "log" ,
465454 pre_transform_addition = 1 ,
466455 )
467- result = plugin (file_paths , model_output = model_output )
456+ result = plugin (file_paths )
468457 # Expecting None since no valid paths are provided
469458 assert result is None
470- # Check if the model output file is not created
471- assert not (model_output_dir / "qrf_model.pkl" ).exists ()
472459
473460
474461@pytest .mark .parametrize (
@@ -491,10 +478,6 @@ def test_load_and_train_qrf_mismatches(tmp_path, cycletime, forecast_periods):
491478 tmp_path / "partition" / "truth_table/" ,
492479 ]
493480
494- model_output_dir = tmp_path / "train_qrf"
495- model_output_dir .mkdir (parents = True )
496- model_output = str (model_output_dir / "qrf_model.pkl" )
497-
498481 plugin = LoadAndTrainQRF (
499482 experiment = "latestblend" ,
500483 feature_config = feature_config ,
@@ -509,11 +492,9 @@ def test_load_and_train_qrf_mismatches(tmp_path, cycletime, forecast_periods):
509492 transformation = "log" ,
510493 pre_transform_addition = 1 ,
511494 )
512- result = plugin (file_paths , model_output = model_output )
495+ result = plugin (file_paths )
513496 # Expecting None since no valid paths are provided
514497 assert result is None
515- # Check if the model output file is not created
516- assert not (model_output_dir / "qrf_model.pkl" ).exists ()
517498
518499
519500@pytest .mark .parametrize (
@@ -581,10 +562,6 @@ def test_unexpected(
581562 truth_path = truth_creation (tmp_path )
582563 file_paths = [forecast_path , truth_path ]
583564
584- model_output_dir = tmp_path / "train_qrf"
585- model_output_dir .mkdir (parents = True )
586- model_output = str (model_output_dir / "qrf_model.pkl" )
587-
588565 # Create an instance of LoadAndTrainQRF with the required parameters
589566 plugin = LoadAndTrainQRF (
590567 experiment = "latestblend" ,
@@ -603,7 +580,7 @@ def test_unexpected(
603580
604581 if exception == "non_matching_truth" :
605582 with pytest .raises (IOError , match = "The requested filepath" ):
606- plugin (file_paths , model_output = model_output )
583+ plugin (file_paths )
607584 elif exception == "missing_static_feature" :
608585 feature_config = {
609586 "wind_speed_at_10m" : ["mean" , "std" ],
@@ -622,13 +599,13 @@ def test_unexpected(
622599 plugin .process (file_paths = file_paths )
623600 elif exception == "no_percentile_realization" :
624601 with pytest .raises (ValueError , match = "The forecast parquet file" ):
625- plugin (file_paths , model_output = model_output )
602+ plugin (file_paths )
626603 elif exception == "alternative_forecast_period" :
627604 with pytest .raises (ValueError , match = "The forecast_periods argument" ):
628- plugin (file_paths , model_output = model_output )
605+ plugin (file_paths )
629606 elif exception == "no_quantile_forest_package" :
630607 plugin .quantile_forest_installed = False
631- result = plugin (file_paths , model_output = model_output )
608+ result = plugin (file_paths )
632609 assert result is None
633610 else :
634611 raise ValueError (f"Unknown exception type: { exception } " )
0 commit comments