@@ -595,26 +595,15 @@ def test_calendar(self):
595
595
dt = datetime (2014 , 1 , 17 )
596
596
assertEq (CDay (calendar = calendar ), dt , datetime (2014 , 1 , 21 ))
597
597
598
- class TestCustomBusinessMonthEnd ( TestBase ):
598
+ class CustomBusinessMonthBase ( object ):
599
599
_multiprocess_can_split_ = True
600
600
601
601
def setUp (self ):
602
602
self .d = datetime (2008 , 1 , 1 )
603
603
604
604
_skip_if_no_cday ()
605
- self .offset = CBMonthEnd ()
606
- self .offset2 = CBMonthEnd (2 )
607
-
608
- def test_different_normalize_equals (self ):
609
- # equivalent in this special case
610
- offset = CBMonthEnd ()
611
- offset2 = CBMonthEnd ()
612
- offset2 .normalize = True
613
- self .assertEqual (offset , offset2 )
614
-
615
- def test_repr (self ):
616
- assert repr (self .offset ) == '<CustomBusinessMonthEnd>'
617
- assert repr (self .offset2 ) == '<2 * CustomBusinessMonthEnds>'
605
+ self .offset = self ._object ()
606
+ self .offset2 = self ._object (2 )
618
607
619
608
def testEQ (self ):
620
609
self .assertEqual (self .offset2 , self .offset2 )
@@ -625,9 +614,6 @@ def test_mul(self):
625
614
def test_hash (self ):
626
615
self .assertEqual (hash (self .offset2 ), hash (self .offset2 ))
627
616
628
- def testCall (self ):
629
- self .assertEqual (self .offset2 (self .d ), datetime (2008 , 2 , 29 ))
630
-
631
617
def testRAdd (self ):
632
618
self .assertEqual (self .d + self .offset2 , self .offset2 + self .d )
633
619
@@ -637,18 +623,40 @@ def testSub(self):
637
623
self .assertEqual (2 * off - off , off )
638
624
639
625
self .assertEqual (self .d - self .offset2 ,
640
- self .d + CBMonthEnd (- 2 ))
626
+ self .d + self . _object (- 2 ))
641
627
642
628
def testRSub (self ):
643
629
self .assertEqual (self .d - self .offset2 , (- self .offset2 ).apply (self .d ))
644
630
645
631
def testMult1 (self ):
646
632
self .assertEqual (self .d + 10 * self .offset ,
647
- self .d + CBMonthEnd (10 ))
633
+ self .d + self . _object (10 ))
648
634
649
635
def testMult2 (self ):
650
- self .assertEqual (self .d + (- 5 * CBMonthEnd (- 10 )),
651
- self .d + CBMonthEnd (50 ))
636
+ self .assertEqual (self .d + (- 5 * self ._object (- 10 )),
637
+ self .d + self ._object (50 ))
638
+
639
+ def test_offsets_compare_equal (self ):
640
+ offset1 = self ._object ()
641
+ offset2 = self ._object ()
642
+ self .assertFalse (offset1 != offset2 )
643
+
644
+ class TestCustomBusinessMonthEnd (CustomBusinessMonthBase , TestBase ):
645
+ _object = CBMonthEnd
646
+
647
+ def test_different_normalize_equals (self ):
648
+ # equivalent in this special case
649
+ offset = CBMonthEnd ()
650
+ offset2 = CBMonthEnd ()
651
+ offset2 .normalize = True
652
+ self .assertEqual (offset , offset2 )
653
+
654
+ def test_repr (self ):
655
+ assert repr (self .offset ) == '<CustomBusinessMonthEnd>'
656
+ assert repr (self .offset2 ) == '<2 * CustomBusinessMonthEnds>'
657
+
658
+ def testCall (self ):
659
+ self .assertEqual (self .offset2 (self .d ), datetime (2008 , 2 , 29 ))
652
660
653
661
def testRollback1 (self ):
654
662
self .assertEqual (
@@ -734,11 +742,6 @@ def test_apply_large_n(self):
734
742
xp = datetime (2012 , 5 , 31 )
735
743
self .assertEqual (rs , xp )
736
744
737
- def test_offsets_compare_equal (self ):
738
- offset1 = CBMonthEnd ()
739
- offset2 = CBMonthEnd ()
740
- self .assertFalse (offset1 != offset2 )
741
-
742
745
def test_holidays (self ):
743
746
# Define a TradingDay offset
744
747
holidays = ['2012-01-31' , datetime (2012 , 2 , 28 ),
@@ -753,16 +756,8 @@ def test_datetimeindex(self):
753
756
self .assertEqual (DatetimeIndex (start = '20120101' ,end = '20130101' ,freq = CBMonthEnd (calendar = USFederalHolidayCalendar ())).tolist ()[0 ],
754
757
datetime (2012 ,1 ,31 ))
755
758
756
-
757
- class TestCustomBusinessMonthBegin (TestBase ):
758
- _multiprocess_can_split_ = True
759
-
760
- def setUp (self ):
761
- self .d = datetime (2008 , 1 , 1 )
762
-
763
- _skip_if_no_cday ()
764
- self .offset = CBMonthBegin ()
765
- self .offset2 = CBMonthBegin (2 )
759
+ class TestCustomBusinessMonthBegin (CustomBusinessMonthBase , TestBase ):
760
+ _object = CBMonthBegin
766
761
767
762
def test_different_normalize_equals (self ):
768
763
# equivalent in this special case
@@ -775,40 +770,9 @@ def test_repr(self):
775
770
assert repr (self .offset ) == '<CustomBusinessMonthBegin>'
776
771
assert repr (self .offset2 ) == '<2 * CustomBusinessMonthBegins>'
777
772
778
- def testEQ (self ):
779
- self .assertEqual (self .offset2 , self .offset2 )
780
-
781
- def test_mul (self ):
782
- pass
783
-
784
- def test_hash (self ):
785
- self .assertEqual (hash (self .offset2 ), hash (self .offset2 ))
786
-
787
773
def testCall (self ):
788
774
self .assertEqual (self .offset2 (self .d ), datetime (2008 , 3 , 3 ))
789
775
790
- def testRAdd (self ):
791
- self .assertEqual (self .d + self .offset2 , self .offset2 + self .d )
792
-
793
- def testSub (self ):
794
- off = self .offset2
795
- self .assertRaises (Exception , off .__sub__ , self .d )
796
- self .assertEqual (2 * off - off , off )
797
-
798
- self .assertEqual (self .d - self .offset2 ,
799
- self .d + CBMonthBegin (- 2 ))
800
-
801
- def testRSub (self ):
802
- self .assertEqual (self .d - self .offset2 , (- self .offset2 ).apply (self .d ))
803
-
804
- def testMult1 (self ):
805
- self .assertEqual (self .d + 10 * self .offset ,
806
- self .d + CBMonthBegin (10 ))
807
-
808
- def testMult2 (self ):
809
- self .assertEqual (self .d + (- 5 * CBMonthBegin (- 10 )),
810
- self .d + CBMonthBegin (50 ))
811
-
812
776
def testRollback1 (self ):
813
777
self .assertEqual (
814
778
CDay (10 ).rollback (datetime (2007 , 12 , 31 )), datetime (2007 , 12 , 31 ))
@@ -893,11 +857,6 @@ def test_apply_large_n(self):
893
857
xp = datetime (2012 , 6 , 1 )
894
858
self .assertEqual (rs , xp )
895
859
896
- def test_offsets_compare_equal (self ):
897
- offset1 = CBMonthBegin ()
898
- offset2 = CBMonthBegin ()
899
- self .assertFalse (offset1 != offset2 )
900
-
901
860
def test_holidays (self ):
902
861
# Define a TradingDay offset
903
862
holidays = ['2012-02-01' , datetime (2012 , 2 , 2 ),
@@ -907,14 +866,11 @@ def test_holidays(self):
907
866
self .assertEqual (dt + bm_offset ,datetime (2012 ,1 ,2 ))
908
867
self .assertEqual (dt + 2 * bm_offset ,datetime (2012 ,2 ,3 ))
909
868
910
- def test_datetimindex (self ):
911
- self .assertEqual (DatetimeIndex (start = '2012' ,end = '2013' ,freq = 'CBMS' ).tolist ()[0 ],
912
- datetime (2012 ,5 ,1 ))
869
+ def test_datetimeindex (self ):
913
870
self .assertEqual (DatetimeIndex (start = '20120101' ,end = '20130101' ,freq = CBMonthBegin (calendar = USFederalHolidayCalendar ())).tolist ()[0 ],
914
871
datetime (2012 ,1 ,3 ))
915
872
916
873
917
-
918
874
def assertOnOffset (offset , date , expected ):
919
875
actual = offset .onOffset (date )
920
876
assert actual == expected , ("\n Expected: %s\n Actual: %s\n For Offset: %s)"
0 commit comments