def test_sub_unsupported(self): p = Interval(days=23, seconds=32) self.assertEqual(NotImplemented, p.__sub__(5))
def test_add_timedelta(self): p1 = Interval(days=23, seconds=32) p2 = timedelta(days=12, seconds=30) p = p1 + p2 self.assertInterval(p, 5, 0, 0, 1, 2)
def test_sub_timedelta(self): p1 = Interval(days=23, seconds=32) p2 = timedelta(days=12, seconds=28) p = p1 - p2 self.assertInterval(p, 1, 4, 0, 0, 4)
def test_all(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertInterval(pi, 168, 1, 2, 1, 25)
def setUp(self): super(ForHumansTest, self).setUp() Interval.set_locale('en')
def test_weeks(self): pi = Interval(days=365) self.assertInterval(pi, 52) pi = Interval(days=13) self.assertInterval(pi, 1)
def test_hours(self): pi = Interval(seconds=3600 * 3) self.assertInterval(pi, 0, 0, 3, 0, 0)
def test_all(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertEqual( '168 weeks 1 day 2 hours 1 minute 25 seconds', pi.in_words() )
def test_in_french(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertEqual( '168 semaines 1 jour 2 heures 1 minute 25 secondes', pi.in_words(locale='fr') )
def test_week_to_string(self): self.assertEqual('52 weeks', str(Interval(days=364))) self.assertEqual('1 week', str(Interval(days=7)))
def test_weeks_and_day(self): self.assertEqual('52 weeks 1 day', Interval(days=365).in_words())
def test_week(self): self.assertEqual('52 weeks', Interval(days=364).in_words()) self.assertEqual('1 week', Interval(days=7).in_words())
def test_invert(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertFalse(pi.invert) pi = Interval(days=-1177, seconds=-7284, microseconds=-1000000) self.assertTrue(pi.invert)
def test_instance(self): pi = Interval.instance( timedelta(days=1177, seconds=7284, microseconds=1000000)) self.assertInterval(pi, 168, 1, 2, 1, 25)
def test_neg(self): p = Interval(days=23, seconds=32) self.assertInterval(-p, -3, -2, 0, 0, -32)
def test_repr(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertEqual( '<Interval [168 weeks 1 day 2 hours 1 minute 25 seconds]>', repr(pi) )
def test_defaults(self): pi = Interval() self.assertIsInstanceOfInterval(pi) self.assertInterval(pi, 0, 0, 0, 0, 0)
def test_singluar_negative_values(self): pi = Interval(days=-1) self.assertEqual( '-1 day', pi.in_words() )
def test_days(self): pi = Interval(days=6) self.assertInterval(pi, 0, 6, 0, 0, 0) pi = Interval(days=16) self.assertInterval(pi, 2, 2, 0, 0, 0)
def test_separator(self): pi = Interval(days=1177, seconds=7284, microseconds=1000000) self.assertEqual( '168 weeks, 1 day, 2 hours, 1 minute, 25 seconds', pi.in_words(separator=', ') )
def test_minutes(self): pi = Interval(seconds=60 * 3) self.assertInterval(pi, 0, 0, 0, 3, 0) pi = Interval(seconds=60 * 3 + 12) self.assertInterval(pi, 0, 0, 0, 3, 12)
def getDateList(start, end): dif = int((end - start).total_seconds() / 3600) date_list = [(start + Interval(hours=x)) for x in range(dif)] return date_list