@@ -153,3 +153,35 @@ def quadruple(a: int) -> int:
153153 assert lp .schedule == _schedule_models .Schedule (
154154 "kickoff_input" , rate = _schedule_models .Schedule .FixedRate (12 , _schedule_models .Schedule .FixedRateUnit .HOUR )
155155 )
156+
157+
158+ @pytest .mark .parametrize (
159+ "invalid_schedule" ,
160+ [
161+ "0 0 31 2 *" , # February 31st (does not exist)
162+ "0 0 30 2 *" , # February 30th (does not exist)
163+ "0 0 31 4 *" , # April 31st (does not exist)
164+ "0 0 31 6 *" , # June 31st (does not exist)
165+ ],
166+ )
167+ def test_cron_invalid_date_combinations (invalid_schedule ):
168+ """Test that CronSchedule rejects invalid date combinations like 31st of February."""
169+ with pytest .raises (ValueError , match = "Schedule is invalid." ):
170+ CronSchedule (schedule = invalid_schedule )
171+
172+
173+ @pytest .mark .parametrize (
174+ "valid_schedule" ,
175+ [
176+ "0 0 28 2 *" , # February 28th (always valid)
177+ "0 0 29 2 *" , # February 29th (valid in leap years - handled by croniter)
178+ "0 0 30 4 *" , # April 30th (valid)
179+ "0 0 31 1 *" , # January 31st (valid)
180+ "0 0 31 3 *" , # March 31st (valid)
181+ ],
182+ )
183+ def test_cron_valid_date_combinations (valid_schedule ):
184+ """Test that CronSchedule accepts valid date combinations."""
185+ # These should not raise any exceptions
186+ obj = CronSchedule (schedule = valid_schedule )
187+ assert obj .cron_schedule .schedule == valid_schedule
0 commit comments