Пример #1
0
 def test_now_to_1_year(self, run_in_various_years):
     # The following two tests test the span from "now" to "a year from
     # now".  Depending on when the test is run, the interval may include a
     # leap year.  The 'try' assumes it's not a leap year, the 'except'
     # tries it again as a leap year.
     try:
         assert dtw(0, 31536000) == "1 year"
         assert dtw(1, 31536001) == "1 year"
     except AssertionError:  # If the intervening year contains February 29th
         assert dtw(0, 31536000) == "11 months and 30 days"
         assert dtw(1, 31536001) == "11 months and 30 days"
Пример #2
0
 def now_to_1_year(self):
     # The following two tests test the span from "now" to "a year from
     # now".  Depending on when the test is run, the interval may include a
     # leap year.  The 'try' assumes it's not a leap year, the 'except'
     # tries it again as a leap year.
     try:
         assert dtw(0, 31536000) == "1 year"
         assert dtw(1, 31536001) == "1 year"
     except AssertionError:  # If the intervening year contains February 29th
         assert dtw(0, 31536000) == "11 months and 30 days" 
         assert dtw(1, 31536001) == "11 months and 30 days"
Пример #3
0
 def test_symmetry(self):
     # Should get the same values going forward and backward
     from_time = self.from_time
     to_time = self.to_time
     assert dtw(from_time, to_time) == dtw(to_time, from_time)
     assert dtw(from_time, to_time, "month") ==  dtw(to_time, from_time, "month")
     assert dtw(from_time, to_time, "year") ==  dtw(to_time, from_time, "year")
