forked from JesperDramsch/python-deadlines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_date_enhanced.py
More file actions
1104 lines (850 loc) · 37.1 KB
/
Copy pathtest_date_enhanced.py
File metadata and controls
1104 lines (850 loc) · 37.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Enhanced tests for tidy_conf.date functionality to increase coverage."""
import sys
from datetime import date
from datetime import datetime
from datetime import timezone
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).parent))
sys.path.append(str(Path(__file__).parent.parent / "utils"))
from hypothesis_strategies import HYPOTHESIS_AVAILABLE
from tidy_conf.date import clean_dates
from tidy_conf.date import create_nice_date
from tidy_conf.date import suffix
class TestCleanDates:
"""Test clean_dates functionality with comprehensive coverage."""
def test_clean_dates_string_start_end_dates(self):
"""Test cleaning of start and end dates when they are strings."""
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15"}
result = clean_dates(data)
# Start and end should be converted to date objects
assert isinstance(result["start"], date)
assert isinstance(result["end"], date)
assert result["start"] == date(2025, 6, 1)
assert result["end"] == date(2025, 6, 3)
def test_clean_dates_already_date_objects(self):
"""Test cleaning when start and end are already date objects."""
data = {"start": date(2025, 6, 1), "end": date(2025, 6, 3), "cfp": "2025-02-15"}
result = clean_dates(data)
# Should remain as date objects
assert isinstance(result["start"], date)
assert isinstance(result["end"], date)
assert result["start"] == date(2025, 6, 1)
assert result["end"] == date(2025, 6, 3)
def test_clean_dates_cfp_date_only(self):
"""Test CFP cleaning when only date is provided (no time)."""
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15"} # Date only
result = clean_dates(data)
# CFP should get time appended (23:59:00)
assert result["cfp"] == "2025-02-15 23:59:00"
def test_clean_dates_cfp_with_time(self):
"""Test CFP cleaning when time is already provided."""
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15 12:30:00"} # Already has time
result = clean_dates(data)
# CFP should remain unchanged
assert result["cfp"] == "2025-02-15 12:30:00"
def test_clean_dates_tba_words(self):
"""Test handling of TBA words in deadlines."""
tba_words = ["tba", "tbd", "cancelled"]
for tba_word in tba_words:
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": tba_word}
result = clean_dates(data)
# TBA words should remain unchanged
assert result["cfp"] == tba_word
def test_clean_dates_tba_case_insensitive(self):
"""Test that TBA word matching is case insensitive."""
tba_variations = ["TBA", "Tba", "tBa", "TBD", "CANCELLED"]
for tba_word in tba_variations:
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": tba_word}
result = clean_dates(data)
# Should remain unchanged regardless of case
assert result["cfp"] == tba_word
def test_clean_dates_datetime_object_cfp(self):
"""Test CFP cleaning when it's a datetime object."""
cfp_datetime = datetime(2025, 2, 15, 12, 30, 0, tzinfo=timezone.utc)
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": cfp_datetime}
result = clean_dates(data)
# Should convert datetime to string format
assert result["cfp"] == "2025-02-15 12:30:00"
def test_clean_dates_date_object_cfp(self):
"""Test CFP cleaning when it's a date object."""
cfp_date = date(2025, 2, 15)
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": cfp_date}
result = clean_dates(data)
# Date objects get converted to string, then time is added (23:59:00)
assert result["cfp"] == "2025-02-15 23:59:00"
def test_clean_dates_workshop_deadline(self):
"""Test workshop_deadline processing."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-01-15", # Date only
}
result = clean_dates(data)
# Workshop deadline should get time appended
assert result["workshop_deadline"] == "2025-01-15 23:59:00"
def test_clean_dates_tutorial_deadline(self):
"""Test tutorial_deadline processing."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"tutorial_deadline": "2025-01-20", # Date only
}
result = clean_dates(data)
# Tutorial deadline should get time appended
assert result["tutorial_deadline"] == "2025-01-20 23:59:00"
def test_clean_dates_deadline_same_as_cfp(self):
"""Test that deadlines identical to CFP are removed."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-02-15", # Same as CFP
"tutorial_deadline": "2025-01-20", # Different from CFP
}
result = clean_dates(data)
# Workshop deadline should be removed (same as CFP)
assert "workshop_deadline" not in result
# Tutorial deadline should remain (different from CFP)
assert "tutorial_deadline" in result
assert result["tutorial_deadline"] == "2025-01-20 23:59:00"
def test_clean_dates_missing_deadline_keys(self):
"""Test handling when deadline keys are missing."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
# No workshop_deadline or tutorial_deadline
}
result = clean_dates(data)
# Should not crash and should only have the provided keys
assert "workshop_deadline" not in result
assert "tutorial_deadline" not in result
assert result["cfp"] == "2025-02-15 23:59:00"
def test_clean_dates_invalid_date_format(self):
"""Test handling of invalid date formats."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "invalid-date-format",
}
result = clean_dates(data)
# Invalid date should be left unchanged due to ValueError handling
assert result["workshop_deadline"] == "invalid-date-format"
def test_clean_dates_midnight_time_conversion(self):
"""Test that midnight times get converted to 23:59."""
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15"} # Will become midnight when parsed
result = clean_dates(data)
# Should convert midnight (00:00) to 23:59
assert result["cfp"] == "2025-02-15 23:59:00"
def test_clean_dates_non_midnight_time_preservation(self):
"""Test that non-midnight times are preserved."""
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15 14:30:00"} # Non-midnight time
result = clean_dates(data)
# Should preserve the original time
assert result["cfp"] == "2025-02-15 14:30:00"
def test_clean_dates_all_deadline_types(self):
"""Test processing all deadline types together."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-01-15",
"tutorial_deadline": "2025-01-20",
}
result = clean_dates(data)
# All deadlines should be processed
assert result["cfp"] == "2025-02-15 23:59:00"
assert result["workshop_deadline"] == "2025-01-15 23:59:00"
assert result["tutorial_deadline"] == "2025-01-20 23:59:00"
def test_clean_dates_data_modification_in_place(self):
"""Test that the original data dict is modified in place."""
original_data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15"}
result = clean_dates(original_data)
# Should return the same object (modified in place)
assert result is original_data
assert original_data["cfp"] == "2025-02-15 23:59:00"
class TestSuffix:
"""Test suffix function for ordinal numbers."""
def test_suffix_basic_numbers(self):
"""Test suffix for basic ordinal numbers."""
test_cases = [
(1, "st"),
(2, "nd"),
(3, "rd"),
(4, "th"),
(5, "th"),
(6, "th"),
(7, "th"),
(8, "th"),
(9, "th"),
(10, "th"),
]
for number, expected_suffix in test_cases:
assert suffix(number) == expected_suffix
def test_suffix_teens_special_case(self):
"""Test suffix for teen numbers (11, 12, 13) which are special cases."""
teen_numbers = [11, 12, 13]
for number in teen_numbers:
assert suffix(number) == "th"
def test_suffix_twenties_and_beyond(self):
"""Test suffix for numbers in twenties and beyond."""
test_cases = [
(21, "st"), # 21st
(22, "nd"), # 22nd
(23, "rd"), # 23rd
(24, "th"), # 24th
(31, "st"), # 31st
(32, "nd"), # 32nd
(33, "rd"), # 33rd
(101, "st"), # 101st
(102, "nd"), # 102nd
(103, "rd"), # 103rd
(111, "th"), # 111th (special case)
(112, "th"), # 112th (special case)
(113, "th"), # 113th (special case)
(121, "st"), # 121st
(122, "nd"), # 122nd
(123, "rd"), # 123rd
]
for number, expected_suffix in test_cases:
assert suffix(number) == expected_suffix
def test_suffix_large_numbers(self):
"""Test suffix for large numbers."""
test_cases = [
(1001, "st"),
(1002, "nd"),
(1003, "rd"),
(1011, "th"), # Special case
(1021, "st"),
(1111, "th"), # Special case
(1121, "st"),
]
for number, expected_suffix in test_cases:
assert suffix(number) == expected_suffix
class TestCreateNiceDate:
"""Test create_nice_date functionality."""
def test_create_nice_date_same_day(self):
"""Test nice date creation when start and end are the same day."""
data = {"start": "2025-06-01", "end": "2025-06-01"}
result = create_nice_date(data)
# Should create a single date format
assert result["date"] == "June 1st, 2025"
def test_create_nice_date_same_month(self):
"""Test nice date creation when start and end are in the same month."""
data = {"start": "2025-06-01", "end": "2025-06-15"}
result = create_nice_date(data)
# Should show month once with date range
assert result["date"] == "June 1 - 15, 2025"
def test_create_nice_date_same_year_different_months(self):
"""Test nice date creation for different months in same year."""
data = {"start": "2025-06-01", "end": "2025-07-15"}
result = create_nice_date(data)
# Should show both months with year once
assert result["date"] == "June 1 - July 15, 2025"
def test_create_nice_date_different_years(self):
"""Test nice date creation spanning different years."""
data = {"start": "2025-12-15", "end": "2026-01-05"}
result = create_nice_date(data)
# Should show full dates for both
assert result["date"] == "December 15, 2025 - January 5, 2026"
def test_create_nice_date_ordinal_suffixes(self):
"""Test that ordinal suffixes are correctly applied."""
test_cases = [
("2025-06-01", "2025-06-01", "June 1st, 2025"),
("2025-06-02", "2025-06-02", "June 2nd, 2025"),
("2025-06-03", "2025-06-03", "June 3rd, 2025"),
("2025-06-04", "2025-06-04", "June 4th, 2025"),
("2025-06-11", "2025-06-11", "June 11th, 2025"), # Teen special case
("2025-06-21", "2025-06-21", "June 21st, 2025"),
("2025-06-22", "2025-06-22", "June 22nd, 2025"),
("2025-06-23", "2025-06-23", "June 23rd, 2025"),
]
for start_date, end_date, expected in test_cases:
data = {"start": start_date, "end": end_date}
result = create_nice_date(data)
assert result["date"] == expected
def test_create_nice_date_removes_leading_zeros(self):
"""Test that leading zeros are removed from dates."""
data = {"start": "2025-06-01", "end": "2025-06-09"} # Day 01 should become 1 # Day 09 should become 9
result = create_nice_date(data)
# Should not have leading zeros
assert result["date"] == "June 1 - 9, 2025"
assert " 01" not in result["date"]
assert " 09" not in result["date"]
def test_create_nice_date_already_date_objects(self):
"""Test nice date creation when dates are already date objects."""
data = {"start": date(2025, 6, 1), "end": date(2025, 6, 15)}
result = create_nice_date(data)
# Should handle date objects correctly
assert result["date"] == "June 1 - 15, 2025"
def test_create_nice_date_mixed_date_types(self):
"""Test nice date creation with mixed date types."""
data = {"start": "2025-06-01", "end": date(2025, 6, 15)} # String # Date object
# Should handle mixed types gracefully now
result = create_nice_date(data)
# Should create proper date format
assert "date" in result
assert "June 1 - 15, 2025" in result["date"]
def test_create_nice_date_edge_cases_months(self):
"""Test nice date creation for edge case months."""
test_cases = [
("2025-01-01", "2025-01-31", "January"), # January
("2025-02-01", "2025-02-28", "February"), # February
("2025-12-01", "2025-12-31", "December"), # December
]
for start_date, end_date, expected_month in test_cases:
data = {"start": start_date, "end": end_date}
result = create_nice_date(data)
assert expected_month in result["date"]
def test_create_nice_date_data_modification(self):
"""Test that create_nice_date modifies the original data dict."""
original_data = {"start": "2025-06-01", "end": "2025-06-15", "conference": "Test Conference"}
result = create_nice_date(original_data)
# Should return the same object (modified in place)
assert result is original_data
assert "date" in original_data
assert original_data["date"] == "June 1 - 15, 2025"
def test_create_nice_date_preserves_other_data(self):
"""Test that create_nice_date preserves other data in the dict."""
data = {
"start": "2025-06-01",
"end": "2025-06-15",
"conference": "Test Conference",
"year": 2025,
"cfp": "2025-02-15",
}
result = create_nice_date(data)
# Should preserve all other data
assert result["conference"] == "Test Conference"
assert result["year"] == 2025
assert result["cfp"] == "2025-02-15"
assert result["date"] == "June 1 - 15, 2025"
class TestIntegrationAndEdgeCases:
"""Test integration scenarios and edge cases."""
def test_full_date_processing_workflow(self):
"""Test complete date processing workflow."""
data = {
"start": "2025-06-01",
"end": "2025-06-15",
"cfp": "2025-02-15",
"workshop_deadline": "2025-01-15",
"tutorial_deadline": "2025-02-15", # Same as CFP
}
# Clean dates first
cleaned = clean_dates(data)
# Then create nice date
result = create_nice_date(cleaned)
# Should have processed everything correctly
assert isinstance(result["start"], date)
assert isinstance(result["end"], date)
assert result["cfp"] == "2025-02-15 23:59:00"
assert result["workshop_deadline"] == "2025-01-15 23:59:00"
assert "tutorial_deadline" not in result # Removed because same as CFP
assert result["date"] == "June 1 - 15, 2025"
def test_error_handling_invalid_dates(self):
"""Test error handling with invalid date formats."""
data = {"start": "invalid-start-date", "end": "invalid-end-date", "cfp": "2025-02-15"}
# clean_dates should handle invalid formats gracefully
with pytest.raises(ValueError, match=r"time data .* does not match format"):
clean_dates(data)
def test_timezone_awareness_preservation(self):
"""Test that timezone information is properly handled."""
utc_datetime = datetime(2025, 2, 15, 12, 30, 0, tzinfo=timezone.utc)
data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": utc_datetime}
result = clean_dates(data)
# Should preserve the time information
assert result["cfp"] == "2025-02-15 12:30:00"
def test_boundary_date_handling(self):
"""Test handling of boundary dates and times."""
data = {
"start": "2025-01-01", # Start of year
"end": "2025-12-31", # End of year
"cfp": "2025-02-28", # End of February (non-leap year)
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
assert cleaned["cfp"] == "2025-02-28 23:59:00"
assert nice_date["date"] == "January 1 - December 31, 2025"
def test_data_immutability_concerns(self):
"""Test that functions properly handle data modification."""
original_data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"immutable_field": "should_not_change",
}
# Make a copy to compare
import copy
data_copy = copy.deepcopy(original_data)
# Process the data
result = clean_dates(data_copy)
# Original should be unchanged, copy should be modified
assert original_data["cfp"] == "2025-02-15"
assert result["cfp"] == "2025-02-15 23:59:00"
assert result["immutable_field"] == "should_not_change"
def test_memory_efficiency_large_datasets(self):
"""Test memory efficiency with repeated function calls."""
# Simulate processing many conferences
base_data = {"start": "2025-06-01", "end": "2025-06-03", "cfp": "2025-02-15"}
results = []
for i in range(100):
data = base_data.copy()
data["conference"] = f"Conference {i}"
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
results.append(nice_date)
# Should handle many operations without issues
assert len(results) == 100
assert all("date" in result for result in results)
assert all(result["cfp"] == "2025-02-15 23:59:00" for result in results)
class TestDateEdgeCases:
"""Test edge cases for date handling as identified in the audit.
Section 5 of the audit identified these missing tests:
- Malformed date strings (e.g., "2025-13-45")
- Timezone edge cases (deadline at midnight in AoE vs UTC)
- Leap year handling
- Year boundary transitions
"""
def test_malformed_date_invalid_month(self):
"""Test handling of invalid month (13) in date string."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-13-15", # Invalid: month 13 doesn't exist
}
result = clean_dates(data)
# Invalid date should be left unchanged (ValueError is caught and continues)
assert result["workshop_deadline"] == "2025-13-15"
def test_malformed_date_invalid_day(self):
"""Test handling of invalid day (45) in date string."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-06-45", # Invalid: day 45 doesn't exist
}
result = clean_dates(data)
# Invalid date should be left unchanged
assert result["workshop_deadline"] == "2025-06-45"
def test_malformed_date_february_30(self):
"""Test handling of impossible date: February 30."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-02-30", # Invalid: Feb 30 doesn't exist
}
result = clean_dates(data)
# Invalid date should be left unchanged
assert result["workshop_deadline"] == "2025-02-30"
def test_leap_year_february_29_valid(self):
"""Test CFP on Feb 29 of leap year (2024 is a leap year)."""
data = {
"start": "2024-06-01",
"end": "2024-06-03",
"cfp": "2024-02-29", # Valid: 2024 is a leap year
}
result = clean_dates(data)
# Should process correctly and add time
assert result["cfp"] == "2024-02-29 23:59:00"
def test_non_leap_year_february_29_invalid(self):
"""Test CFP on Feb 29 of non-leap year (2025 is not a leap year)."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2025-02-29", # Invalid: 2025 is not a leap year
}
result = clean_dates(data)
# Invalid date should be left unchanged
assert result["workshop_deadline"] == "2025-02-29"
def test_leap_year_february_29_nice_date(self):
"""Test nice date creation for Feb 29 on leap year."""
data = {
"start": "2024-02-29", # Leap year day
"end": "2024-02-29",
}
result = create_nice_date(data)
assert result["date"] == "February 29th, 2024"
def test_year_boundary_transition_december_to_january(self):
"""Test conference spanning year boundary (Dec to Jan)."""
data = {
"start": "2025-12-28",
"end": "2026-01-03",
"cfp": "2025-10-15",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
# Should handle year transition in nice date
assert nice_date["date"] == "December 28, 2025 - January 3, 2026"
def test_year_boundary_cfp_deadline(self):
"""Test CFP deadline on Dec 31 (year boundary)."""
data = {
"start": "2026-03-01",
"end": "2026-03-05",
"cfp": "2025-12-31", # Deadline on year boundary
}
result = clean_dates(data)
# Should process correctly
assert result["cfp"] == "2025-12-31 23:59:00"
def test_year_boundary_new_years_day_cfp(self):
"""Test CFP deadline on Jan 1 (start of new year)."""
data = {
"start": "2026-03-01",
"end": "2026-03-05",
"cfp": "2026-01-01", # First day of year
}
result = clean_dates(data)
assert result["cfp"] == "2026-01-01 23:59:00"
def test_century_leap_year_2000(self):
"""Test that year 2000 leap year rules work (divisible by 400)."""
# 2000 was a leap year (divisible by 400)
data = {
"start": "2000-02-29",
"end": "2000-02-29",
}
result = create_nice_date(data)
assert result["date"] == "February 29th, 2000"
def test_century_non_leap_year_1900(self):
"""Test that year 1900 non-leap year rules work (divisible by 100 but not 400)."""
# 1900 was NOT a leap year (divisible by 100 but not 400)
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "1900-02-29", # Invalid: 1900 was not a leap year
}
result = clean_dates(data)
# Invalid date should be left unchanged
assert result["workshop_deadline"] == "1900-02-29"
def test_midnight_boundary_explicit_midnight(self):
"""Test CFP with explicit midnight time (00:00:00).
When a datetime string includes an explicit time component,
it is preserved as-is. The 23:59 conversion only applies to
date-only strings that are parsed without a time component.
"""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15 00:00:00", # Explicit midnight
}
result = clean_dates(data)
# Explicit times are preserved as-is (conversion only for date-only strings)
assert result["cfp"] == "2025-02-15 00:00:00"
def test_one_minute_before_midnight(self):
"""Test CFP with 23:59:00 time (one minute before midnight)."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15 23:59:00",
}
result = clean_dates(data)
# Should remain unchanged
assert result["cfp"] == "2025-02-15 23:59:00"
def test_conference_single_day_event(self):
"""Test single-day conference (start == end)."""
data = {
"start": "2025-06-15",
"end": "2025-06-15",
"cfp": "2025-02-15",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
# Single day should show ordinal suffix
assert nice_date["date"] == "June 15th, 2025"
def test_multi_year_conference(self):
"""Test conference spanning multiple years (unusual but possible)."""
data = {
"start": "2025-11-15",
"end": "2026-02-15", # 3 months span across year
"cfp": "2025-08-01",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
assert nice_date["date"] == "November 15, 2025 - February 15, 2026"
def test_future_year_dates(self):
"""Test handling of far future dates."""
data = {
"start": "2099-12-01",
"end": "2099-12-05",
"cfp": "2099-06-15",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
assert cleaned["cfp"] == "2099-06-15 23:59:00"
assert "2099" in nice_date["date"]
class TestDSTTransitions:
"""Test handling of Daylight Saving Time transitions.
Coverage gap: DST transitions can cause issues with date/time calculations.
"""
def test_dst_spring_forward_date(self):
"""Test CFP on spring forward date (clocks skip ahead).
In the US, DST starts second Sunday of March.
March 9, 2025 is a DST transition day.
"""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-03-09", # DST spring forward in US
}
result = clean_dates(data)
# Should handle DST date correctly
assert result["cfp"] == "2025-03-09 23:59:00"
def test_dst_fall_back_date(self):
"""Test CFP on fall back date (clocks repeat an hour).
In the US, DST ends first Sunday of November.
November 2, 2025 is a DST transition day.
"""
data = {
"start": "2025-12-01",
"end": "2025-12-03",
"cfp": "2025-11-02", # DST fall back in US
}
result = clean_dates(data)
# Should handle DST date correctly
assert result["cfp"] == "2025-11-02 23:59:00"
def test_conference_spanning_dst_transition(self):
"""Test conference that spans DST transition."""
data = {
"start": "2025-03-08", # Day before DST
"end": "2025-03-10", # Day after DST
"cfp": "2025-01-15",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
# Should handle dates correctly across DST boundary
assert nice_date["date"] == "March 8 - 10, 2025"
def test_european_dst_dates(self):
"""Test European DST transition dates (last Sunday of March/October)."""
# EU DST starts last Sunday of March (March 30, 2025)
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-03-30", # EU DST start
}
result = clean_dates(data)
assert result["cfp"] == "2025-03-30 23:59:00"
class TestAoETimezoneEdgeCases:
"""Test Anywhere on Earth (AoE) timezone edge cases.
Coverage gap: AoE timezone (UTC-12) is commonly used for CFP deadlines.
A deadline of "2025-02-15 23:59 AoE" means it's valid until
2025-02-16 11:59 UTC.
"""
def test_aoe_deadline_format(self):
"""Test that CFP times can represent AoE deadlines.
AoE is UTC-12, so 23:59 AoE = 11:59 UTC next day.
"""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15 23:59:00", # Interpreted as AoE
}
result = clean_dates(data)
# Time should be preserved (AoE interpretation is application-level)
assert result["cfp"] == "2025-02-15 23:59:00"
def test_aoe_date_line_crossing(self):
"""Test dates near the international date line.
Conferences in Pacific islands may have unusual date considerations.
"""
data = {
"start": "2025-01-01", # Could be Dec 31 in some timezones
"end": "2025-01-03",
"cfp": "2024-12-31 23:59:00", # Last day of year in AoE
}
result = clean_dates(data)
# Date should be preserved correctly
assert result["cfp"] == "2024-12-31 23:59:00"
def test_aoe_vs_utc_deadline_day(self):
"""Test that deadline day is correctly represented.
If deadline is Feb 15 AoE, submissions are accepted until
Feb 16 11:59 UTC. The stored date should reflect the AoE date.
"""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15", # Date only - will get 23:59:00 appended
}
result = clean_dates(data)
# Should append 23:59:00 (commonly interpreted as AoE)
assert result["cfp"] == "2025-02-15 23:59:00"
assert "2025-02-15" in result["cfp"]
def test_utc_plus_14_edge_case(self):
"""Test UTC+14 (Line Islands) edge case.
Kiritimati (Christmas Island) is UTC+14, the earliest timezone.
A Jan 1 conference there starts before anywhere else on Earth.
"""
data = {
"start": "2025-01-01",
"end": "2025-01-03",
"cfp": "2024-11-15 23:59:00",
}
cleaned = clean_dates(data)
nice_date = create_nice_date(cleaned)
# Should handle correctly
assert nice_date["date"] == "January 1 - 3, 2025"
class TestLeapYearEdgeCases:
"""Additional leap year edge cases.
Coverage gap: Comprehensive leap year testing including edge cases.
"""
def test_leap_year_century_rule_2000(self):
"""Test year 2000 (divisible by 400 = leap year)."""
data = {
"start": "2000-02-29",
"end": "2000-03-02",
}
result = create_nice_date(data)
assert "February 29" in result["date"]
def test_leap_year_century_rule_2100(self):
"""Test year 2100 (divisible by 100 but not 400 = not leap year)."""
data = {
"start": "2025-06-01",
"end": "2025-06-03",
"cfp": "2025-02-15",
"workshop_deadline": "2100-02-29", # Invalid: 2100 is not a leap year
}
result = clean_dates(data)
# Invalid date should be left unchanged
assert result["workshop_deadline"] == "2100-02-29"
def test_leap_year_2024(self):
"""Test 2024 (regular leap year)."""
data = {
"start": "2024-02-29",
"end": "2024-02-29",
}
result = create_nice_date(data)
assert result["date"] == "February 29th, 2024"
def test_leap_year_2028(self):
"""Test 2028 (future leap year)."""
data = {
"start": "2028-02-29",
"end": "2028-03-01",
}
result = create_nice_date(data)
assert result["date"] == "February 29 - March 1, 2028"
def test_leap_year_cfp_feb_29(self):
"""Test CFP deadline on Feb 29 of leap year."""
data = {
"start": "2024-06-01",
"end": "2024-06-03",
"cfp": "2024-02-29",
}
result = clean_dates(data)
assert result["cfp"] == "2024-02-29 23:59:00"
# ---------------------------------------------------------------------------
# Property-based tests using Hypothesis
# ---------------------------------------------------------------------------
if HYPOTHESIS_AVAILABLE:
from datetime import timedelta
from hypothesis import assume
from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
from pydantic import ValidationError
from tidy_conf.schema import Conference
@pytest.mark.skipif(not HYPOTHESIS_AVAILABLE, reason="hypothesis not installed")
class TestDateProperties:
"""Property-based tests for date handling."""
@given(st.dates(min_value=date(1990, 1, 1), max_value=date(2050, 12, 31)))
@settings(max_examples=50)
def test_valid_dates_accepted_in_range(self, d):
"""Dates between 1990 and 2050 should be valid start/end dates."""
end_date = d + timedelta(days=2)
# Skip if end date would cross year boundary
assume(d.year == end_date.year)
try: