@@ -652,3 +652,129 @@ def my_partitioned_config_2(_start, _end):
652
652
partitions_def .get_partition_keys_between_indexes (50 , 53 , current_time = current_time )
653
653
== partitions_def .get_partition_keys (current_time = current_time )[50 :53 ]
654
654
)
655
+
656
+
657
+ def test_get_first_partition_window ():
658
+ assert DailyPartitionsDefinition (
659
+ start_date = "2023-01-01"
660
+ ).get_first_partition_window () == time_window ("2023-01-01" , "2023-01-02" )
661
+
662
+ assert DailyPartitionsDefinition (
663
+ start_date = "2023-01-01" , end_offset = 1
664
+ ).get_first_partition_window (
665
+ current_time = datetime .strptime ("2023-01-01" , "%Y-%m-%d" )
666
+ ) == time_window (
667
+ "2023-01-01" , "2023-01-02"
668
+ )
669
+
670
+ assert (
671
+ DailyPartitionsDefinition (start_date = "2023-02-15" , end_offset = 1 ).get_first_partition_window (
672
+ current_time = datetime .strptime ("2023-02-14" , "%Y-%m-%d" )
673
+ )
674
+ is None
675
+ )
676
+
677
+ assert DailyPartitionsDefinition (
678
+ start_date = "2023-01-01" , end_offset = 2
679
+ ).get_first_partition_window (
680
+ current_time = datetime .strptime ("2023-01-02" , "%Y-%m-%d" )
681
+ ) == time_window (
682
+ "2023-01-01" , "2023-01-02"
683
+ )
684
+
685
+ assert MonthlyPartitionsDefinition (
686
+ start_date = "2023-01-01" , end_offset = 1
687
+ ).get_first_partition_window (
688
+ current_time = datetime .strptime ("2023-01-15" , "%Y-%m-%d" )
689
+ ) == time_window (
690
+ "2023-01-01" , "2023-02-01"
691
+ )
692
+
693
+ assert (
694
+ DailyPartitionsDefinition (
695
+ start_date = "2023-01-15" , end_offset = - 1
696
+ ).get_first_partition_window (current_time = datetime .strptime ("2023-01-16" , "%Y-%m-%d" ))
697
+ is None
698
+ )
699
+
700
+ assert DailyPartitionsDefinition (
701
+ start_date = "2023-01-15" , end_offset = - 1
702
+ ).get_first_partition_window (
703
+ current_time = datetime .strptime ("2023-01-17" , "%Y-%m-%d" )
704
+ ) == time_window (
705
+ "2023-01-15" , "2023-01-16"
706
+ )
707
+
708
+ assert (
709
+ DailyPartitionsDefinition (
710
+ start_date = "2023-01-15" , end_offset = - 2
711
+ ).get_first_partition_window (current_time = datetime .strptime ("2023-01-17" , "%Y-%m-%d" ))
712
+ is None
713
+ )
714
+
715
+ assert DailyPartitionsDefinition (
716
+ start_date = "2023-01-15" , end_offset = - 2
717
+ ).get_first_partition_window (
718
+ current_time = datetime .strptime ("2023-01-18" , "%Y-%m-%d" )
719
+ ) == time_window (
720
+ "2023-01-15" , "2023-01-16"
721
+ )
722
+
723
+ assert (
724
+ MonthlyPartitionsDefinition (
725
+ start_date = "2023-01-01" , end_offset = - 1
726
+ ).get_first_partition_window (current_time = datetime .strptime ("2023-01-15" , "%Y-%m-%d" ))
727
+ is None
728
+ )
729
+
730
+ assert (
731
+ DailyPartitionsDefinition (start_date = "2023-01-15" , end_offset = 1 ).get_first_partition_window (
732
+ current_time = datetime .strptime ("2023-01-14" , "%Y-%m-%d" )
733
+ )
734
+ is None
735
+ )
736
+
737
+ assert DailyPartitionsDefinition (
738
+ start_date = "2023-01-15" , end_offset = 1
739
+ ).get_first_partition_window (
740
+ current_time = datetime (year = 2023 , month = 1 , day = 15 , hour = 12 , minute = 0 , second = 0 )
741
+ ) == time_window (
742
+ "2023-01-15" , "2023-01-16"
743
+ )
744
+
745
+ assert DailyPartitionsDefinition (
746
+ start_date = "2023-01-15" , end_offset = 1
747
+ ).get_first_partition_window (
748
+ current_time = datetime (year = 2023 , month = 1 , day = 14 , hour = 12 , minute = 0 , second = 0 )
749
+ ) == time_window (
750
+ "2023-01-15" , "2023-01-16"
751
+ )
752
+
753
+ assert (
754
+ DailyPartitionsDefinition (start_date = "2023-01-15" , end_offset = 1 ).get_first_partition_window (
755
+ current_time = datetime (year = 2023 , month = 1 , day = 13 , hour = 12 , minute = 0 , second = 0 )
756
+ )
757
+ is None
758
+ )
759
+
760
+ assert (
761
+ MonthlyPartitionsDefinition (
762
+ start_date = "2023-01-01" , end_offset = - 1
763
+ ).get_first_partition_window (current_time = datetime .strptime ("2023-01-15" , "%Y-%m-%d" ))
764
+ is None
765
+ )
766
+
767
+ assert (
768
+ MonthlyPartitionsDefinition (
769
+ start_date = "2023-01-01" , end_offset = - 1
770
+ ).get_first_partition_window (current_time = datetime .strptime ("2023-02-01" , "%Y-%m-%d" ))
771
+ is None
772
+ )
773
+
774
+ assert MonthlyPartitionsDefinition (
775
+ start_date = "2023-01-01" , end_offset = - 1
776
+ ).get_first_partition_window (
777
+ current_time = datetime .strptime ("2023-03-01" , "%Y-%m-%d" )
778
+ ) == time_window (
779
+ "2023-01-01" , "2023-02-01"
780
+ )
0 commit comments