def test_parse_bad_expression(self):
     """ Should raise if the expression isn't a duration"""
     try:
         d = parse_duration("Not a number, Bro")
         assert False, "Should have raised"
     except ValueError as e:
         assert True
예제 #2
0
 def test_parse_bad_expression(self):
     """ Should raise if the expression isn't a duration"""
     try:
         d = parse_duration("Not a number, Bro")
         assert False, "Should have raised"
     except ValueError as e:
         assert True
예제 #3
0
 def test_parse_negative_value(self):
     """ Should raise if the expression is negative because a duration can't be negative"""
     try:
         d = parse_duration("-1")
         assert False, "Should have raised"
     except ValueError as e:
         assert True
 def test_parse_negative_value(self):
     """ Should raise if the expression is negative because a duration can't be negative"""
     try:
         d = parse_duration("-1")
         assert False, "Should have raised"
     except ValueError as e:
         assert True
예제 #5
0
def check_duration(value):
    if len(value) == 0:
        raise ArgumentTypeError("Duration can't be empty")
    try:
        sec = int(value)
        if sec < -1:
                raise ArgumentTypeError("A duration can't be negative (found {})".format(sec))
        return sec
    except ValueError:
        pass
    try:
        return parse_duration(value)
    except ValueError as e:
        raise ArgumentTypeError(e.message)
예제 #6
0
 def test_parse_minutes(self):
     """ A duration can have only minutes """
     d = parse_duration("14min")
     assert d == 14*60, d
예제 #7
0
 def test_parse_minutes_secs(self):
     """ A duration can have minutes and seconds """
     d = parse_duration("14min 12s")
     assert d == 14*60 + 12, d
예제 #8
0
 def test_parse_seconds(self):
     """ should interpret s as seconds """
     d = parse_duration("12s")
     assert d == 12, d
예제 #9
0
 def test_parse_days(self):
     """ A duration can have days """
     d = parse_duration("4d 12s")
     assert d == 4*24*3600 + 12, d
예제 #10
0
 def test_parse_days(self):
     """ A duration can have days """
     d = parse_duration("4d 12s")
     assert d == 4 * 24 * 3600 + 12, d
예제 #11
0
 def test_parse_several_spaces(self):
     """ Figures and units also parts of the duration can be separated by any number of spaces """
     d = parse_duration("14  min     12 s")
     assert d == 14 * 60 + 12, d
예제 #12
0
 def test_parse_minutes(self):
     """ A duration can have only minutes """
     d = parse_duration("14min")
     assert d == 14 * 60, d
예제 #13
0
 def test_parse_minutes_secs(self):
     """ A duration can have minutes and seconds """
     d = parse_duration("14min 12s")
     assert d == 14 * 60 + 12, d
예제 #14
0
 def test_parse_seconds(self):
     """ should interpret s as seconds """
     d = parse_duration("12s")
     assert d == 12, d
예제 #15
0
 def test_parse_several_spaces(self):
     """ Figures and units also parts of the duration can be separated by any number of spaces """
     d = parse_duration("14  min     12 s")
     assert d == 14*60 + 12, d
예제 #16
0
 def test_parse_hours(self):
     """ A duration can have hours """
     d = parse_duration("3 h 12s")
     assert d == 3*3600 + 12, d
예제 #17
0
 def test_parse_hours(self):
     """ A duration can have hours """
     d = parse_duration("3 h 12s")
     assert d == 3 * 3600 + 12, d