1414
1515def test_schedule_parser ():
1616 """Test the schedule parser functionality."""
17- try :
18- from praisonai .scheduler import ScheduleParser
19-
20- # Test various schedule expressions
21- test_cases = [
22- ("daily" , 86400 ),
23- ("hourly" , 3600 ),
24- ("*/30m" , 1800 ),
25- ("*/6h" , 21600 ),
26- ("60" , 60 ),
27- ("3600" , 3600 )
28- ]
29-
30- print ("Testing ScheduleParser..." )
31- for expr , expected in test_cases :
32- result = ScheduleParser .parse (expr )
33- assert result == expected , f"Expected { expected } , got { result } for '{ expr } '"
34- print (f" ✓ '{ expr } ' -> { result } seconds" )
35-
36- print ("ScheduleParser tests passed!" )
37- return True
38-
39- except Exception as e :
40- print (f"ScheduleParser test failed: { e } " )
41- return False
17+ from praisonai .scheduler import ScheduleParser
18+
19+ # Test various schedule expressions
20+ test_cases = [
21+ ("daily" , 86400 ),
22+ ("hourly" , 3600 ),
23+ ("*/30m" , 1800 ),
24+ ("*/6h" , 21600 ),
25+ ("60" , 60 ),
26+ ("3600" , 3600 )
27+ ]
28+
29+ print ("Testing ScheduleParser..." )
30+ for expr , expected in test_cases :
31+ result = ScheduleParser .parse (expr )
32+ assert result == expected , f"Expected { expected } , got { result } for '{ expr } '"
33+ print (f" ✓ '{ expr } ' -> { result } seconds" )
34+
35+ print ("ScheduleParser tests passed!" )
4236
4337def test_scheduler_creation ():
4438 """Test scheduler creation and basic functionality."""
45- try :
46- from praisonai .scheduler import create_scheduler , DeploymentScheduler
47-
48- print ("Testing scheduler creation..." )
49-
50- # Test default scheduler
51- scheduler = create_scheduler ()
39+ from praisonai .scheduler import create_scheduler , DeploymentScheduler
40+
41+ print ("Testing scheduler creation..." )
42+
43+ # Test default scheduler
44+ scheduler = create_scheduler ()
45+ assert isinstance (scheduler , DeploymentScheduler )
46+ print (" ✓ Default scheduler created" )
47+
48+ # Test with different providers
49+ for provider in ["gcp" , "aws" , "azure" ]:
50+ scheduler = create_scheduler (provider = provider )
5251 assert isinstance (scheduler , DeploymentScheduler )
53- print (" ✓ Default scheduler created" )
54-
55- # Test with different providers
56- for provider in ["gcp" , "aws" , "azure" ]:
57- scheduler = create_scheduler (provider = provider )
58- assert isinstance (scheduler , DeploymentScheduler )
59- print (f" ✓ { provider } scheduler created" )
60-
61- print ("Scheduler creation tests passed!" )
62- return True
63-
64- except Exception as e :
65- print (f"Scheduler creation test failed: { e } " )
66- return False
52+ print (f" ✓ { provider } scheduler created" )
53+
54+ print ("Scheduler creation tests passed!" )
6755
6856def test_config_file_parsing ():
6957 """Test configuration file parsing."""
70- try :
71- # Create a temporary config file
72- config_data = {
73- 'deployment' : {
74- 'schedule' : 'daily' ,
75- 'provider' : 'gcp' ,
76- 'max_retries' : 5
77- },
78- 'environment' : {
79- 'TEST_VAR' : 'test_value'
80- }
58+ # Create a temporary config file
59+ config_data = {
60+ 'deployment' : {
61+ 'schedule' : 'daily' ,
62+ 'provider' : 'gcp' ,
63+ 'max_retries' : 5
64+ },
65+ 'environment' : {
66+ 'TEST_VAR' : 'test_value'
8167 }
82-
83- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.yaml' , delete = False ) as f :
84- yaml .dump (config_data , f )
85- config_file = f .name
86-
87- print ("Testing config file parsing..." )
88-
89- # Test loading the config
90- with open (config_file , 'r' ) as f :
91- loaded_config = yaml .safe_load (f )
92-
93- assert loaded_config ['deployment' ]['schedule' ] == 'daily'
94- assert loaded_config ['deployment' ]['provider' ] == 'gcp'
95- assert loaded_config ['deployment' ]['max_retries' ] == 5
96- print (" ✓ Config file parsed correctly" )
97-
98- # Clean up
99- os .unlink (config_file )
100-
101- print ("Config file parsing tests passed!" )
102- return True
103-
104- except Exception as e :
105- print (f"Config file parsing test failed: { e } " )
106- return False
68+ }
69+
70+ with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.yaml' , delete = False ) as f :
71+ yaml .dump (config_data , f )
72+ config_file = f .name
73+
74+ print ("Testing config file parsing..." )
75+
76+ # Test loading the config
77+ with open (config_file , 'r' ) as f :
78+ loaded_config = yaml .safe_load (f )
79+
80+ assert loaded_config ['deployment' ]['schedule' ] == 'daily'
81+ assert loaded_config ['deployment' ]['provider' ] == 'gcp'
82+ assert loaded_config ['deployment' ]['max_retries' ] == 5
83+ print (" ✓ Config file parsed correctly" )
84+
85+ # Clean up
86+ os .unlink (config_file )
87+
88+ print ("Config file parsing tests passed!" )
10789
10890def test_cli_argument_parsing ():
10991 """Test CLI argument parsing for scheduling options."""
110- try :
111- from praisonai .cli import PraisonAI
112-
113- print ("Testing CLI argument parsing..." )
114-
115- # Test basic CLI instantiation
116- praison = PraisonAI ()
117- assert praison is not None
118- print (" ✓ PraisonAI CLI instance created" )
119-
120- print ("CLI argument parsing tests passed!" )
121- return True
122-
123- except Exception as e :
124- print (f"CLI argument parsing test failed: { e } " )
125- return False
92+ from praisonai .cli import PraisonAI
93+
94+ print ("Testing CLI argument parsing..." )
95+
96+ # Test basic CLI instantiation
97+ praison = PraisonAI ()
98+ assert praison is not None
99+ print (" ✓ PraisonAI CLI instance created" )
100+
101+ print ("CLI argument parsing tests passed!" )
126102
127103def main ():
128104 """Run all tests."""
@@ -141,10 +117,11 @@ def main():
141117
142118 for test in tests :
143119 print ()
144- if test ():
120+ try :
121+ test ()
145122 passed += 1
146- else :
147- print ("❌ Test failed" )
123+ except Exception as e :
124+ print (f "❌ Test failed: { e } " )
148125
149126 print ()
150127 print ("=" * 40 )
0 commit comments