python3.x merge caused issues with python2.x compat
instead of importing division from future we simply use int() to cast floats to integers. nosetests: on python2.7 passes python2 test_ago.py: passes python3 test_ago.py: passes TODO: Does nosetests work with python3.x? branch 'default' changed ago.py changed test_ago.py
This commit is contained in:
parent
cd08476137
commit
e95b5d8c10
2 changed files with 16 additions and 9 deletions
11
ago.py
11
ago.py
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import division
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
|
|
@ -6,11 +5,11 @@ def delta2dict( delta ):
|
|||
"""Accepts a delta, returns a dictionary of units"""
|
||||
delta = abs( delta )
|
||||
return {
|
||||
'year' : delta.days // 365 ,
|
||||
'day' : delta.days % 365 ,
|
||||
'hour' : delta.seconds // 3600 ,
|
||||
'minute' : (delta.seconds // 60) % 60 ,
|
||||
'second' : delta.seconds % 60 ,
|
||||
'year' : int(delta.days / 365),
|
||||
'day' : int(delta.days % 365),
|
||||
'hour' : int(delta.seconds / 3600),
|
||||
'minute' : int(delta.seconds / 60) % 60,
|
||||
'second' : delta.seconds % 60,
|
||||
'microsecond' : delta.microseconds
|
||||
}
|
||||
|
||||
|
|
|
|||
14
test_ago.py
14
test_ago.py
|
|
@ -4,6 +4,14 @@ from datetime import timedelta
|
|||
from ago import human
|
||||
from ago import delta2dict
|
||||
|
||||
try:
|
||||
from types import StringType as STRING
|
||||
from types import DictType as DICT
|
||||
except ImportError:
|
||||
import builtins
|
||||
STRING = builtins.str
|
||||
DICT = builtins.dict
|
||||
|
||||
# datetime objects
|
||||
PRESENT = datetime.now()
|
||||
PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms
|
||||
|
|
@ -15,13 +23,13 @@ FUTURE_DELTA = PRESENT - FUTURE
|
|||
ONE_YEAR_FOUR_HOURS_DELTA = timedelta( 365, 14400, 0 )
|
||||
|
||||
def test_human_passed_datetime_is_string():
|
||||
assert type(human( PAST )) is builtins.str
|
||||
assert type(human( PAST )) is STRING
|
||||
|
||||
def test_human_passed_timedelta_is_string():
|
||||
assert type(human( PAST_DELTA )) is builtins.str
|
||||
assert type(human( PAST_DELTA )) is STRING
|
||||
|
||||
def test_delta2dict_is_dict():
|
||||
assert type(delta2dict( PAST_DELTA )) is builtins.dict
|
||||
assert type(delta2dict( PAST_DELTA )) is DICT
|
||||
|
||||
def test_ago_in_past_human():
|
||||
assert 'ago' in human( PAST )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue