|
1 |
| -from datetime import date, datetime, timedelta |
| 1 | +from datetime import date, time, datetime, timedelta |
2 | 2 | from distutils.version import LooseVersion
|
3 | 3 |
|
4 | 4 | import numpy as np
|
@@ -767,37 +767,53 @@ def setup_method(self, method):
|
767 | 767 | self.offset10 = BusinessHour(n=-1, start=['23:00', '13:00'],
|
768 | 768 | end=['02:00', '17:00'])
|
769 | 769 |
|
770 |
| - def test_constructor_errors(self): |
771 |
| - from datetime import time as dt_time |
772 |
| - with pytest.raises(ValueError, |
773 |
| - match='time data must be specified only with hour ' |
774 |
| - 'and minute'): |
775 |
| - BusinessHour(start=dt_time(11, 0, 5)) |
776 |
| - with pytest.raises(ValueError, |
777 |
| - match="time data must match '%H:%M' format"): |
778 |
| - BusinessHour(start='AAA') |
779 |
| - with pytest.raises(ValueError, |
780 |
| - match="time data must match '%H:%M' format"): |
781 |
| - BusinessHour(start='14:00:05') |
782 |
| - with pytest.raises(ValueError, |
783 |
| - match='Must include at least 1 start time'): |
784 |
| - BusinessHour(start=[]) |
785 |
| - with pytest.raises(ValueError, |
786 |
| - match='Must include at least 1 end time'): |
787 |
| - BusinessHour(end=[]) |
| 770 | + @pytest.mark.parametrize("start,end,match", [ |
| 771 | + ( |
| 772 | + time(11, 0, 5), |
| 773 | + '17:00', |
| 774 | + "time data must be specified only with hour and minute" |
| 775 | + ), |
| 776 | + ( |
| 777 | + 'AAA', |
| 778 | + '17:00', |
| 779 | + "time data must match '%H:%M' format" |
| 780 | + ), |
| 781 | + ( |
| 782 | + '14:00:05', |
| 783 | + '17:00', |
| 784 | + "time data must match '%H:%M' format" |
| 785 | + ), |
| 786 | + ( |
| 787 | + [], |
| 788 | + '17:00', |
| 789 | + "Must include at least 1 start time" |
| 790 | + ), |
| 791 | + ( |
| 792 | + '09:00', |
| 793 | + [], |
| 794 | + "Must include at least 1 end time" |
| 795 | + ), |
| 796 | + ( |
| 797 | + ['09:00', '11:00'], |
| 798 | + '17:00', |
| 799 | + "number of starting time and ending time must be the same" |
| 800 | + ), |
| 801 | + ( |
| 802 | + ['09:00', '11:00'], |
| 803 | + ['10:00'], |
| 804 | + "number of starting time and ending time must be the same" |
| 805 | + ), |
| 806 | + ( |
| 807 | + ['09:00', '11:00'], |
| 808 | + ['12:00', '20:00'], |
| 809 | + r"invalid starting and ending time\(s\): opening hours should not " |
| 810 | + "touch or overlap with one another" |
| 811 | + ), |
| 812 | + ]) |
| 813 | + def test_constructor_errors(self, start, end, match): |
788 | 814 | with pytest.raises(ValueError,
|
789 |
| - match='number of starting time and ending time ' |
790 |
| - 'must be the same'): |
791 |
| - BusinessHour(start=['09:00', '11:00']) |
792 |
| - with pytest.raises(ValueError, |
793 |
| - match='number of starting time and ending time ' |
794 |
| - 'must be the same'): |
795 |
| - BusinessHour(start=['09:00', '11:00'], end=['10:00']) |
796 |
| - with pytest.raises(ValueError, |
797 |
| - match=r'invalid starting and ending time\(s\): ' |
798 |
| - 'opening hours should not touch or overlap with ' |
799 |
| - 'one another'): |
800 |
| - BusinessHour(start=['09:00', '11:00'], end=['12:00', '20:00']) |
| 815 | + match=match): |
| 816 | + BusinessHour(start=start, end=end) |
801 | 817 |
|
802 | 818 | def test_different_normalize_equals(self):
|
803 | 819 | # GH#21404 changed __eq__ to return False when `normalize` doesnt match
|
@@ -827,30 +843,50 @@ def test_with_offset(self):
|
827 | 843 | assert self.d + BusinessHour() * 3 == expected
|
828 | 844 | assert self.d + BusinessHour(n=3) == expected
|
829 | 845 |
|
830 |
| - def test_eq(self): |
831 |
| - for offset in [self.offset1, self.offset2, self.offset3, self.offset4, |
832 |
| - self.offset8, self.offset9, self.offset10]: |
833 |
| - assert offset == offset |
| 846 | + @pytest.mark.parametrize("offset_name", [ |
| 847 | + "offset1", |
| 848 | + "offset2", |
| 849 | + "offset3", |
| 850 | + "offset4", |
| 851 | + "offset8", |
| 852 | + "offset9", |
| 853 | + "offset10" |
| 854 | + ]) |
| 855 | + def test_eq_attribute(self, offset_name): |
| 856 | + offset = getattr(self, offset_name) |
| 857 | + assert offset == offset |
| 858 | + |
| 859 | + @pytest.mark.parametrize("offset1,offset2", [ |
| 860 | + (BusinessHour(start='09:00'), BusinessHour()), |
| 861 | + (BusinessHour(start=['23:00', '13:00'], end=['12:00', '17:00']), |
| 862 | + BusinessHour(start=['13:00', '23:00'], end=['17:00', '12:00'])), |
| 863 | + ]) |
| 864 | + def test_eq(self, offset1, offset2): |
| 865 | + assert offset1 == offset2 |
834 | 866 |
|
835 |
| - assert BusinessHour() != BusinessHour(-1) |
836 |
| - assert BusinessHour(start='09:00') == BusinessHour() |
837 |
| - assert BusinessHour(start='09:00') != BusinessHour(start='09:01') |
838 |
| - assert (BusinessHour(start='09:00', end='17:00') != |
839 |
| - BusinessHour(start='17:00', end='09:01')) |
840 |
| - |
841 |
| - assert (BusinessHour(start=['23:00', '13:00'], |
842 |
| - end=['12:00', '17:00']) == |
843 |
| - BusinessHour(start=['13:00', '23:00'], |
844 |
| - end=['17:00', '12:00'])) |
845 |
| - assert (BusinessHour(start=['13:00', '23:00'], |
846 |
| - end=['18:00', '07:00']) != |
847 |
| - BusinessHour(start=['13:00', '23:00'], |
848 |
| - end=['17:00', '12:00'])) |
| 867 | + @pytest.mark.parametrize("offset1,offset2", [ |
| 868 | + (BusinessHour(), BusinessHour(-1)), |
| 869 | + (BusinessHour(start='09:00'), BusinessHour(start='09:01')), |
| 870 | + (BusinessHour(start='09:00', end='17:00'), |
| 871 | + BusinessHour(start='17:00', end='09:01')), |
| 872 | + (BusinessHour(start=['13:00', '23:00'], end=['18:00', '07:00']), |
| 873 | + BusinessHour(start=['13:00', '23:00'], end=['17:00', '12:00'])), |
| 874 | + ]) |
| 875 | + def test_neq(self, offset1, offset2): |
| 876 | + assert offset1 != offset2 |
849 | 877 |
|
850 |
| - def test_hash(self): |
851 |
| - for offset in [self.offset1, self.offset2, self.offset3, self.offset4, |
852 |
| - self.offset8, self.offset9, self.offset10]: |
853 |
| - assert hash(offset) == hash(offset) |
| 878 | + @pytest.mark.parametrize("offset_name", [ |
| 879 | + "offset1", |
| 880 | + "offset2", |
| 881 | + "offset3", |
| 882 | + "offset4", |
| 883 | + "offset8", |
| 884 | + "offset9", |
| 885 | + "offset10" |
| 886 | + ]) |
| 887 | + def test_hash(self, offset_name): |
| 888 | + offset = getattr(self, offset_name) |
| 889 | + assert offset == offset |
854 | 890 |
|
855 | 891 | def test_call(self):
|
856 | 892 | assert self.offset1(self.d) == datetime(2014, 7, 1, 11)
|
|
0 commit comments