def test_parse_out_of_bounds_handled_successfully(self):
     self.assertEquals(
         utils.parse_timedelta_string('86400s'),
         datetime.timedelta(days=1))
     self.assertEquals(
         utils.parse_timedelta_string('19d, 86400s'),
         datetime.timedelta(weeks=2, days=6))
Пример #2
0
 def test_parse_out_of_bounds_handled_successfully(self):
     self.assertEquals(
         utils.parse_timedelta_string('86400s'),
         datetime.timedelta(days=1))
     self.assertEquals(
         utils.parse_timedelta_string('19d, 86400s'),
         datetime.timedelta(weeks=2, days=6))
Пример #3
0
    def test_parse_combinations(self):
        self.assertEquals(utils.parse_timedelta_string("3w1d3m"), datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(utils.parse_timedelta_string("3w,  1d,  3m"), datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(utils.parse_timedelta_string("3 w 1 d 3 m"), datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(
            utils.parse_timedelta_string("3 weeks 1 day 3 minutes"), datetime.timedelta(weeks=3, days=1, minutes=3)
        )

        self.assertEquals(
            utils.parse_timedelta_string("3 weeks, 1 day, 3 minutes"), datetime.timedelta(weeks=3, days=1, minutes=3)
        )
Пример #4
0
    def test_parse_combinations(self):
        self.assertEquals(utils.parse_timedelta_string('3w1d3m'),
                          datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(utils.parse_timedelta_string('3w,  1d,  3m'),
                          datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(utils.parse_timedelta_string('3 w 1 d 3 m'),
                          datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(
            utils.parse_timedelta_string('3 weeks 1 day 3 minutes'),
            datetime.timedelta(weeks=3, days=1, minutes=3))

        self.assertEquals(
            utils.parse_timedelta_string('3 weeks, 1 day, 3 minutes'),
            datetime.timedelta(weeks=3, days=1, minutes=3))
Пример #5
0
 def _test_parse_units(self, unit):
     expected1 = datetime.timedelta(**{unit + "s": 1})
     expected2 = datetime.timedelta(**{unit + "s": 2})
     self.assertEquals(utils.parse_timedelta_string("1%s" % unit[0]), expected1)
     self.assertEquals(utils.parse_timedelta_string("1%s" % unit), expected1)
     self.assertEquals(utils.parse_timedelta_string("2%ss" % unit), expected2)
     self.assertEquals(utils.parse_timedelta_string("2 %s" % unit[0]), expected2)
     self.assertEquals(utils.parse_timedelta_string("1 %s" % unit), expected1)
     self.assertEquals(utils.parse_timedelta_string("2 %s" % unit), expected2)
     self.assertEquals(utils.parse_timedelta_string("2    \t\t\n   %ss" % unit), expected2)
 def _test_parse_units(self, unit):
     expected1 = datetime.timedelta(**{unit + 's': 1})
     expected2 = datetime.timedelta(**{unit + 's': 2})
     self.assertEquals(
         utils.parse_timedelta_string('1%s' % unit[0]), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('1%s' % unit), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('2%ss' % unit), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('2 %s' % unit[0]), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('1 %s' % unit), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('2 %s' % unit), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('2    \t\t\n   %ss' % unit), expected2)
Пример #7
0
 def _test_parse_units(self, unit):
     expected1 = datetime.timedelta(**{unit + 's': 1})
     expected2 = datetime.timedelta(**{unit + 's': 2})
     self.assertEquals(
         utils.parse_timedelta_string('1%s' % unit[0]), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('1%s' % unit), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('2%ss' % unit), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('2 %s' % unit[0]), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('1 %s' % unit), expected1)
     self.assertEquals(
         utils.parse_timedelta_string('2 %s' % unit), expected2)
     self.assertEquals(
         utils.parse_timedelta_string('2    \t\t\n   %ss' % unit), expected2)
Пример #8
0
 def test_parse_trailing_valid_partial_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string('we will leave in 5 days'),
         datetime.timedelta(days=0))
Пример #9
0
 def test_parse_leading_valid_partial_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string(
             '5 days and a partridge in a pear tree'),
         datetime.timedelta(days=5))
Пример #10
0
 def test_parse_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string(
             'Amidst the mists and coldest frosts'), datetime.timedelta())
Пример #11
0
 def test_parse_zero(self):
     self.assertEquals(utils.parse_timedelta_string('0'),
                       datetime.timedelta())
Пример #12
0
 def test_parse_empty_string(self):
     self.assertEquals(utils.parse_timedelta_string(''),
                       datetime.timedelta())
Пример #13
0
 def test_parse_empty_string(self):
     self.assertEquals(
         utils.parse_timedelta_string(''),
         datetime.timedelta())
Пример #14
0
 def test_parse_zero(self):
     self.assertEquals(
         utils.parse_timedelta_string('0'),
         datetime.timedelta())
Пример #15
0
 def test_parse_trailing_valid_partial_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string('we will leave in 5 days'),
         datetime.timedelta(days=0))
Пример #16
0
 def test_parse_leading_valid_partial_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string(
             '5 days and a partridge in a pear tree'),
         datetime.timedelta(days=5))
Пример #17
0
 def test_parse_gibberish(self):
     self.assertEquals(
         utils.parse_timedelta_string('Amidst the mists and coldest frosts'),
         datetime.timedelta())