66from datetime import datetime
77import os
88import pandas as pd
9+ from tests .test_constants import PROBLEM_TYPE
910
1011
11- @pytest .fixture
12+ @pytest .fixture ( scope = "session" )
1213def runner ():
1314 return CliRunner ()
1415
1516
17+ @pytest .fixture (scope = "session" )
18+ def temp_dir (tmp_path_factory ):
19+ temp_dir = tmp_path_factory .mktemp ("session_temp" )
20+ yield temp_dir
21+
22+
1623@pytest .fixture
17- def temp_dir (tmp_path ):
18- yield tmp_path
24+ def setup_run_environment (temp_dir ):
25+ # Create necessary directories and files
26+ (temp_dir / "input" / "data" ).mkdir (parents = True , exist_ok = True )
27+ (temp_dir / "input" / "configuration" ).mkdir (parents = True , exist_ok = True )
28+ (temp_dir / "trained_models" ).mkdir (exist_ok = True )
29+
30+ # Create a dummy CSV file with some data
31+ df = pd .DataFrame (
32+ {
33+ "target" : [0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 ],
34+ "feature1" : [1 , 2 , 3 , 4 , 6 , 7 , 8 , 3 , 6 , 1 ],
35+ "feature2" : [5 , 6 , 7 , 8 , 3 , 4 , 6 , 7 , 3 , 1 ],
36+ }
37+ )
38+ df .to_csv (temp_dir / "input" / "data" / "AA_test.csv" , index = False )
39+
40+ # Create a dummy JSON configuration file
41+ config = {
42+ "target" : "target" ,
43+ "features" : ["feature1" , "feature2" ],
44+ "model_params" : {},
45+ }
46+
47+ with open (temp_dir / "input" / "configuration" / "AA_config.json" , "w" ) as f :
48+ json .dump (config , f )
49+
50+ # Change to the temp directory
51+ original_dir = os .getcwd ()
52+ os .chdir (temp_dir )
53+ yield temp_dir
54+ # Change back to the original directory after the test
55+ os .chdir (original_dir )
1956
2057
2158def test_version (runner ):
@@ -25,7 +62,7 @@ def test_version(runner):
2562
2663
2764# Test cli_init
28- def test_init_command (runner , temp_dir ):
65+ def test_init_command (temp_dir , runner ):
2966 result = runner .invoke (app , ["init" , "--dest" , str (temp_dir )])
3067 assert result .exit_code == 0
3168
@@ -44,7 +81,7 @@ def test_init_command(runner, temp_dir):
4481 ), "No files found in input/configuration"
4582
4683
47- def test_init_command_existing_directory (runner , temp_dir ):
84+ def test_init_command_existing_directory (temp_dir , runner ):
4885 # Create a file in the directory to simulate an existing project
4986 (temp_dir / "existing_file.txt" ).touch ()
5087
@@ -58,51 +95,15 @@ def test_init_command_existing_directory(runner, temp_dir):
5895 assert (temp_dir / "existing_file.txt" ).exists ()
5996
6097
61- @pytest .fixture
62- def setup_run_environment (temp_dir ):
63- # Create necessary directories and files
64- (temp_dir / "input" / "data" ).mkdir (parents = True )
65- (temp_dir / "input" / "configuration" ).mkdir (parents = True )
66- (temp_dir / "trained_models" ).mkdir ()
67-
68- # Create a dummy CSV file with some data
69- df = pd .DataFrame (
70- {
71- "target" : [0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 ],
72- "feature1" : [1 , 2 , 3 , 4 , 6 , 7 , 8 , 3 , 6 , 1 ],
73- "feature2" : [5 , 6 , 7 , 8 , 3 , 4 , 6 , 7 , 3 , 1 ],
74- }
75- )
76- df .to_csv (temp_dir / "input" / "data" / "test.csv" , index = False )
77-
78- # Create a dummy JSON configuration file
79- config = {
80- "target" : "target" ,
81- "features" : ["feature1" , "feature2" ],
82- "model_params" : {},
83- }
84-
85- with open (temp_dir / "input" / "configuration" / "config.json" , "w" ) as f :
86- json .dump (config , f )
87-
88- # Change to the temp directory
89- original_dir = os .getcwd ()
90- os .chdir (temp_dir )
91- yield temp_dir
92- # Change back to the original directory after the test
93- os .chdir (original_dir )
94-
95-
96- def test_run_command (setup_run_environment , caplog ):
98+ def test_run_command (setup_run_environment , runner , caplog ):
9799 # Avoid I/O error by not having any logger produce a message
98100 caplog .set_level (100000 )
99101
100- runner = CliRunner ()
101102 temp_dir = setup_run_environment
102103
103104 # Create the input sequence for test_run
104105 user_inputs = (
105- "1\n " # Select the first CSV file
106+ "1\n " # Select the first CSV file (AA_test.csv)
106107 "2\n " # Select the first JSON file (we created one in setup)
107108 "1\n " # Select the first model type (assuming it's "Explainable Boosting Machine")
108109 "test_model\n " # Enter model name
0 commit comments