Пример #4
0
    def test_spot_checks(self):
        # Spot checks
        from_time = DT(
            200, 2, 2, 0, 12, 12, 0,
            None)  # 12 minutes, 12 seconds past midnight on Feb 2 200AD
        to_time = DT(1981, 3, 31, 7, 31, 0, 0, None)  # 7:31 am, March 31, 1981
        assert dtw(
            from_time, to_time
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days, 7 hours, 18 minutes and 48 seconds"
        assert dtw(
            from_time, to_time, granularity="hour"
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
        assert dtw(
            from_time, to_time, granularity="hour", round=True
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
        assert dtw(from_time, to_time, granularity="month"
                   ) == "17 centuries, 8 decades, 1 year and 1 month"
        assert dtw(
            from_time, to_time, granularity="month",
            round=True) == "17 centuries, 8 decades, 1 year and 2 months"

        from_time = DT(200, 2, 2, 12, 30, 30, 0,
                       None)  # 12:30:30, Feb 2, 200AD
        to_time = DT(220, 3, 2, 12, 30, 31, 0, None)  # 12:30:31, Mar 2, 220AD
        assert dtw(from_time, to_time) == "2 decades, 1 month and 1 second"
Пример #5
0
 def test_symmetry(self):
     # Should get the same values going forward and backward
     from_time = self.from_time
     to_time = self.to_time
     assert dtw(from_time, to_time) == dtw(to_time, from_time)
     assert dtw(from_time, to_time, "month") == dtw(to_time, from_time,
                                                    "month")
     assert dtw(from_time, to_time, "year") == dtw(to_time, from_time,
                                                   "year")
Пример #6
0
 def test_spot_checks(self):
     # Spot checks
     from_time = DT(200, 2, 2, 0, 12, 12, 0, None) # 12 minutes, 12 seconds past midnight on Feb 2 200AD
     to_time = DT(1981, 3, 31, 7, 31, 0, 0, None) # 7:31 am, March 31, 1981
     assert dtw(from_time, to_time) == "17 centuries, 8 decades, 1 year, 1 month, 29 days, 7 hours, 18 minutes and 48 seconds"
     assert dtw(from_time, to_time, granularity = "hour") == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
     assert dtw(from_time, to_time, granularity = "hour", round=True) == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
     assert dtw(from_time, to_time, granularity = "month") == "17 centuries, 8 decades, 1 year and 1 month"
     assert dtw(from_time, to_time, granularity = "month", round=True) == "17 centuries, 8 decades, 1 year and 2 months"
     
     from_time = DT(200, 2, 2, 12, 30, 30, 0, None) # 12:30:30, Feb 2, 200AD
     to_time = DT(220, 3, 2, 12, 30, 31, 0, None) # 12:30:31, Mar 2, 220AD
     assert dtw(from_time, to_time) == "2 decades, 1 month and 1 second"
Пример #7
0
 def test2(self):
     assert dtw(86399, granularity='day') == "less than 1 day"
Пример #8
0
 def test1(self):
     assert dtw(86399, round=True, granularity="day") == "1 day"
Пример #9
0
 def test1(self):
     assert dtw(86399, round=True, granularity="day") == "1 day"
Пример #10
0
 def test6(self):
     b = "1 month, 15 days, 6 hours and 49 minutes"
     assert dtw(self.start, self.end, granularity="second") == b
Пример #11
0
 def test_plural2(self):
     assert dtw(DT(2000, 1,1), DT(2000, 2, 1)) == "1 month"
     assert dtw(DT(2000, 1,1), DT(2000, 5, 1)) == "4 months"
Пример #12
0
 def test5(self):
     b = "less than 1 decade"
     assert dtw(self.start, self.end, granularity="decade") == b
Пример #13
0
 def test6(self):
     b = "1 month, 15 days, 6 hours and 49 minutes"
     assert dtw(self.start, self.end, granularity="second") == b
Пример #14
0
 def test_granularity(self):
     # Ensure we get the correct granularity when the times are the same
     from_time = self.from_time
     assert dtw(from_time, from_time, "second") == "0 seconds"
     assert dtw(from_time, from_time, "day") == "0 days"
     assert dtw(from_time, from_time, "century") == "0 centuries"
Пример #15
0
 def test_february_nonleap(self):
     # February 2nd 2007 to March 1 2007 is 27 days because February is shorter month in the year
     assert dtw(DT(2007,2,2), DT(2007, 3, 1)) == "27 days"
Пример #16
0
 def test_february_leap(self):
     # February 2nd 2008 to March 1 2008 is 28 days because it's a leap year
     assert dtw(DT(2008, 2, 2), DT(2008, 3, 1)) == "28 days"
Пример #17
0
 def test3(self):
     assert dtw(86399) == "23 hours, 59 minutes and 59 seconds"
Пример #18
0
 def test_february_nonleap(self):
     # February 2nd 2007 to March 1 2007 is 27 days because February is shorter month in the year
     assert dtw(DT(2007, 2, 2), DT(2007, 3, 1)) == "27 days"
Пример #19
0
 def test4(self):
     b = "1 month, 15 days, 6 hours and 49 minutes"
     assert dtw(self.start, self.end) == b
Пример #20
0
 def test_integer_seconds(self):
     # Test that if integers are supplied they are interpreted as seconds from now
     assert dtw(1) == "1 second"
Пример #21
0
 def test3(self):
     assert dtw(86399) == "23 hours, 59 minutes and 59 seconds"
Пример #22
0
 def test2(self):
     assert dtw(86399, granularity='day') == "less than 1 day"
Пример #23
0
 def test4(self):
     b = "1 month, 15 days, 6 hours and 49 minutes"
     assert dtw(self.start, self.end) == b
Пример #24
0
 def test_smaller_than_granularity(self):
     # We are not over the finest granularity
     assert dtw(1, granularity="hour") == "less than 1 hour"
     assert dtw(86399, granularity="day") == "less than 1 day"
Пример #25
0
 def test_integer_seconds(self):
     # Test that if integers are supplied they are interpreted as seconds from now
     assert dtw(1) == "1 second"
Пример #26
0
 def test_grandularity_round_second_value(self):
     # Rounding at the second value makes no difference
     from_time = self.from_time
     to_time = self.to_time
     assert dtw(to_time, from_time, granularity="second") == \
         dtw(to_time, from_time, granularity="second", round=True)
Пример #27
0
 def test_smaller_than_granularity(self):
     # We are not over the finest granularity
     assert dtw(1, granularity="hour") == "less than 1 hour"
     assert dtw(86399, granularity="day") == "less than 1 day"
Пример #28
0
 def test5(self):
     b = "less than 1 decade"
     assert dtw(self.start, self.end, granularity="decade") == b
Пример #29
0
 def test_february_leap(self):
     # February 2nd 2008 to March 1 2008 is 28 days because it's a leap year 
     assert dtw(DT(2008,2,2), DT(2008, 3, 1)) == "28 days"
Пример #30
0
 def test_grandularity_round_up(self):
     # Round up if the granularity after the supplied granularity is high enough
     assert dtw(86399, round=True, granularity="day") == "1 day"
     assert dtw(290, round=True, granularity="minute") == "5 minutes"
     assert dtw(86689, round=True,
                granularity="minute") == "1 day and 5 minutes"
Пример #31
0
 def test_granularity(self):
     # Ensure we get the correct granularity when the times are the same
     from_time = self.from_time
     assert dtw(from_time, from_time, "second") == "0 seconds"
     assert dtw(from_time, from_time, "day") == "0 days"
     assert dtw(from_time, from_time, "century") == "0 centuries"
Пример #32
0
 def test_grandularity_round_second_value(self):
     # Rounding at the second value makes no difference
     from_time = self.from_time
     to_time = self.to_time
     assert dtw(to_time, from_time, granularity="second") == \
         dtw(to_time, from_time, granularity="second", round=True)
Пример #33
0
 def test_grandularity_round_up(self):
     # Round up if the granularity after the supplied granularity is high enough
     assert dtw(86399, round=True, granularity="day") == "1 day"
     assert dtw(290, round=True, granularity="minute") == "5 minutes"
     assert dtw(86689, round=True, granularity="minute") == "1 day and 5 minutes"
Пример #34
0
 def test_round_smaller_than_granularity(self):
     assert dtw(1, granularity="hour", round=True) == "less than 1 hour"
Пример #35
0
 def test_plural(self):
     # Pluralization
     assert dtw(DT(200, 1,1), DT(300, 1, 1)) == "1 century"
     assert dtw(DT(200, 1,1), DT(500, 1, 1)) == "3 centuries"
Пример #36
0
 def test_plural(self):
     # Pluralization
     assert dtw(DT(200, 1, 1), DT(300, 1, 1)) == "1 century"
     assert dtw(DT(200, 1, 1), DT(500, 1, 1)) == "3 centuries"
Пример #37
0
 def test_plural2(self):
     assert dtw(DT(2000, 1, 1), DT(2000, 2, 1)) == "1 month"
     assert dtw(DT(2000, 1, 1), DT(2000, 5, 1)) == "4 months"
Пример #38
0
 def test_round_smaller_than_granularity(self):
     assert dtw(1, granularity="hour", round=True) == "less than 1 hour"