Used `futurize
in
future
` module to make 2/3 compatible
This commit is contained in:
parent
c366c8923d
commit
1f1fa7d03e
@ -10,7 +10,7 @@ Unit tests for the `timeparse` module.
|
|||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
import re
|
import re
|
||||||
import timeparse
|
from pytimeparse import timeparse
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestTimeparse(unittest.TestCase):
|
class TestTimeparse(unittest.TestCase):
|
||||||
@ -58,7 +58,7 @@ class TestTimeparse(unittest.TestCase):
|
|||||||
'''Test parsing time expression.'''
|
'''Test parsing time expression.'''
|
||||||
self.assertGreater(
|
self.assertGreater(
|
||||||
set(re.match(timeparse.TIMEFORMATS[0] + r'\s*$',
|
set(re.match(timeparse.TIMEFORMATS[0] + r'\s*$',
|
||||||
'16h32m64s ').groupdict().iteritems()),
|
'16h32m64s ').groupdict().items()),
|
||||||
set([('hours', '16'), ('mins', '32'), ('secs', '64')]))
|
set([('hours', '16'), ('mins', '32'), ('secs', '64')]))
|
||||||
|
|
||||||
def test_timeparse_multipliers(self):
|
def test_timeparse_multipliers(self):
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from future.builtins import dict
|
||||||
|
from future.builtins import int
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
@ -105,9 +107,9 @@ def timeparse(sval):
|
|||||||
if match and match.group(0).strip():
|
if match and match.group(0).strip():
|
||||||
mdict = match.groupdict()
|
mdict = match.groupdict()
|
||||||
# if all of the fields are integer numbers
|
# if all of the fields are integer numbers
|
||||||
if all(v.isdigit() for v in mdict.values() if v):
|
if all(v.isdigit() for v in list(mdict.values()) if v):
|
||||||
return sum([MULTIPLIERS[k] * int(v, 10) for (k, v) in
|
return sum([MULTIPLIERS[k] * int(v, 10) for (k, v) in
|
||||||
mdict.items() if v is not None])
|
list(mdict.items()) if v is not None])
|
||||||
# if SECS is an integer number
|
# if SECS is an integer number
|
||||||
elif ('secs' not in mdict or
|
elif ('secs' not in mdict or
|
||||||
mdict['secs'] is None or
|
mdict['secs'] is None or
|
||||||
@ -115,9 +117,9 @@ def timeparse(sval):
|
|||||||
# we will return an integer
|
# we will return an integer
|
||||||
return (
|
return (
|
||||||
int(sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
int(sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
||||||
mdict.items() if k != 'secs' and v is not None])) +
|
list(mdict.items()) if k != 'secs' and v is not None])) +
|
||||||
(int(mdict['secs'], 10) if mdict['secs'] else 0))
|
(int(mdict['secs'], 10) if mdict['secs'] else 0))
|
||||||
else:
|
else:
|
||||||
# SECS is a float, we will return a float
|
# SECS is a float, we will return a float
|
||||||
return sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
return sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
||||||
mdict.items() if v is not None])
|
list(mdict.items()) if v is not None])
|
||||||
|
Loading…
Reference in New Issue
Block a user